Skip to content

Commit

Permalink
Bug 927979 - Register the gecko thread correctly in the profiler for …
Browse files Browse the repository at this point in the history
…FxMetro. r=bgirard
  • Loading branch information
jmathies committed Oct 22, 2013
1 parent e6ac0c2 commit 357604d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tools/profiler/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "mozilla/Services.h"
#include "nsThreadUtils.h"
#include "ProfilerMarkers.h"
#include "nsXULAppAPI.h"

#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
#include "AndroidBridge.h"
Expand Down Expand Up @@ -65,6 +66,13 @@ TableTicker* Sampler::sActiveSampler;
static mozilla::StaticAutoPtr<mozilla::ProfilerIOInterposeObserver>
sInterposeObserver;

// The name that identifies the gecko thread for calls to
// profiler_register_thread. For all platform except metro
// the thread that calls mozilla_sampler_init is considered
// the gecko thread. With metro the gecko thread is
// registered later based on this thread name.
static const char * gGeckoThreadName = "GeckoMain";

void Sampler::Startup() {
sRegisteredThreads = new std::vector<ThreadInfo*>();
sRegisteredThreadsMutex = new mozilla::Mutex("sRegisteredThreads mutex");
Expand Down Expand Up @@ -367,6 +375,13 @@ void set_tls_stack_top(void* stackTop)
tlsStackTop.set((void*)stackTopR);
}

bool is_main_thread_name(const char* aName) {
if (aName) {
return false;
}
return strcmp(aName, gGeckoThreadName) == 0;
}

////////////////////////////////////////////////////////////////////////
// BEGIN externally visible functions

Expand All @@ -389,7 +404,14 @@ void mozilla_sampler_init(void* stackTop)
PseudoStack *stack = new PseudoStack();
tlsPseudoStack.set(stack);

Sampler::RegisterCurrentThread("GeckoMain", stack, true, stackTop);
bool isMainThread = true;
#ifdef XP_WIN
// For metrofx, we'll register the main thread once it's created.
isMainThread = !(XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro);
#endif
Sampler::RegisterCurrentThread(isMainThread ?
gGeckoThreadName : "Application Thread",
stack, isMainThread, stackTop);

// Read mode settings from MOZ_PROFILER_MODE and interval
// settings from MOZ_PROFILER_INTERVAL and stack-scan threshhold
Expand Down Expand Up @@ -730,8 +752,8 @@ bool mozilla_sampler_register_thread(const char* aName, void* stackTop)

PseudoStack* stack = new PseudoStack();
tlsPseudoStack.set(stack);

return Sampler::RegisterCurrentThread(aName, stack, false, stackTop);
bool isMainThread = is_main_thread_name(aName);
return Sampler::RegisterCurrentThread(aName, stack, isMainThread, stackTop);
}

void mozilla_sampler_unregister_thread()
Expand Down
12 changes: 12 additions & 0 deletions widget/windows/winrt/MetroApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "nsICommandLineRunner.h"
#include "FrameworkView.h"
#include "nsAppDirectoryServiceDefs.h"
#include "GeckoProfiler.h"
#include <shellapi.h>

using namespace ABI::Windows::ApplicationModel;
Expand All @@ -27,6 +28,8 @@ using namespace Microsoft::WRL::Wrappers;
extern nsresult XRE_metroStartup(bool runXREMain);
extern void XRE_metroShutdown();

static const char* gGeckoThreadName = "GeckoMain";

#ifdef PR_LOGGING
extern PRLogModuleInfo* gWindowsLog;
#endif
Expand Down Expand Up @@ -65,6 +68,12 @@ MetroApp::Run()
{
LogThread();

// Name this thread for debugging and register it with the profiler
// as the main gecko thread.
char aLocal;
PR_SetCurrentThreadName(gGeckoThreadName);
profiler_register_thread(gGeckoThreadName, &aLocal);

HRESULT hr;
hr = sCoreApp->add_Suspending(Callback<__FIEventHandler_1_Windows__CApplicationModel__CSuspendingEventArgs_t>(
this, &MetroApp::OnSuspending).Get(), &mSuspendEvent);
Expand Down Expand Up @@ -101,6 +110,9 @@ MetroApp::ShutdownXPCOM()

// Shut down xpcom
XRE_metroShutdown();

// Unhook this thread from the profiler
profiler_unregister_thread();
}

// Request a shutdown of the application
Expand Down

0 comments on commit 357604d

Please sign in to comment.