Commit 65630c6c authored by Markus Stange's avatar Markus Stange
Browse files

Bug 1323100 - Register most of the remaining threadfunc threads with the profiler. r=froydnj

As far as I can tell, this covers all the remaining threads which we start
using PR_CreateThread, except the ones that are created inside NSPR or NSS.

This adds a AutoProfilerRegister stack class for easy registering and
unregistering. There are a few places where we still call
profiler_register_thread() and profiler_unregister_thread() manually, either
because registration happens conditionally, or because there is a variable that
gets put on the stack before the AutoProfilerRegister (e.g. a dynamically
generated thread name). AutoProfilerRegister needs to be the first object on
the stack because it uses its own `this` pointer as the stack top address.

MozReview-Commit-ID: 3vwhS55Yzt

--HG--
extra : rebase_source : 9deaace277db2f63c520325be27f6ed97aa65ac9
parent e9c7fbcf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include "HRTFDatabaseLoader.h"
#include "HRTFDatabase.h"
#include "GeckoProfiler.h"

using namespace mozilla;

@@ -151,6 +152,7 @@ void HRTFDatabaseLoader::MainThreadRelease()
// Asynchronously load the database in this thread.
static void databaseLoaderEntry(void* threadData)
{
    AutoProfilerRegister registerThread("HRTFDatabaseLdr");
    PR_SetCurrentThreadName("HRTFDatabaseLdr");

    HRTFDatabaseLoader* loader = reinterpret_cast<HRTFDatabaseLoader*>(threadData);
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "mozilla/IOInterposer.h"
#include "mozilla/Services.h"
#include "mozilla/Tokenizer.h"
#include "GeckoProfiler.h"

// How long we collect write oprerations
// before they are flushed to the database
@@ -337,6 +338,7 @@ DOMStorageDBThread::SetDefaultPriority()
void
DOMStorageDBThread::ThreadFunc(void* aArg)
{
  AutoProfilerRegister registerThread("localStorage DB");
  PR_SetCurrentThreadName("localStorage DB");
  mozilla::IOInterposer::RegisterCurrentThread();

+1 −0
Original line number Diff line number Diff line
@@ -1166,6 +1166,7 @@ AutoLockWatchdog::~AutoLockWatchdog()
static void
WatchdogMain(void* arg)
{
    mozilla::AutoProfilerRegister registerThread("JS Watchdog");
    PR_SetCurrentThreadName("JS Watchdog");

    Watchdog* self = static_cast<Watchdog*>(arg);
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
#include "nsPrintfCString.h"
#include "nsThreadUtils.h"
#include "mozilla/IOInterposer.h"
#include "GeckoProfiler.h"

#ifdef XP_WIN
#include <windows.h>
@@ -437,6 +438,7 @@ already_AddRefed<nsIEventTarget> CacheIOThread::Target()
// static
void CacheIOThread::ThreadFunc(void* aClosure)
{
  AutoProfilerRegister registerThread("Cache2 I/O");
  PR_SetCurrentThreadName("Cache2 I/O");
  mozilla::IOInterposer::RegisterCurrentThread();
  CacheIOThread* thread = static_cast<CacheIOThread*>(aClosure);
+6 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "nsURLHelper.h"
#include "nsThreadUtils.h"
#include "GetAddrInfo.h"
#include "GeckoProfiler.h"

#include "mozilla/HashFunctions.h"
#include "mozilla/TimeStamp.h"
@@ -1435,12 +1436,15 @@ nsHostResolver::SizeOfIncludingThis(MallocSizeOf mallocSizeOf) const
void
nsHostResolver::ThreadFunc(void *arg)
{
    char stackTop;

    LOG(("DNS lookup thread - starting execution.\n"));

    static nsThreadPoolNaming naming;
    nsCString name = naming.GetNextThreadName("DNS Resolver");

    PR_SetCurrentThreadName(name.BeginReading());
    profiler_register_thread(name.BeginReading(), &stackTop);

#if defined(RES_RETRY_ON_FAILURE)
    nsResState rs;
@@ -1511,6 +1515,8 @@ nsHostResolver::ThreadFunc(void *arg)
    resolver->mThreadCount--;
    NS_RELEASE(resolver);
    LOG(("DNS lookup thread - queue empty, thread finished.\n"));

    profiler_unregister_thread();
}

nsresult
Loading