New option: Thread-specific LongTask markers

43 views
Skip to first unread message

Randell Jesup

unread,
Dec 7, 2023, 5:14:21 PM12/7/23
to dev-pl...@mozilla.org

In bug 1862556 I landed support for thread-specific LongTask markers.  You can do this when creating an nsThread by setting the longTaskLength field in the new thread options , like this:

  nsresult rv = NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), nullptr,
                            {nsIThreadManager::DEFAULT_STACK_SIZE, false, false,
                            Some(SOCKET_THREAD_LONGTASK_MS)});

In the profiler, if the thread in question was being profiled, there will be a row in the Markers tab where LongTask markers will appear.  These appear anytime an event takes longer than the specified time to run.   Once you have one of these markers it's easy to drill down and figure out why the event took so long.

Note that if the thread doesn't use the default event loop (such as the SocketTransport thread, which calls Poll(), etc), you may need to make some adjustments and manually insert some markers; you can look at nsSocketTransportService2.cpp for examples.

MainThread now uses this mechanism to insert markers for any event taking longer than 50ms (which is also the W3 LongTask API threshold).

Any timing-sensitive threads may find this useful (Media threads, UI threads, backend operation threads to find causes of unexpected processing delay, etc.

--

Randell Jesup, Mozilla

Reply all
Reply to author
Forward
0 new messages