Bug 668312 - Report only probes defined in TelemetryHistograms.h r=Mossop

This commit is contained in:
Taras Glek 2011-06-30 14:58:00 -07:00
Родитель b6b612f8d8
Коммит 4cfc91c2f2
5 изменённых файлов: 22 добавлений и 7 удалений

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

@ -121,13 +121,13 @@ HistogramGet(const char *name, PRUint32 min, PRUint32 max, PRUint32 bucketCount,
switch (histogramType) { switch (histogramType) {
case nsITelemetry::HISTOGRAM_EXPONENTIAL: case nsITelemetry::HISTOGRAM_EXPONENTIAL:
*result = Histogram::FactoryGet(name, min, max, bucketCount, Histogram::kNoFlags); *result = Histogram::FactoryGet(name, min, max, bucketCount, Histogram::kUmaTargetedHistogramFlag);
break; break;
case nsITelemetry::HISTOGRAM_LINEAR: case nsITelemetry::HISTOGRAM_LINEAR:
*result = LinearHistogram::FactoryGet(name, min, max, bucketCount, Histogram::kNoFlags); *result = LinearHistogram::FactoryGet(name, min, max, bucketCount, Histogram::kUmaTargetedHistogramFlag);
break; break;
case nsITelemetry::HISTOGRAM_BOOLEAN: case nsITelemetry::HISTOGRAM_BOOLEAN:
*result = BooleanHistogram::FactoryGet(name, Histogram::kNoFlags); *result = BooleanHistogram::FactoryGet(name, Histogram::kUmaTargetedHistogramFlag);
break; break;
default: default:
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
@ -172,6 +172,7 @@ ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
h->SnapshotSample(&ss); h->SnapshotSample(&ss);
JSObject *counts_array; JSObject *counts_array;
JSObject *rarray; JSObject *rarray;
jsval static_histogram = h->flags() && Histogram::kUmaTargetedHistogramFlag ? JSVAL_TRUE : JSVAL_FALSE;
const size_t count = h->bucket_count(); const size_t count = h->bucket_count();
if (!(JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), NULL, NULL, JSPROP_ENUMERATE) if (!(JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), NULL, NULL, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), NULL, NULL, JSPROP_ENUMERATE) && JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), NULL, NULL, JSPROP_ENUMERATE)
@ -182,6 +183,7 @@ ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
&& FillRanges(cx, rarray, h) && FillRanges(cx, rarray, h)
&& (counts_array = JS_NewArrayObject(cx, count, NULL)) && (counts_array = JS_NewArrayObject(cx, count, NULL))
&& JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array), NULL, NULL, JSPROP_ENUMERATE) && JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array), NULL, NULL, JSPROP_ENUMERATE)
&& JS_DefineProperty(cx, obj, "static", static_histogram, NULL, NULL, JSPROP_ENUMERATE)
)) { )) {
return JS_FALSE; return JS_FALSE;
} }
@ -273,6 +275,7 @@ TelemetryImpl::NewHistogram(const nsACString &name, PRUint32 min, PRUint32 max,
nsresult rv = HistogramGet(PromiseFlatCString(name).get(), min, max, bucketCount, histogramType, &h); nsresult rv = HistogramGet(PromiseFlatCString(name).get(), min, max, bucketCount, histogramType, &h);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
h->ClearFlags(Histogram::kUmaTargetedHistogramFlag);
return WrapAndReturnHistogram(h, cx, ret); return WrapAndReturnHistogram(h, cx, ret);
} }

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

