Bug 1345262 (part 2) - Add profiler_{set,clear}_js_context(). r=mstange.

PseudoContext::sampleContext() is always called immediately after
profiler_get_pseudo_stack(). This patch introduces profiler_set_js_context()
and profiler_clear_js_context(), which replace the profiler_get_pseudo_stack()
+ sampleContext() pairs. This takes us a step closer to not having to export
PseudoStack outside the profiler.

--HG--
extra : rebase_source : 8558d1600eafd395cc696d31f3d21fb52a1a74b0
This commit is contained in:
Nicholas Nethercote 2017-03-09 17:06:35 +11:00
Родитель 8c96fbb044
Коммит d8023679e3
5 изменённых файлов: 38 добавлений и 14 удалений

Просмотреть файл

@ -2877,10 +2877,7 @@ WorkerThreadPrimaryRunnable::Run()
{
#ifdef MOZ_GECKO_PROFILER
PseudoStack* stack = profiler_get_pseudo_stack();
if (stack) {
stack->sampleContext(cx);
}
profiler_set_js_context(cx);
#endif
{
@ -2896,9 +2893,7 @@ WorkerThreadPrimaryRunnable::Run()
BackgroundChild::CloseForCurrentThread();
#ifdef MOZ_GECKO_PROFILER
if (stack) {
stack->sampleContext(nullptr);
}
profiler_clear_js_context();
#endif
}

Просмотреть файл

@ -1620,8 +1620,7 @@ XPCJSContext::~XPCJSContext()
#ifdef MOZ_GECKO_PROFILER
// Tell the profiler that the context is gone
if (PseudoStack* stack = profiler_get_pseudo_stack())
stack->sampleContext(nullptr);
profiler_clear_js_context();
#endif
Preferences::UnregisterCallback(ReloadPrefsCallback, JS_OPTIONS_DOT_STR, this);
@ -3495,8 +3494,7 @@ XPCJSContext::Initialize()
JS_SetWrapObjectCallbacks(cx, &WrapObjectCallbacks);
js::SetPreserveWrapperCallback(cx, PreserveWrapper);
#ifdef MOZ_GECKO_PROFILER
if (PseudoStack* stack = profiler_get_pseudo_stack())
stack->sampleContext(cx);
profiler_set_js_context(cx);
#endif
JS_SetAccumulateTelemetryCallback(cx, AccumulateTelemetryCallback);
js::SetActivityCallback(cx, ActivityCallback, this);

Просмотреть файл

@ -2949,6 +2949,36 @@ profiler_tracing(const char* aCategory, const char* aInfo,
locked_profiler_add_marker(lock, aInfo, marker);
}
void
profiler_set_js_context(JSContext* aCx)
{
// This function runs both on and off the main thread.
MOZ_ASSERT(aCx);
PseudoStack* stack = tlsPseudoStack.get();
if (!stack) {
return;
}
stack->sampleContext(aCx);
}
void
profiler_clear_js_context()
{
// This function runs both on and off the main thread.
MOZ_RELEASE_ASSERT(gPS);
PseudoStack* stack = tlsPseudoStack.get();
if (!stack) {
return;
}
stack->sampleContext(nullptr);
}
// END externally visible functions
////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -527,6 +527,9 @@ profiler_get_pseudo_stack(void)
return tlsPseudoStack.get();
}
void profiler_set_js_context(JSContext* aCx);
void profiler_clear_js_context();
class GeckoProfilerReporter final : public nsIMemoryReporter
{
public:

Просмотреть файл

@ -1022,9 +1022,7 @@ ShutdownXPCOM(nsIServiceManager* aServMgr)
// JS pseudo-stack's internal reference to the main thread JSContext,
// duplicating the call in XPCJSContext::~XPCJSContext() in case that
// never fired.
if (PseudoStack* stack = profiler_get_pseudo_stack()) {
stack->sampleContext(nullptr);
}
profiler_clear_js_context();
#endif
if (sInitializedJS) {