From 9410a39f058c7f4d577a5c4e89c74e5276eef9a5 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 7 Dec 2023 16:27:23 +0000 Subject: [PATCH] Bug 1862557: Add LongTask profiler marker generation to SocketThread r=necko-reviewers,kershaw Includes separate markers for OnSocketReady() calls after Poll() Differential Revision: https://phabricator.services.mozilla.com/D192533 UltraBlame original commit: 93a04e8835aaaf359b24f47f54d622f7d36fd813 --- netwerk/base/nsSocketTransportService2.cpp | 253 ++++++++++++++++++++- xpcom/threads/nsThreadManager.cpp | 8 +- 2 files changed, 249 insertions(+), 12 deletions(-) diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index bf80ca39a59f0..6cbea98aff21d 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -300,6 +300,10 @@ mozilla namespace net { +# +define +SOCKET_THREAD_LONGTASK_MS +3 LazyLogModule gSocketTransportLog ( @@ -4363,7 +4367,7 @@ pollTimeout ) ; int32_t -rv +n ; { # @@ -4423,7 +4427,7 @@ profiler_thread_sleep } # endif -rv +n = PR_Poll ( @@ -4597,7 +4601,7 @@ ts ) ; return -rv +n ; } / @@ -4907,6 +4911,22 @@ network_allow_raw_sockets_in_content_processes_AtStartup ) ) { +/ +/ +Since +we +Poll +we +can +' +t +use +normal +LongTask +support +in +Main +Process nsresult rv = @@ -4922,12 +4942,15 @@ thread ) this { -. -stackSize -= GetThreadStackSize ( ) +false +false +Some +( +SOCKET_THREAD_LONGTASK_MS +) } ) ; @@ -4989,6 +5012,18 @@ getter_AddRefs thread ) nullptr +{ +nsIThreadManager +: +: +DEFAULT_STACK_SIZE +false +false +Some +( +SOCKET_THREAD_LONGTASK_MS +) +} ) ; NS_ENSURE_SUCCESS @@ -8750,6 +8785,36 @@ PR_IntervalNow ( ) ; +TimeStamp +startTime +; +# +ifdef +MOZ_GECKO_PROFILER +bool +profiling += +profiler_thread_is_being_profiled_for_markers +( +) +; +if +( +profiling +) +{ +startTime += +TimeStamp +: +: +Now +( +) +; +} +# +endif if ( n @@ -9191,6 +9256,182 @@ TryRepairPollableEvent } } } +# +ifdef +MOZ_GECKO_PROFILER +if +( +profiling +) +{ +TimeStamp +endTime += +TimeStamp +: +: +Now +( +) +; +if +( +( +endTime +- +startTime +) +. +ToMilliseconds +( +) +> += +SOCKET_THREAD_LONGTASK_MS +) +{ +struct +LongTaskMarker +{ +static +constexpr +Span +< +const +char +> +MarkerTypeName +( +) +{ +return +MakeStringSpan +( +" +SocketThreadLongTask +" +) +; +} +static +void +StreamJSONMarkerData +( +baseprofiler +: +: +SpliceableJSONWriter +& +aWriter +) +{ +aWriter +. +StringProperty +( +" +category +" +" +LongTask +" +) +; +} +static +MarkerSchema +MarkerTypeDisplay +( +) +{ +using +MS += +MarkerSchema +; +MS +schema +{ +MS +: +: +Location +: +: +MarkerChart +MS +: +: +Location +: +: +MarkerTable +} +; +schema +. +AddKeyLabelFormatSearchable +( +" +category +" +" +Type +" +MS +: +: +Format +: +: +String +MS +: +: +Searchable +: +: +Searchable +) +; +return +schema +; +} +} +; +profiler_add_marker +( +ProfilerString8View +( +" +LongTaskSocketProcessing +" +) +geckoprofiler +: +: +category +: +: +OTHER +MarkerTiming +: +: +Interval +( +startTime +endTime +) +LongTaskMarker +{ +} +) +; +} +} +# +endif return NS_OK ; diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index c2b620f169358..b02c98294670f 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -2080,13 +2080,9 @@ nsThread : MAIN_THREAD { -. -stackSize -= 0 -. -longTaskLength -= +false +false Some ( W3_LONGTASK_BUSY_WINDOW_MS