diff --git a/tools/profiler/TableTicker.cpp b/tools/profiler/TableTicker.cpp index 78204af6bb6..80fd6ed837e 100644 --- a/tools/profiler/TableTicker.cpp +++ b/tools/profiler/TableTicker.cpp @@ -283,13 +283,15 @@ void TableTicker::StreamJSObject(JSStreamWriter& b) } } - // Send a event asking any subprocesses (plugins) to - // give us their information - SubprocessClosure closure(&b); - nsCOMPtr os = mozilla::services::GetObserverService(); - if (os) { - nsRefPtr pse = new ProfileSaveEvent(SubProcessCallback, &closure); - os->NotifyObservers(pse, "profiler-subprocess", nullptr); + if (Sampler::CanNotifyObservers()) { + // Send a event asking any subprocesses (plugins) to + // give us their information + SubprocessClosure closure(&b); + nsCOMPtr os = mozilla::services::GetObserverService(); + if (os) { + nsRefPtr pse = new ProfileSaveEvent(SubProcessCallback, &closure); + os->NotifyObservers(pse, "profiler-subprocess", nullptr); + } } #if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK) @@ -306,7 +308,6 @@ void TableTicker::StreamJSObject(JSStreamWriter& b) b.EndArray(); b.EndObject(); - } // END SaveProfileTask et al diff --git a/tools/profiler/platform.cpp b/tools/profiler/platform.cpp index 5b01c42daba..5b5fd5d1c96 100644 --- a/tools/profiler/platform.cpp +++ b/tools/profiler/platform.cpp @@ -698,9 +698,11 @@ void mozilla_sampler_start(int aProfileEntries, double aInterval, sIsProfiling = true; - nsCOMPtr os = mozilla::services::GetObserverService(); - if (os) - os->NotifyObservers(nullptr, "profiler-started", nullptr); + if (Sampler::CanNotifyObservers()) { + nsCOMPtr os = mozilla::services::GetObserverService(); + if (os) + os->NotifyObservers(nullptr, "profiler-started", nullptr); + } LOG("END mozilla_sampler_start"); } @@ -749,9 +751,11 @@ void mozilla_sampler_stop() sIsProfiling = false; - nsCOMPtr os = mozilla::services::GetObserverService(); - if (os) - os->NotifyObservers(nullptr, "profiler-stopped", nullptr); + if (Sampler::CanNotifyObservers()) { + nsCOMPtr os = mozilla::services::GetObserverService(); + if (os) + os->NotifyObservers(nullptr, "profiler-stopped", nullptr); + } LOG("END mozilla_sampler_stop"); } diff --git a/tools/profiler/platform.h b/tools/profiler/platform.h index c0925c5a984..ea401cc005c 100644 --- a/tools/profiler/platform.h +++ b/tools/profiler/platform.h @@ -44,6 +44,7 @@ #include "mozilla/unused.h" #include "mozilla/TimeStamp.h" #include "mozilla/Mutex.h" +#include "MainThreadUtils.h" #include "PlatformMacros.h" #include "v8-support.h" #include @@ -353,6 +354,17 @@ class Sampler { static void SetActiveSampler(TableTicker* sampler) { sActiveSampler = sampler; } static mozilla::Mutex* sRegisteredThreadsMutex; + + static bool CanNotifyObservers() { +#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK) + // Android ANR reporter uses the profiler off the main thread + return NS_IsMainThread(); +#else + MOZ_ASSERT(NS_IsMainThread()); + return true; +#endif + } + protected: static std::vector* sRegisteredThreads; static TableTicker* sActiveSampler;