Bug 999071 - Don't notify observers in profiler when used by Android ANR reporter; r=BenWa

This commit is contained in:
Jim Chen 2014-04-24 17:49:01 -04:00
parent 9342b7fdec
commit b807184a9a
3 changed files with 31 additions and 14 deletions

View File

@ -283,6 +283,7 @@ void TableTicker::StreamJSObject(JSStreamWriter& b)
}
}
if (Sampler::CanNotifyObservers()) {
// Send a event asking any subprocesses (plugins) to
// give us their information
SubprocessClosure closure(&b);
@ -291,6 +292,7 @@ void TableTicker::StreamJSObject(JSStreamWriter& b)
nsRefPtr<ProfileSaveEvent> pse = new ProfileSaveEvent(SubProcessCallback, &closure);
os->NotifyObservers(pse, "profiler-subprocess", nullptr);
}
}
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
if (ProfileJava()) {
@ -306,7 +308,6 @@ void TableTicker::StreamJSObject(JSStreamWriter& b)
b.EndArray();
b.EndObject();
}
// END SaveProfileTask et al

View File

@ -698,9 +698,11 @@ void mozilla_sampler_start(int aProfileEntries, double aInterval,
sIsProfiling = true;
if (Sampler::CanNotifyObservers()) {
nsCOMPtr<nsIObserverService> 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;
if (Sampler::CanNotifyObservers()) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(nullptr, "profiler-stopped", nullptr);
}
LOG("END mozilla_sampler_stop");
}

View File

@ -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 <vector>
@ -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<ThreadInfo*>* sRegisteredThreads;
static TableTicker* sActiveSampler;