bug 1312778 - Ensure histogram recording is enabled before remote accumulation r?gfritzsche
There is a mechanism to selectively turn hgram recording off and on. This is
presently only used to throttle an otherwise-devastatingly-chatty hgram to only
contain accumulations from specific times (sync scroll).
This was only checked on the parent. This checks it on the child as well.
MozReview-Commit-ID: 4f0VXMHLaPW
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -1336,16 +1336,21 @@ void internal_armIPCTimer()
}
bool
internal_RemoteAccumulate(mozilla::Telemetry::ID aId, uint32_t aSample)
{
if (XRE_IsParentProcess()) {
return false;
}
+ Histogram *h;
+ nsresult rv = internal_GetHistogramByEnumId(aId, &h);
+ if (NS_SUCCEEDED(rv) && !h->IsRecordingEnabled()) {
+ return true;
+ }
if (!gAccumulations) {
gAccumulations = new nsTArray<Accumulation>();
}
if (gAccumulations->Length() == kAccumulationsArrayHighWaterMark) {
NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
TelemetryHistogram::IPCTimerFired(nullptr, nullptr);
}));
}
@@ -1356,16 +1361,23 @@ internal_RemoteAccumulate(mozilla::Telem
bool
internal_RemoteAccumulate(mozilla::Telemetry::ID aId,
const nsCString& aKey, uint32_t aSample)
{
if (XRE_IsParentProcess()) {
return false;
}
+ const HistogramInfo& th = gHistograms[aId];
+ KeyedHistogram* keyed
+ = internal_GetKeyedHistogramById(nsDependentCString(th.id()));
+ MOZ_ASSERT(keyed);
+ if (!keyed->IsRecordingEnabled()) {
+ return false;
+ }
if (!gKeyedAccumulations) {
gKeyedAccumulations = new nsTArray<KeyedAccumulation>();
}
if (gKeyedAccumulations->Length() == kAccumulationsArrayHighWaterMark) {
NS_DispatchToMainThread(NS_NewRunnableFunction([]() -> void {
TelemetryHistogram::IPCTimerFired(nullptr, nullptr);
}));
}
--- a/toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
+++ b/toolkit/components/telemetry/tests/unit/test_ChildHistograms.js
@@ -13,26 +13,33 @@ const APP_VERSION = "1";
const APP_ID = "xpcshell@tests.mozilla.org";
const APP_NAME = "XPCShell";
function run_child_test() {
// Setup histograms with some fixed values.
let flagHist = Telemetry.getHistogramById("TELEMETRY_TEST_FLAG");
flagHist.add(1);
let countHist = Telemetry.getHistogramById("TELEMETRY_TEST_COUNT");
+ Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_COUNT", false);
+ countHist.add();
+ Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_COUNT", true);
countHist.add();
countHist.add();
let categHist = Telemetry.getHistogramById("TELEMETRY_TEST_CATEGORICAL");
categHist.add("Label2");
categHist.add("Label3");
let flagKeyed = Telemetry.getKeyedHistogramById("TELEMETRY_TEST_KEYED_FLAG");
flagKeyed.add("a", 1);
flagKeyed.add("b", 1);
let countKeyed = Telemetry.getKeyedHistogramById("TELEMETRY_TEST_KEYED_COUNT");
+ Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_KEYED_COUNT", false);
+ countKeyed.add("a");
+ countKeyed.add("b");
+ Telemetry.setHistogramRecordingEnabled("TELEMETRY_TEST_KEYED_COUNT", true);
countKeyed.add("a");
countKeyed.add("b");
countKeyed.add("b");
}
function check_histogram_values(payload) {
const hs = payload.histograms;
Assert.ok("TELEMETRY_TEST_COUNT" in hs, "Should have count test histogram.");