mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1346356 (part 4) - Clean up notification in the profiler. r=mstange.
This patch does the following. - Introduces NotifyObservers() for the simple notification cases in platform.cpp. - Removes profiler_lock() and profiler_unlock() because they do notifications that the profiler add-on no longer listens for. --HG-- extra : rebase_source : 77a1868ba494dea314702bbdf9478a1da36c9efb
This commit is contained in:
parent
b152707def
commit
d4cea5f1de
@ -1774,7 +1774,7 @@ NotifyProfilerStarted(const int aEntries, double aInterval,
|
||||
}
|
||||
|
||||
static void
|
||||
NotifyProfilerStopped()
|
||||
NotifyObservers(const char* aTopic)
|
||||
{
|
||||
if (!CanNotifyObservers()) {
|
||||
return;
|
||||
@ -1785,7 +1785,7 @@ NotifyProfilerStopped()
|
||||
return;
|
||||
}
|
||||
|
||||
os->NotifyObservers(nullptr, "profiler-stopped", nullptr);
|
||||
os->NotifyObservers(nullptr, aTopic, nullptr);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1949,7 +1949,7 @@ profiler_shutdown()
|
||||
// We do these operations with gPSMutex unlocked. The comments in
|
||||
// profiler_stop() explain why.
|
||||
if (samplerThread) {
|
||||
NotifyProfilerStopped();
|
||||
NotifyObservers("profiler-stopped");
|
||||
delete samplerThread;
|
||||
}
|
||||
|
||||
@ -2392,7 +2392,7 @@ profiler_start(int aEntries, double aInterval,
|
||||
// We do these operations with gPSMutex unlocked. The comments in
|
||||
// profiler_stop() explain why.
|
||||
if (samplerThread) {
|
||||
NotifyProfilerStopped();
|
||||
NotifyObservers("profiler-stopped");
|
||||
delete samplerThread;
|
||||
}
|
||||
NotifyProfilerStarted(aEntries, aInterval, aFeatures, aFeatureCount,
|
||||
@ -2508,7 +2508,7 @@ profiler_stop()
|
||||
// We notify observers with gPSMutex unlocked. Otherwise we might get a
|
||||
// deadlock, if code run by the observer calls a profiler function that locks
|
||||
// gPSMutex. (This has been seen in practise in bug 1346356.)
|
||||
NotifyProfilerStopped();
|
||||
NotifyObservers("profiler-stopped");
|
||||
|
||||
// We delete with gPSMutex unlocked. Otherwise we would get a deadlock: we
|
||||
// would be waiting here with gPSMutex locked for SamplerThread::Run() to
|
||||
@ -2556,12 +2556,7 @@ profiler_pause()
|
||||
}
|
||||
|
||||
// gPSMutex must be unlocked when we notify, to avoid potential deadlocks.
|
||||
if (CanNotifyObservers()) {
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nullptr, "profiler-paused", nullptr);
|
||||
}
|
||||
}
|
||||
NotifyObservers("profiler-paused");
|
||||
}
|
||||
|
||||
void
|
||||
@ -2581,12 +2576,7 @@ profiler_resume()
|
||||
}
|
||||
|
||||
// gPSMutex must be unlocked when we notify, to avoid potential deadlocks.
|
||||
if (CanNotifyObservers()) {
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nullptr, "profiler-resumed", nullptr);
|
||||
}
|
||||
}
|
||||
NotifyObservers("profiler-resumed");
|
||||
}
|
||||
|
||||
bool
|
||||
@ -2644,31 +2634,6 @@ profiler_set_frame_number(int aFrameNumber)
|
||||
gPS->SetFrameNumber(lock, aFrameNumber);
|
||||
}
|
||||
|
||||
void
|
||||
profiler_lock()
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
||||
MOZ_RELEASE_ASSERT(gPS);
|
||||
|
||||
profiler_stop();
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nullptr, "profiler-locked", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
profiler_unlock()
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
||||
MOZ_RELEASE_ASSERT(gPS);
|
||||
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nullptr, "profiler-unlocked", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
profiler_register_thread(const char* aName, void* aGuessStackTop)
|
||||
{
|
||||
|
@ -56,17 +56,19 @@ nsProfiler::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const char16_t *aData)
|
||||
{
|
||||
// The profiler's handling of private browsing is as simple as possible: it
|
||||
// is stopped when the first PB window opens, and left stopped when the last
|
||||
// PB window closes.
|
||||
if (strcmp(aTopic, "chrome-document-global-created") == 0) {
|
||||
nsCOMPtr<nsIInterfaceRequestor> requestor = do_QueryInterface(aSubject);
|
||||
nsCOMPtr<nsIWebNavigation> parentWebNav = do_GetInterface(requestor);
|
||||
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(parentWebNav);
|
||||
if (loadContext && loadContext->UsePrivateBrowsing() && !mLockedForPrivateBrowsing) {
|
||||
mLockedForPrivateBrowsing = true;
|
||||
profiler_lock();
|
||||
profiler_stop();
|
||||
}
|
||||
} else if (strcmp(aTopic, "last-pb-context-exited") == 0) {
|
||||
mLockedForPrivateBrowsing = false;
|
||||
profiler_unlock();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -274,14 +274,6 @@ static inline void profiler_get_buffer_info(uint32_t* aCurrentPosition,
|
||||
profiler_get_buffer_info_helper(aCurrentPosition, aEntries, aGeneration);
|
||||
}
|
||||
|
||||
// Lock the profiler. When locked the profiler is (1) stopped,
|
||||
// (2) profile data is cleared, (3) 'profiler-locked' is fired.
|
||||
// This is used to lock down the profiler during private browsing.
|
||||
PROFILER_FUNC_VOID(profiler_lock())
|
||||
|
||||
// Unlock the profiler, leaving it stopped, and fire 'profiler-unlocked'.
|
||||
PROFILER_FUNC_VOID(profiler_unlock())
|
||||
|
||||
// Register/unregister threads with the profiler.
|
||||
PROFILER_FUNC_VOID(profiler_register_thread(const char* name,
|
||||
void* guessStackTop))
|
||||
|
Loading…
Reference in New Issue
Block a user