Bug 1307746: Make capturing stacks thread safe. r?gfritzsche
MozReview-Commit-ID: B7p1bDdlk6k
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -483,16 +483,18 @@ private:
Mutex mStackCapturerMutex;
};
KeyedStackCapturer::KeyedStackCapturer()
: mStackCapturerMutex("Telemetry::StackCapturerMutex")
{}
void KeyedStackCapturer::Capture(const nsACString& aKey) {
+ MutexAutoLock captureStackMutex(mStackCapturerMutex);
+
// Check if the key is ok.
if (!IsKeyValid(aKey)) {
NS_WARNING(nsPrintfCString(
"Invalid key is used to capture stack in telemetry: '%s'",
PromiseFlatCString(aKey).get()
).get());
return;
}
@@ -519,17 +521,16 @@ void KeyedStackCapturer::Capture(const n
static_cast<std::vector<uintptr_t>*>(aClosure);
stack->push_back(reinterpret_cast<uintptr_t>(aPC));
};
MozStackWalk(callback, /* skipFrames */ 0,
/* maxFrames */ 0, reinterpret_cast<void*>(&rawStack), 0, nullptr);
Telemetry::ProcessedStack stack = Telemetry::GetStackAndModules(rawStack);
// Store the new stack info.
- MutexAutoLock captureStackMutex(mStackCapturerMutex);
size_t stackIndex = mStacks.AddStack(stack);
mStackInfos.Put(aKey, new StackFrequencyInfo(1, stackIndex));
}
NS_IMETHODIMP
KeyedStackCapturer::ReflectCapturedStacks(JSContext *cx, JS::MutableHandle<JS::Value> ret)
{
MutexAutoLock capturedStackMutex(mStackCapturerMutex);