Bug 1321617 - Reduce the scope of the lock in profiler_get_profile. r?njn
MozReview-Commit-ID: 5OmVMwy1yMl
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -1415,16 +1415,34 @@ locked_profiler_stream_json_for_this_pro
}
#endif
gPS->SetIsPaused(aLock, false);
}
aWriter.EndArray();
}
+static bool
+profiler_stream_json_for_this_process(SpliceableJSONWriter& aWriter, double aSinceTime)
+{
+ LOG("locked_profiler_stream_json_for_this_process");
+
+ MOZ_RELEASE_ASSERT(NS_IsMainThread());
+ MOZ_RELEASE_ASSERT(gPS);
+
+ PS::AutoLock lock(gPSMutex);
+
+ if (!gPS->IsActive(lock)) {
+ return false;
+ }
+
+ locked_profiler_stream_json_for_this_process(lock, aWriter, aSinceTime);
+ return true;
+}
+
// END saving/streaming code
////////////////////////////////////////////////////////////////////////
ProfilerMarker::ProfilerMarker(const char* aMarkerName,
ProfilerMarkerPayload* aPayload,
double aTime)
: mMarkerName(strdup(aMarkerName))
, mPayload(aPayload)
@@ -2093,32 +2111,24 @@ profiler_shutdown()
UniquePtr<char[]>
profiler_get_profile(double aSinceTime)
{
LOG("profiler_get_profile");
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(gPS);
- PS::AutoLock lock(gPSMutex);
-
- if (!gPS->IsActive(lock)) {
- return nullptr;
- }
-
SpliceableChunkedJSONWriter b;
b.Start(SpliceableJSONWriter::SingleLineStyle);
{
- locked_profiler_stream_json_for_this_process(lock, b, aSinceTime);
+ if (!profiler_stream_json_for_this_process(b, aSinceTime)) {
+ return nullptr;
+ }
b.StartArrayProperty("processes");
- // When notifying observers in other places in this file we are careful
- // to do it when gPSMutex is unlocked, to avoid deadlocks. But that's not
- // necessary here, because "profiler-subprocess" observers just call back
- // into SubprocessCallback, which is simple and doesn't lock gPSMutex.
if (CanNotifyObservers()) {
// Send a event asking any subprocesses (plugins) to
// give us their information
SubprocessClosure closure(&b);
nsCOMPtr<nsIObserverService> os =
mozilla::services::GetObserverService();
if (os) {
RefPtr<ProfileSaveEvent> pse =