Bug 1176992 - Allow hud.js to support custom metrics with exponential and counter histograms. r=janx

This commit is contained in:
Tamara Hills 2015-08-27 06:55:00 -04:00
Родитель 02f42b4abc
Коммит fa73711f0c
1 изменённых файлов: 48 добавлений и 17 удалений

Просмотреть файл

@ -366,18 +366,33 @@ Target.prototype = {
} else {
let histogramName = CUSTOM_HISTOGRAM_PREFIX + metricAppName + '_'
+ metricName;
if (!developerHUD._customHistograms.has(histogramName)) {
try {
Services.telemetry.registerAddonHistogram(metricAppName,
CUSTOM_HISTOGRAM_PREFIX + metricName,
Services.telemetry.HISTOGRAM_LINEAR, 1, 10000, 10);
developerHUD._customHistograms.add(histogramName);
} catch(err) {
console.error('Histogram error: ' + err);
}
// This is a call to add a value to an existing histogram.
if (typeof metric.value !== 'undefined') {
Services.telemetry.getAddonHistogram(metricAppName,
CUSTOM_HISTOGRAM_PREFIX + metricName).add(parseInt(metric.value, 10));
return;
}
// The histogram already exists and are not adding data to it.
if (developerHUD._customHistograms.has(histogramName)) {
return;
}
// This is a call to create a new histogram.
try {
let metricType = parseInt(metric.type, 10);
if (metricType === Services.telemetry.HISTOGRAM_COUNT) {
Services.telemetry.registerAddonHistogram(metricAppName,
CUSTOM_HISTOGRAM_PREFIX + metricName, metricType);
} else {
Services.telemetry.registerAddonHistogram(metricAppName,
CUSTOM_HISTOGRAM_PREFIX + metricName, metricType, metric.min,
metric.max, metric.buckets);
}
developerHUD._customHistograms.add(histogramName);
} catch (err) {
console.error('Histogram error: ' + err);
}
Services.telemetry.getAddonHistogram(metricAppName,
CUSTOM_HISTOGRAM_PREFIX + metricName).add(parseInt(metric.value, 10));
}
}
};
@ -588,24 +603,40 @@ let consoleWatcher = {
let TELEMETRY_IDENTIFIER_IDX = 0;
let NAME_IDX = 1;
let VALUE_IDX = 2;
let TYPE_IDX = 2;
let MIN_IDX = 3;
let MAX_IDX = 4;
let BUCKETS_IDX = 5;
let MAX_CUSTOM_ARGS = 6;
let MIN_CUSTOM_ARGS = 3;
if (telemetryData[TELEMETRY_IDENTIFIER_IDX] != 'telemetry' ||
telemetryData.length < 3 || telemetryData.length > 4) {
telemetryData.length < MIN_CUSTOM_ARGS ||
telemetryData.length > MAX_CUSTOM_ARGS) {
return;
}
let metric = {
name: telemetryData[NAME_IDX],
value: telemetryData[VALUE_IDX]
name: telemetryData[NAME_IDX]
};
if (metric.name == 'MGMT') {
if (metric.value == 'TIMETOSHIP') {
if (metric.name === 'MGMT') {
metric.value = telemetryData[VALUE_IDX];
if (metric.value === 'TIMETOSHIP') {
telemetryDebug('Received a Ship event');
target._sendTelemetryData();
} else if (metric.value == 'CLEARMETRICS') {
} else if (metric.value === 'CLEARMETRICS') {
target._clearTelemetryData();
}
} else {
if (telemetryData.length === MIN_CUSTOM_ARGS) {
metric.value = telemetryData[VALUE_IDX];
} else if (telemetryData.length === MAX_CUSTOM_ARGS) {
metric.type = telemetryData[TYPE_IDX];
metric.min = telemetryData[MIN_IDX];
metric.max = telemetryData[MAX_IDX];
metric.buckets = telemetryData[BUCKETS_IDX];
}
metric.custom = true;
target._logHistogram(metric);
}