Commit 48513de6 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 : dffab11abf7d4b57fa54475fd22e71b84375cd7b
parent 38bf1607
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@


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


using namespace mozilla;
using namespace mozilla;


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


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


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


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


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


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


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

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


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


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


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

    profiler_unregister_thread();
}
}


nsresult
nsresult
Loading