@ -77,6 +77,9 @@ function getHistograms() {
for (let key in hls) { for (let key in hls) {
let hgram = hls[key]; let hgram = hls[key];
if (!hgram.static)
continue;
let r = hgram.ranges; let r = hgram.ranges;
let c = hgram.counts; let c = hgram.counts;
let retgram = { let retgram = {
@ -185,6 +188,7 @@ function TelemetryPing() {}
TelemetryPing.prototype = { TelemetryPing.prototype = {
_histograms: {}, _histograms: {},
_initialized: false,
_prevValues: {}, _prevValues: {},
/** /**

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

@ -61,6 +61,7 @@ interface nsITelemetry : nsISupports
* counts - array representing contents of the buckets in the histogram * counts - array representing contents of the buckets in the histogram
* ranges - an array with calculated bucket sizes * ranges - an array with calculated bucket sizes
* sum - sum of the bucket contents * sum - sum of the bucket contents
* static - true for histograms defined in TelemetryHistograms.h, false for ones defined with newHistogram
*/ */
[implicit_jscontext] [implicit_jscontext]
readonly attribute jsval histogramSnapshots; readonly attribute jsval histogramSnapshots;

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

@ -13,6 +13,7 @@ Cu.import("resource://gre/modules/Services.jsm");
const PATH = "/submit/telemetry/test-ping"; const PATH = "/submit/telemetry/test-ping";
const SERVER = "http://localhost:4444"; const SERVER = "http://localhost:4444";
const IGNORE_HISTOGRAM = "test::ignore_me";
const BinaryInputStream = Components.Constructor( const BinaryInputStream = Components.Constructor(
"@mozilla.org/binaryinputstream;1", "@mozilla.org/binaryinputstream;1",
@ -22,8 +23,8 @@ const BinaryInputStream = Components.Constructor(
var httpserver = new nsHttpServer(); var httpserver = new nsHttpServer();
function telemetry_ping () { function telemetry_ping () {
let tp = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver); const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
tp.observe(tp, "test-ping", SERVER); TelemetryPing.observe(null, "test-ping", SERVER);
} }
function nonexistentServerObserver(aSubject, aTopic, aData) { function nonexistentServerObserver(aSubject, aTopic, aData) {
@ -40,6 +41,8 @@ function nonexistentServerObserver(aSubject, aTopic, aData) {
function telemetryObserver(aSubject, aTopic, aData) { function telemetryObserver(aSubject, aTopic, aData) {
Services.obs.removeObserver(telemetryObserver, aTopic); Services.obs.removeObserver(telemetryObserver, aTopic);
httpserver.registerPathHandler(PATH, checkHistograms); httpserver.registerPathHandler(PATH, checkHistograms);
const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
Telemetry.newHistogram(IGNORE_HISTOGRAM, 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
telemetry_ping(); telemetry_ping();
} }
@ -85,7 +88,8 @@ function checkHistograms(request, response) {
const TELEMETRY_PING = "TELEMETRY_PING"; const TELEMETRY_PING = "TELEMETRY_PING";
const TELEMETRY_SUCCESS = "TELEMETRY_SUCCESS"; const TELEMETRY_SUCCESS = "TELEMETRY_SUCCESS";
do_check_true(TELEMETRY_PING in payload.histograms) do_check_true(TELEMETRY_PING in payload.histograms);
do_check_false(IGNORE_HISTOGRAM in payload.histograms);
// There should be one successful report from the previous telemetry ping. // There should be one successful report from the previous telemetry ping.
const expected_tc = { const expected_tc = {

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

@ -31,7 +31,9 @@ function test_histogram(histogram_type, name, min, max, bucket_count) {
do_check_eq(gh.min, min) do_check_eq(gh.min, min)
do_check_eq(gh.max, max) do_check_eq(gh.max, max)
do_check_false(gh.static);
// Check that booleans work with nonboolean histograms // Check that booleans work with nonboolean histograms
h.add(false); h.add(false);
h.add(true); h.add(true);
@ -85,6 +87,7 @@ function test_getHistogramById() {
do_check_eq(s.histogram_type, Telemetry.HISTOGRAM_EXPONENTIAL); do_check_eq(s.histogram_type, Telemetry.HISTOGRAM_EXPONENTIAL);
do_check_eq(s.min, 1); do_check_eq(s.min, 1);
do_check_eq(s.max, 10000); do_check_eq(s.max, 10000);
do_check_true(s.static);
} }
// Check that telemetry doesn't record in private mode // Check that telemetry doesn't record in private mode