void mozilla_sampler_stop() { if (!stack_key_initialized) profiler_init(); TableTicker *t = tlsTicker.get(); if (!t) { return; } bool disableJS = t->ProfileJS(); t->Stop(); delete t; tlsTicker.set(NULL); PseudoStack *stack = tlsPseudoStack.get(); ASSERT(stack != NULL); if (disableJS) stack->disableJSSampling(); sIsProfiling = false; nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); if (os) os->NotifyObservers(nullptr, "profiler-stopped", nullptr); }
// Values are only honored on the first start void mozilla_sampler_start(int aProfileEntries, int aInterval, const char** aFeatures, uint32_t aFeatureCount) { if (!stack_key_initialized) mozilla_sampler_init(); ProfileStack *stack = tlsStack.get(); if (!stack) { ASSERT(false); return; } mozilla_sampler_stop(); TableTicker *t = new TableTicker(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL, aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY, stack, aFeatures, aFeatureCount); tlsTicker.set(t); t->Start(); if (t->ProfileJS()) stack->enableJSSampling(); nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); if (os) os->NotifyObservers(nullptr, "profiler-started", nullptr); }
void mozilla_sampler_stop() { LOG("BEGIN mozilla_sampler_stop"); if (!stack_key_initialized) profiler_init(nullptr); TableTicker *t = tlsTicker.get(); if (!t) { LOG("END mozilla_sampler_stop-early"); return; } bool disableJS = t->ProfileJS(); bool unwinderThreader = t->HasUnwinderThread(); // Shut down and reap the unwinder thread. We have to do this // before stopping the sampler, so as to guarantee that the unwinder // thread doesn't try to access memory that the subsequent call to // mozilla_sampler_stop causes to be freed. if (unwinderThreader) { uwt__stop(); } t->Stop(); delete t; tlsTicker.set(nullptr); if (disableJS) { PseudoStack *stack = tlsPseudoStack.get(); ASSERT(stack != nullptr); stack->disableJSSampling(); } if (unwinderThreader) { uwt__deinit(); } mozilla::IOInterposer::Unregister(mozilla::IOInterposeObserver::OpAll, sInterposeObserver); sInterposeObserver = nullptr; sIsProfiling = false; if (Sampler::CanNotifyObservers()) { nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); if (os) os->NotifyObservers(nullptr, "profiler-stopped", nullptr); } LOG("END mozilla_sampler_stop"); }
// Values are only honored on the first start void mozilla_sampler_start(int aProfileEntries, int aInterval, const char** aFeatures, uint32_t aFeatureCount) { if (!stack_key_initialized) profiler_init(); /* If the sampling interval was set using env vars, use that in preference to anything else. */ if (sUnwindInterval > 0) aInterval = sUnwindInterval; PseudoStack *stack = tlsPseudoStack.get(); if (!stack) { ASSERT(false); return; } // Reset the current state if the profiler is running profiler_stop(); TableTicker* t; if (sps_version2()) { t = new BreakpadSampler(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL, aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY, aFeatures, aFeatureCount); } else { t = new TableTicker(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL, aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY, aFeatures, aFeatureCount); } tlsTicker.set(t); t->Start(); if (t->ProfileJS()) { mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex); std::vector<ThreadInfo*> threads = t->GetRegisteredThreads(); for (uint32_t i = 0; i < threads.size(); i++) { ThreadInfo* info = threads[i]; ThreadProfile* thread_profile = info->Profile(); if (!thread_profile) { continue; } thread_profile->GetPseudoStack()->enableJSSampling(); } } sIsProfiling = true; nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); if (os) os->NotifyObservers(nullptr, "profiler-started", nullptr); }
void mozilla_sampler_stop() { LOG("BEGIN mozilla_sampler_stop"); if (!stack_key_initialized) return; TableTicker *t = tlsTicker.get(); if (!t) { LOG("END mozilla_sampler_stop-early"); return; } bool disableJS = t->ProfileJS(); t->Stop(); delete t; tlsTicker.set(nullptr); #ifndef SPS_STANDALONE if (disableJS) { PseudoStack *stack = tlsPseudoStack.get(); ASSERT(stack != nullptr); stack->disableJSSampling(); } mozilla::IOInterposer::Unregister(mozilla::IOInterposeObserver::OpAll, sInterposeObserver); sInterposeObserver = nullptr; #endif sIsProfiling = false; #ifndef SPS_STANDALONE sIsGPUProfiling = false; sIsLayersDump = false; sIsDisplayListDump = false; sIsRestyleProfiling = false; if (Sampler::CanNotifyObservers()) { nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); if (os) os->NotifyObservers(nullptr, "profiler-stopped", nullptr); } #endif LOG("END mozilla_sampler_stop"); }
void mozilla_sampler_stop() { if (!stack_key_initialized) mozilla_sampler_init(); TableTicker *t = tlsTicker.get(); if (!t) { return; } bool disableJS = t->ProfileJS(); t->Stop(); delete t; tlsTicker.set(NULL); ProfileStack *stack = tlsStack.get(); ASSERT(stack != NULL); if (disableJS) stack->disableJSSampling(); }
// Values are only honored on the first start void mozilla_sampler_start(int aProfileEntries, int aInterval, const char** aFeatures, uint32_t aFeatureCount) { if (!stack_key_initialized) mozilla_sampler_init(); ProfileStack *stack = tlsStack.get(); if (!stack) { ASSERT(false); return; } mozilla_sampler_stop(); TableTicker *t = new TableTicker(aInterval, aProfileEntries, stack, aFeatures, aFeatureCount); tlsTicker.set(t); t->Start(); if (t->ProfileJS()) stack->enableJSSampling(); }
// Values are only honored on the first start void mozilla_sampler_start(int aProfileEntries, double aInterval, const char** aFeatures, uint32_t aFeatureCount, const char** aThreadNameFilters, uint32_t aFilterCount) { LOG("BEGIN mozilla_sampler_start"); if (!stack_key_initialized) profiler_init(nullptr); /* If the sampling interval was set using env vars, use that in preference to anything else. */ if (sUnwindInterval > 0) aInterval = sUnwindInterval; /* If the entry count was set using env vars, use that, too: */ if (sProfileEntries > 0) aProfileEntries = sProfileEntries; // Reset the current state if the profiler is running profiler_stop(); TableTicker* t; t = new TableTicker(aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL, aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY, aFeatures, aFeatureCount, aThreadNameFilters, aFilterCount); if (t->HasUnwinderThread()) { // Create the unwinder thread. ATM there is only one. uwt__init(); } tlsTicker.set(t); t->Start(); if (t->ProfileJS() || t->InPrivacyMode()) { mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex); std::vector<ThreadInfo*> threads = t->GetRegisteredThreads(); for (uint32_t i = 0; i < threads.size(); i++) { ThreadInfo* info = threads[i]; if (info->IsPendingDelete()) { continue; } ThreadProfile* thread_profile = info->Profile(); if (!thread_profile) { continue; } thread_profile->GetPseudoStack()->reinitializeOnResume(); if (t->ProfileJS()) { thread_profile->GetPseudoStack()->enableJSSampling(); } if (t->InPrivacyMode()) { thread_profile->GetPseudoStack()->mPrivacyMode = true; } } } #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK) if (t->ProfileJava()) { int javaInterval = aInterval; // Java sampling doesn't accuratly keep up with 1ms sampling if (javaInterval < 10) { aInterval = 10; } mozilla::widget::android::GeckoJavaSampler::StartJavaProfiling(javaInterval, 1000); } #endif if (t->AddMainThreadIO()) { if (!sInterposeObserver) { // Lazily create IO interposer observer sInterposeObserver = new mozilla::ProfilerIOInterposeObserver(); } mozilla::IOInterposer::Register(mozilla::IOInterposeObserver::OpAll, sInterposeObserver); } sIsProfiling = true; sIsGPUProfiling = t->ProfileGPU(); if (Sampler::CanNotifyObservers()) { nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); if (os) os->NotifyObservers(nullptr, "profiler-started", nullptr); } LOG("END mozilla_sampler_start"); }