--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -277,42 +277,45 @@ const HistogramID kRecordingInitiallyDis
namespace {
size_t internal_KeyedHistogramStorageIndex(HistogramID aHistogramId,
ProcessID aProcessId)
{
return aHistogramId * size_t(ProcessID::Count) + size_t(aProcessId);
}
-size_t internal_HistogramStorageIndex(HistogramID aHistogramId,
+size_t internal_HistogramStorageIndex(const StaticMutexAutoLock& aLock,
+ HistogramID aHistogramId,
ProcessID aProcessId)
{
static_assert(
HistogramCount <
std::numeric_limits<size_t>::max() / size_t(ProcessID::Count),
"Too many histograms and processes to store in a 1D array.");
return aHistogramId * size_t(ProcessID::Count) + size_t(aProcessId);
}
-Histogram* internal_GetHistogramFromStorage(HistogramID aHistogramId,
+Histogram* internal_GetHistogramFromStorage(const StaticMutexAutoLock& aLock,
+ HistogramID aHistogramId,
ProcessID aProcessId)
{
- size_t index = internal_HistogramStorageIndex(aHistogramId, aProcessId);
+ size_t index = internal_HistogramStorageIndex(aLock, aHistogramId, aProcessId);
return gHistogramStorage[index];
}
-void internal_SetHistogramInStorage(HistogramID aHistogramId,
+void internal_SetHistogramInStorage(const StaticMutexAutoLock& aLock,
+ HistogramID aHistogramId,
ProcessID aProcessId,
Histogram* aHistogram)
{
MOZ_ASSERT(XRE_IsParentProcess(),
"Histograms are stored only in the parent process.");
- size_t index = internal_HistogramStorageIndex(aHistogramId, aProcessId);
+ size_t index = internal_HistogramStorageIndex(aLock, aHistogramId, aProcessId);
MOZ_ASSERT(!gHistogramStorage[index],
"Mustn't overwrite storage without clearing it first.");
gHistogramStorage[index] = aHistogram;
}
KeyedHistogram* internal_GetKeyedHistogramFromStorage(HistogramID aHistogramId,
ProcessID aProcessId)
{
@@ -341,32 +344,35 @@ bool
internal_IsHistogramEnumId(HistogramID aID)
{
static_assert(((HistogramID)-1 > 0), "ID should be unsigned.");
return aID < HistogramCount;
}
// Look up a plain histogram by id.
Histogram*
-internal_GetHistogramById(HistogramID histogramId, ProcessID processId, bool instantiate = true)
+internal_GetHistogramById(const StaticMutexAutoLock& aLock,
+ HistogramID histogramId,
+ ProcessID processId,
+ bool instantiate = true)
{
MOZ_ASSERT(internal_IsHistogramEnumId(histogramId));
MOZ_ASSERT(!gHistogramInfos[histogramId].keyed);
MOZ_ASSERT(processId < ProcessID::Count);
- Histogram* h = internal_GetHistogramFromStorage(histogramId, processId);
+ Histogram* h = internal_GetHistogramFromStorage(aLock, histogramId, processId);
if (h || !instantiate) {
return h;
}
const HistogramInfo& info = gHistogramInfos[histogramId];
const int bucketsOffset = gHistogramBucketLowerBoundIndex[histogramId];
h = internal_CreateHistogramInstance(info, bucketsOffset);
MOZ_ASSERT(h);
- internal_SetHistogramInStorage(histogramId, processId, h);
+ internal_SetHistogramInStorage(aLock, histogramId, processId, h);
return h;
}
// Look up a keyed histogram by id.
KeyedHistogram*
internal_GetKeyedHistogramById(HistogramID histogramId, ProcessID processId,
bool instantiate = true)
{
@@ -384,31 +390,35 @@ internal_GetKeyedHistogramById(Histogram
kh = new KeyedHistogram(histogramId, info);
internal_SetKeyedHistogramInStorage(histogramId, processId, kh);
return kh;
}
// Look up a histogram id from a histogram name.
nsresult
-internal_GetHistogramIdByName(const nsACString& name, HistogramID* id)
+internal_GetHistogramIdByName(const StaticMutexAutoLock& aLock,
+ const nsACString& name,
+ HistogramID* id)
{
const bool found = gNameToHistogramIDMap.Get(name, id);
if (!found) {
return NS_ERROR_ILLEGAL_VALUE;
}
return NS_OK;
}
// Clear a histogram from storage.
void
-internal_ClearHistogramById(HistogramID histogramId, ProcessID processId)
+internal_ClearHistogramById(const StaticMutexAutoLock& aLock,
+ HistogramID histogramId,
+ ProcessID processId)
{
- size_t index = internal_HistogramStorageIndex(histogramId, processId);
+ size_t index = internal_HistogramStorageIndex(aLock, histogramId, processId);
if (gHistogramStorage[index] == gExpiredHistogram) {
// We keep gExpiredHistogram until TelemetryHistogram::DeInitializeGlobalState
return;
}
delete gHistogramStorage[index];
gHistogramStorage[index] = nullptr;
}
@@ -438,29 +448,31 @@ internal_AttemptedGPUProcess() {
if (auto gpm = mozilla::gfx::GPUProcessManager::Get()) {
attemptedGPUProcess = gpm->AttemptedGPUProcess();
}
return attemptedGPUProcess;
}
// Note: this is completely unrelated to mozilla::IsEmpty.
bool
-internal_IsEmpty(const Histogram *h)
+internal_IsEmpty(const StaticMutexAutoLock& aLock, const Histogram *h)
{
return h->is_empty();
}
bool
-internal_IsExpired(Histogram* h)
+internal_IsExpired(const StaticMutexAutoLock& aLock, Histogram* h)
{
return h == gExpiredHistogram;
}
void
-internal_SetHistogramRecordingEnabled(HistogramID id, bool aEnabled)
+internal_SetHistogramRecordingEnabled(const StaticMutexAutoLock& aLock,
+ HistogramID id,
+ bool aEnabled)
{
MOZ_ASSERT(internal_IsHistogramEnumId(id));
gHistogramRecordingDisabled[id] = !aEnabled;
}
bool
internal_IsRecordingEnabled(HistogramID id)
{
@@ -619,17 +631,18 @@ internal_CreateHistogramInstance(const H
if (isExpired) {
gExpiredHistogram = h;
}
return h;
}
nsresult
-internal_HistogramAdd(Histogram& histogram,
+internal_HistogramAdd(const StaticMutexAutoLock& aLock,
+ Histogram& histogram,
const HistogramID id,
uint32_t value,
ProcessID aProcessType)
{
// Check if we are allowed to record the data.
bool canRecordDataset = CanRecordDataset(gHistogramInfos[id].dataset,
internal_CanRecordBase(),
internal_CanRecordExtended());
@@ -759,24 +772,24 @@ internal_ReflectHistogramAndSamples(JSCo
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}
bool
-internal_ShouldReflectHistogram(Histogram* h, HistogramID id)
+internal_ShouldReflectHistogram(const StaticMutexAutoLock& aLock, Histogram* h, HistogramID id)
{
// Only flag histograms are serialized when they are empty.
// This has historical reasons, changing this will require downstream changes.
// The cheaper path here is to just deprecate flag histograms in favor
// of scalars.
uint32_t type = gHistogramInfos[id].histogramType;
- if (internal_IsEmpty(h) && type != nsITelemetry::HISTOGRAM_FLAG) {
+ if (internal_IsEmpty(aLock, h) && type != nsITelemetry::HISTOGRAM_FLAG) {
return false;
}
// Don't reflect the histogram if it's not allowed in this product.
if (!CanRecordProduct(gHistogramInfos[id].products)) {
return false;
}
@@ -823,19 +836,19 @@ internal_GetHistogramsSnapshot(const Sta
}
if (!IsInDataset(info.dataset, aDataset)) {
continue;
}
bool shouldInstantiate =
info.histogramType == nsITelemetry::HISTOGRAM_FLAG;
- Histogram* h = internal_GetHistogramById(id, ProcessID(process),
+ Histogram* h = internal_GetHistogramById(aLock, id, ProcessID(process),
shouldInstantiate);
- if (!h || internal_IsExpired(h) || !internal_ShouldReflectHistogram(h, id)) {
+ if (!h || internal_IsExpired(aLock, h) || !internal_ShouldReflectHistogram(aLock, h, id)) {
continue;
}
HistogramSnapshotData snapshotData;
if (NS_FAILED(internal_GetHistogramAndSamples(aLock, h, snapshotData))) {
continue;
}
@@ -1147,101 +1160,104 @@ internal_GetKeyedHistogramsSnapshot(cons
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
// PRIVATE: thread-unsafe helpers for the external interface
namespace {
bool
-internal_RemoteAccumulate(HistogramID aId, uint32_t aSample)
+internal_RemoteAccumulate(const StaticMutexAutoLock& aLock, HistogramID aId, uint32_t aSample)
{
if (XRE_IsParentProcess()) {
return false;
}
if (!internal_IsRecordingEnabled(aId)) {
return true;
}
TelemetryIPCAccumulator::AccumulateChildHistogram(aId, aSample);
return true;
}
bool
-internal_RemoteAccumulate(HistogramID aId,
+internal_RemoteAccumulate(const StaticMutexAutoLock& aLock, HistogramID aId,
const nsCString& aKey, uint32_t aSample)
{
if (XRE_IsParentProcess()) {
return false;
}
if (!internal_IsRecordingEnabled(aId)) {
return true;
}
TelemetryIPCAccumulator::AccumulateChildKeyedHistogram(aId, aKey, aSample);
return true;
}
-void internal_Accumulate(HistogramID aId, uint32_t aSample)
+void internal_Accumulate(const StaticMutexAutoLock& aLock, HistogramID aId, uint32_t aSample)
{
if (!internal_CanRecordBase() ||
- internal_RemoteAccumulate(aId, aSample)) {
+ internal_RemoteAccumulate(aLock, aId, aSample)) {
return;
}
- Histogram *h = internal_GetHistogramById(aId, ProcessID::Parent);
+ Histogram *h = internal_GetHistogramById(aLock, aId, ProcessID::Parent);
MOZ_ASSERT(h);
- internal_HistogramAdd(*h, aId, aSample, ProcessID::Parent);
+ internal_HistogramAdd(aLock, *h, aId, aSample, ProcessID::Parent);
}
void
-internal_Accumulate(HistogramID aId,
+internal_Accumulate(const StaticMutexAutoLock& aLock, HistogramID aId,
const nsCString& aKey, uint32_t aSample)
{
if (!gInitDone || !internal_CanRecordBase() ||
- internal_RemoteAccumulate(aId, aKey, aSample)) {
+ internal_RemoteAccumulate(aLock, aId, aKey, aSample)) {
return;
}
KeyedHistogram* keyed = internal_GetKeyedHistogramById(aId, ProcessID::Parent);
MOZ_ASSERT(keyed);
keyed->Add(aKey, aSample, ProcessID::Parent);
}
void
-internal_AccumulateChild(ProcessID aProcessType, HistogramID aId, uint32_t aSample)
+internal_AccumulateChild(const StaticMutexAutoLock& aLock,
+ ProcessID aProcessType,
+ HistogramID aId,
+ uint32_t aSample)
{
if (!internal_CanRecordBase()) {
return;
}
- if (Histogram* h = internal_GetHistogramById(aId, aProcessType)) {
- internal_HistogramAdd(*h, aId, aSample, aProcessType);
+ if (Histogram* h = internal_GetHistogramById(aLock, aId, aProcessType)) {
+ internal_HistogramAdd(aLock, *h, aId, aSample, aProcessType);
} else {
NS_WARNING("Failed GetHistogramById for CHILD");
}
}
void
-internal_AccumulateChildKeyed(ProcessID aProcessType, HistogramID aId,
- const nsCString& aKey, uint32_t aSample)
+internal_AccumulateChildKeyed(const StaticMutexAutoLock& aLock, ProcessID aProcessType,
+ HistogramID aId, const nsCString& aKey, uint32_t aSample)
{
if (!gInitDone || !internal_CanRecordBase()) {
return;
}
KeyedHistogram* keyed = internal_GetKeyedHistogramById(aId, aProcessType);
MOZ_ASSERT(keyed);
keyed->Add(aKey, aSample, aProcessType);
}
void
-internal_ClearHistogram(HistogramID id)
+internal_ClearHistogram(const StaticMutexAutoLock& aLock, HistogramID id)
{
MOZ_ASSERT(XRE_IsParentProcess());
if (!XRE_IsParentProcess()) {
return;
}
// Handle keyed histograms.
if (gHistogramInfos[id].keyed) {
@@ -1250,17 +1266,17 @@ internal_ClearHistogram(HistogramID id)
if (kh) {
kh->Clear();
}
}
}
// Now reset the histograms instances for all processes.
for (uint32_t process = 0; process < static_cast<uint32_t>(ProcessID::Count); ++process) {
- internal_ClearHistogramById(id, static_cast<ProcessID>(process));
+ internal_ClearHistogramById(aLock, id, static_cast<ProcessID>(process));
}
}
} // namespace
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
@@ -1450,17 +1466,17 @@ internal_JSHistogram_Add(JSContext *cx,
// Either GetValueArray or CoerceValue utility function will have printed a meaningful
// error message, so we simply return true
return true;
}
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for (uint32_t aValue: values) {
- internal_Accumulate(id, aValue);
+ internal_Accumulate(locker, id, aValue);
}
}
return true;
}
bool
internal_JSHistogram_Snapshot(JSContext *cx, unsigned argc, JS::Value *vp)
{
@@ -1480,17 +1496,17 @@ internal_JSHistogram_Snapshot(JSContext
HistogramSnapshotData dataSnapshot;
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
MOZ_ASSERT(internal_IsHistogramEnumId(id));
// This is not good standard behavior given that we have histogram instances
// covering multiple processes.
// However, changing this requires some broader changes to callers.
- Histogram* h = internal_GetHistogramById(id, ProcessID::Parent);
+ Histogram* h = internal_GetHistogramById(locker, id, ProcessID::Parent);
// Take a snapshot of the data here, protected by the lock, and then,
// outside of the lock protection, mirror it to a JS structure
if (NS_FAILED(internal_GetHistogramAndSamples(locker, h, dataSnapshot))) {
return false;
}
}
JS::Rooted<JSObject*> snapshot(cx, JS_NewPlainObject(cx));
@@ -1528,17 +1544,17 @@ internal_JSHistogram_Clear(JSContext *cx
// rather report failures using the console.
args.rval().setUndefined();
HistogramID id = data->histogramId;
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
MOZ_ASSERT(internal_IsHistogramEnumId(id));
- internal_ClearHistogram(id);
+ internal_ClearHistogram(locker, id);
}
return true;
}
// NOTE: Runs without protection from |gTelemetryHistogramMutex|.
// See comment at the top of this section.
nsresult
@@ -1762,17 +1778,17 @@ internal_JSKeyedHistogram_Add(JSContext
// Either GetValueArray or CoerceValue utility function will have printed a meaningful
// error message so we simple return true
return true;
}
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for (uint32_t aValue: values) {
- internal_Accumulate(id, NS_ConvertUTF16toUTF8(key), aValue);
+ internal_Accumulate(locker, id, NS_ConvertUTF16toUTF8(key), aValue);
}
}
return true;
}
bool
internal_JSKeyedHistogram_Keys(JSContext *cx, unsigned argc, JS::Value *vp)
{
@@ -2038,21 +2054,22 @@ TelemetryHistogram::InitHistogramRecordi
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
auto processType = XRE_GetProcessType();
for (size_t i = 0; i < HistogramCount; ++i) {
const HistogramInfo& h = gHistogramInfos[i];
mozilla::Telemetry::HistogramID id = mozilla::Telemetry::HistogramID(i);
bool canRecordInProcess = CanRecordInProcess(h.record_in_processes, processType);
bool canRecordProduct = CanRecordProduct(h.products);
- internal_SetHistogramRecordingEnabled(id, canRecordInProcess && canRecordProduct);
+ internal_SetHistogramRecordingEnabled(locker, id, canRecordInProcess && canRecordProduct);
}
for (auto recordingInitiallyDisabledID : kRecordingInitiallyDisabledIDs) {
- internal_SetHistogramRecordingEnabled(recordingInitiallyDisabledID,
+ internal_SetHistogramRecordingEnabled(locker,
+ recordingInitiallyDisabledID,
false);
}
}
void
TelemetryHistogram::SetHistogramRecordingEnabled(HistogramID aID,
bool aEnabled)
{
@@ -2068,64 +2085,64 @@ TelemetryHistogram::SetHistogramRecordin
}
if (!CanRecordProduct(h.products)) {
// Don't permit products-disabled recording to be re-enabled.
return;
}
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
- internal_SetHistogramRecordingEnabled(aID, aEnabled);
+ internal_SetHistogramRecordingEnabled(locker, aID, aEnabled);
}
nsresult
TelemetryHistogram::SetHistogramRecordingEnabled(const nsACString& name,
bool aEnabled)
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
HistogramID id;
- if (NS_FAILED(internal_GetHistogramIdByName(name, &id))) {
+ if (NS_FAILED(internal_GetHistogramIdByName(locker, name, &id))) {
return NS_ERROR_FAILURE;
}
const HistogramInfo& hi = gHistogramInfos[id];
if (CanRecordInProcess(hi.record_in_processes, XRE_GetProcessType())) {
- internal_SetHistogramRecordingEnabled(id, aEnabled);
+ internal_SetHistogramRecordingEnabled(locker, id, aEnabled);
}
return NS_OK;
}
void
TelemetryHistogram::Accumulate(HistogramID aID,
uint32_t aSample)
{
if (NS_WARN_IF(!internal_IsHistogramEnumId(aID))) {
MOZ_ASSERT_UNREACHABLE("Histogram usage requires valid ids.");
return;
}
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
- internal_Accumulate(aID, aSample);
+ internal_Accumulate(locker, aID, aSample);
}
void
TelemetryHistogram::Accumulate(HistogramID aID, const nsTArray<uint32_t>& aSamples)
{
if (NS_WARN_IF(!internal_IsHistogramEnumId(aID))) {
MOZ_ASSERT_UNREACHABLE("Histogram usage requires valid ids.");
return;
}
MOZ_ASSERT(!gHistogramInfos[aID].keyed, "Cannot accumulate into a keyed histogram. No key given.");
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for(uint32_t sample: aSamples){
- internal_Accumulate(aID, sample);
+ internal_Accumulate(locker, aID, sample);
}
}
void
TelemetryHistogram::Accumulate(HistogramID aID,
const nsCString& aKey, uint32_t aSample)
{
if (NS_WARN_IF(!internal_IsHistogramEnumId(aID))) {
@@ -2141,17 +2158,17 @@ TelemetryHistogram::Accumulate(Histogram
LogToBrowserConsole(nsIScriptError::errorFlag, NS_ConvertUTF8toUTF16(msg));
TelemetryScalar::Add(
mozilla::Telemetry::ScalarID::TELEMETRY_ACCUMULATE_UNKNOWN_HISTOGRAM_KEYS,
NS_ConvertASCIItoUTF16(gHistogramInfos[aID].name()), 1);
return;
}
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
- internal_Accumulate(aID, aKey, aSample);
+ internal_Accumulate(locker, aID, aKey, aSample);
}
void
TelemetryHistogram::Accumulate(HistogramID aID, const nsCString& aKey,
const nsTArray<uint32_t>& aSamples)
{
if (NS_WARN_IF(!internal_IsHistogramEnumId(aID))) {
MOZ_ASSERT_UNREACHABLE("Histogram usage requires valid ids");
@@ -2170,52 +2187,52 @@ TelemetryHistogram::Accumulate(Histogram
TelemetryScalar::Add(
mozilla::Telemetry::ScalarID::TELEMETRY_ACCUMULATE_UNKNOWN_HISTOGRAM_KEYS,
NS_ConvertASCIItoUTF16(gHistogramInfos[aID].name()), 1);
return;
}
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for(uint32_t sample: aSamples){
- internal_Accumulate(aID, aKey, sample);
+ internal_Accumulate(locker, aID, aKey, sample);
}
}
void
TelemetryHistogram::Accumulate(const char* name, uint32_t sample)
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
if (!internal_CanRecordBase()) {
return;
}
HistogramID id;
- nsresult rv = internal_GetHistogramIdByName(nsDependentCString(name), &id);
+ nsresult rv = internal_GetHistogramIdByName(locker, nsDependentCString(name), &id);
if (NS_FAILED(rv)) {
return;
}
- internal_Accumulate(id, sample);
+ internal_Accumulate(locker, id, sample);
}
void
TelemetryHistogram::Accumulate(const char* name,
const nsCString& key, uint32_t sample)
{
bool keyNotAllowed = false;
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
if (!internal_CanRecordBase()) {
return;
}
HistogramID id;
- nsresult rv = internal_GetHistogramIdByName(nsDependentCString(name), &id);
+ nsresult rv = internal_GetHistogramIdByName(locker, nsDependentCString(name), &id);
if (NS_SUCCEEDED(rv)) {
// Check if we're allowed to record in the provided key, for this histogram.
if (gHistogramInfos[id].allows_key(key)) {
- internal_Accumulate(id, key, sample);
+ internal_Accumulate(locker, id, key, sample);
return;
}
// We're holding |gTelemetryHistogramMutex|, so we can't print a message
// here.
keyNotAllowed = true;
}
}
@@ -2240,17 +2257,17 @@ TelemetryHistogram::AccumulateCategorica
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
if (!internal_CanRecordBase()) {
return;
}
uint32_t labelId = 0;
if (NS_FAILED(gHistogramInfos[aId].label_id(label.get(), &labelId))) {
return;
}
- internal_Accumulate(aId, labelId);
+ internal_Accumulate(locker, aId, labelId);
}
void
TelemetryHistogram::AccumulateCategorical(HistogramID aId, const nsTArray<nsCString>& aLabels)
{
if (NS_WARN_IF(!internal_IsHistogramEnumId(aId))) {
MOZ_ASSERT_UNREACHABLE("Histogram usage requires valid ids.");
return;
@@ -2272,17 +2289,17 @@ TelemetryHistogram::AccumulateCategorica
return;
}
intSamples.AppendElement(labelId);
}
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for (uint32_t sample: intSamples){
- internal_Accumulate(aId, sample);
+ internal_Accumulate(locker, aId, sample);
}
}
void
TelemetryHistogram::AccumulateChild(ProcessID aProcessType,
const nsTArray<HistogramAccumulation>& aAccumulations)
{
MOZ_ASSERT(XRE_IsParentProcess());
@@ -2291,17 +2308,20 @@ TelemetryHistogram::AccumulateChild(Proc
if (!internal_CanRecordBase()) {
return;
}
for (uint32_t i = 0; i < aAccumulations.Length(); ++i) {
if (NS_WARN_IF(!internal_IsHistogramEnumId(aAccumulations[i].mId))) {
MOZ_ASSERT_UNREACHABLE("Histogram usage requires valid ids.");
continue;
}
- internal_AccumulateChild(aProcessType, aAccumulations[i].mId, aAccumulations[i].mSample);
+ internal_AccumulateChild(locker,
+ aProcessType,
+ aAccumulations[i].mId,
+ aAccumulations[i].mSample);
}
}
void
TelemetryHistogram::AccumulateChildKeyed(ProcessID aProcessType,
const nsTArray<KeyedHistogramAccumulation>& aAccumulations)
{
MOZ_ASSERT(XRE_IsParentProcess());
@@ -2309,31 +2329,32 @@ TelemetryHistogram::AccumulateChildKeyed
if (!internal_CanRecordBase()) {
return;
}
for (uint32_t i = 0; i < aAccumulations.Length(); ++i) {
if (NS_WARN_IF(!internal_IsHistogramEnumId(aAccumulations[i].mId))) {
MOZ_ASSERT_UNREACHABLE("Histogram usage requires valid ids.");
continue;
}
- internal_AccumulateChildKeyed(aProcessType,
+ internal_AccumulateChildKeyed(locker,
+ aProcessType,
aAccumulations[i].mId,
aAccumulations[i].mKey,
aAccumulations[i].mSample);
}
}
nsresult
TelemetryHistogram::GetHistogramById(const nsACString &name, JSContext *cx,
JS::MutableHandle<JS::Value> ret)
{
HistogramID id;
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
- nsresult rv = internal_GetHistogramIdByName(name, &id);
+ nsresult rv = internal_GetHistogramIdByName(locker, name, &id);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
if (gHistogramInfos[id].keyed) {
return NS_ERROR_FAILURE;
}
}
@@ -2344,17 +2365,17 @@ TelemetryHistogram::GetHistogramById(con
nsresult
TelemetryHistogram::GetKeyedHistogramById(const nsACString &name,
JSContext *cx,
JS::MutableHandle<JS::Value> ret)
{
HistogramID id;
{
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
- nsresult rv = internal_GetHistogramIdByName(name, &id);
+ nsresult rv = internal_GetHistogramIdByName(locker, name, &id);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
if (!gHistogramInfos[id].keyed) {
return NS_ERROR_FAILURE;
}
}
@@ -2892,31 +2913,31 @@ TelemetryHistogram::DeserializeHistogram
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for (uint32_t process = 0; process < histogramsToUpdate.length(); ++process) {
PersistedHistogramArray& processArray = histogramsToUpdate[process];
for (auto& histogramData : processArray) {
// Attempt to get the corresponding ID for the deserialized histogram name.
HistogramID id;
- if (NS_FAILED(internal_GetHistogramIdByName(mozilla::Get<0>(histogramData), &id))) {
+ if (NS_FAILED(internal_GetHistogramIdByName(locker, mozilla::Get<0>(histogramData), &id))) {
continue;
}
ProcessID procID = static_cast<ProcessID>(process);
if (!internal_CanRecordHistogram(id, procID)) {
// We're not allowed to record this, so don't try to restore it.
continue;
}
// Get the Histogram instance: this will instantiate it if it doesn't exist.
- Histogram* h = internal_GetHistogramById(id, procID);
+ Histogram* h = internal_GetHistogramById(locker, id, procID);
MOZ_ASSERT(h);
- if (!h || internal_IsExpired(h)) {
+ if (!h || internal_IsExpired(locker, h)) {
// Don't restore expired histograms.
continue;
}
// Make sure that histogram counts have matching sizes. If not,
// |AddSampleSet| will fail and crash.
size_t numCounts = mozilla::Get<1>(histogramData).Length();
if (h->bucket_count() != numCounts) {
@@ -3075,17 +3096,17 @@ TelemetryHistogram::DeserializeKeyedHist
StaticMutexAutoLock locker(gTelemetryHistogramMutex);
for (uint32_t process = 0; process < histogramsToUpdate.length(); ++process) {
PersistedKeyedHistogramArray& processArray = histogramsToUpdate[process];
for (auto& histogramData : processArray) {
// Attempt to get the corresponding ID for the deserialized histogram name.
HistogramID id;
- if (NS_FAILED(internal_GetHistogramIdByName(mozilla::Get<0>(histogramData), &id))) {
+ if (NS_FAILED(internal_GetHistogramIdByName(locker, mozilla::Get<0>(histogramData), &id))) {
continue;
}
ProcessID procID = static_cast<ProcessID>(process);
if (!internal_CanRecordHistogram(id, procID)) {
// We're not allowed to record this, so don't try to restore it.
continue;
}
@@ -3100,17 +3121,17 @@ TelemetryHistogram::DeserializeKeyedHist
// Get data for the key we're looking for.
Histogram* h = nullptr;
if (NS_FAILED(keyed->GetHistogram(mozilla::Get<1>(histogramData), &h))) {
continue;
}
MOZ_ASSERT(h);
- if (!h || internal_IsExpired(h)) {
+ if (!h || internal_IsExpired(locker, h)) {
// Don't restore expired histograms.
continue;
}
// Make sure that histogram counts have matching sizes. If not,
// |AddSampleSet| will fail and crash.
size_t numCounts = mozilla::Get<2>(histogramData).Length();
if (h->bucket_count() != numCounts) {