Bug 701863 - clone STARTUP_* histograms properly; r=taras

This commit is contained in:
Nathan Froyd 2011-11-16 15:33:18 -05:00
parent 9793e7eeef
commit 1be53b4ad1
4 changed files with 52 additions and 23 deletions

View File

@ -94,11 +94,13 @@ struct TelemetryHistogram {
PRUint32 max;
PRUint32 bucketCount;
PRUint32 histogramType;
const char *comment;
};
const TelemetryHistogram gHistograms[] = {
#define HISTOGRAM(id, min, max, bucket_count, histogram_type, b) \
{ NULL, NS_STRINGIFY(id), min, max, bucket_count, nsITelemetry::HISTOGRAM_ ## histogram_type },
#define HISTOGRAM(id, min, max, bucket_count, histogram_type, comment) \
{ NULL, NS_STRINGIFY(id), min, max, bucket_count, \
nsITelemetry::HISTOGRAM_ ## histogram_type, comment },
#include "TelemetryHistograms.h"
@ -204,7 +206,6 @@ ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
&& FillRanges(cx, rarray, h)
&& (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, "static", static_histogram, NULL, NULL, JSPROP_ENUMERATE)
)) {
return JS_FALSE;
}
@ -385,6 +386,28 @@ TelemetryImpl::GetHistogramSnapshots(JSContext *cx, jsval *ret)
return NS_OK;
}
NS_IMETHODIMP
TelemetryImpl::GetRegisteredHistograms(JSContext *cx, jsval *ret)
{
size_t count = ArrayLength(gHistograms);
JSObject *info = JS_NewObject(cx, NULL, NULL, NULL);
if (!info)
return NS_ERROR_FAILURE;
for (size_t i = 0; i < count; ++i) {
JSString *comment = JS_InternString(cx, gHistograms[i].comment);
if (!(comment
&& JS_DefineProperty(cx, info, gHistograms[i].id,
STRING_TO_JSVAL(comment), NULL, NULL,
JSPROP_ENUMERATE))) {
return NS_ERROR_FAILURE;
}
}
*ret = OBJECT_TO_JSVAL(info);
return NS_OK;
}
NS_IMETHODIMP
TelemetryImpl::GetHistogramById(const nsACString &name, JSContext *cx, jsval *ret)

View File

@ -125,7 +125,6 @@ TelemetryPing.prototype = {
_histograms: {},
_initialized: false,
_prevValues: {},
_sqliteOverhead: {},
/**
* Returns a set of histograms that can be converted into JSON
@ -136,19 +135,11 @@ TelemetryPing.prototype = {
*/
getHistograms: function getHistograms() {
let hls = Telemetry.histogramSnapshots;
let info = Telemetry.registeredHistograms;
let ret = {};
// bug 701583: report sqlite overhead on startup
for (let key in this._sqliteOverhead) {
hls[key] = this._sqliteOverhead[key];
}
for (let key in hls) {
let hgram = hls[key];
if (!hgram.static)
continue;
let r = hgram.ranges;
function processHistogram(name, hgram) {
let r = hgram.ranges;;
let c = hgram.counts;
let retgram = {
range: [r[1], r[r.length - 1]],
@ -178,8 +169,18 @@ TelemetryPing.prototype = {
// add an upper bound
if (last && last < c.length)
retgram.values[r[last]] = 0;
ret[key] = retgram;
ret[name] = retgram;
};
for (let name in hls) {
if (info[name]) {
processHistogram(name, hls[name]);
let startup_name = "STARTUP_" + name;
if (hls[startup_name])
processHistogram(startup_name, hls[startup_name]);
}
}
return ret;
},
@ -305,11 +306,11 @@ TelemetryPing.prototype = {
* Make a copy of sqlite histograms on startup
*/
gatherStartupSqlite: function gatherStartupSqlite() {
let hls = Telemetry.histogramSnapshots;
let info = Telemetry.registeredHistograms;
let sqlite_re = /SQLITE/;
for (let key in hls) {
if (sqlite_re.test(key))
this._sqliteOverhead["STARTUP_" + key] = hls[key];
for (let name in info) {
if (sqlite_re.test(name))
Telemetry.histogramFrom("STARTUP_" + name, name);
}
},

View File

@ -66,6 +66,14 @@ interface nsITelemetry : nsISupports
[implicit_jscontext]
readonly attribute jsval histogramSnapshots;
/**
* An object whose properties are the names of histograms defined in
* TelemetryHistograms.h and whose corresponding values are the textual
* comments associated with said histograms.
*/
[implicit_jscontext]
readonly attribute jsval registeredHistograms;
/**
* Create and return a histogram where bucket sizes increase exponentially. Parameters:
*

View File

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