зеркало из https://github.com/mozilla/gecko-dev.git
Bug 819418 - part 1 - be more selective in exporting aggregate statistics; r=vdjeric
This commit is contained in:
Родитель
4bebfa7b67
Коммит
8afc4b1941
|
@ -723,25 +723,28 @@ void Histogram::SampleSet::CheckSize(const Histogram& histogram) const {
|
|||
DCHECK_EQ(histogram.bucket_count(), counts_.size());
|
||||
}
|
||||
|
||||
|
||||
void Histogram::SampleSet::AccumulateWithLinearStats(Sample value,
|
||||
Count count,
|
||||
size_t index) {
|
||||
void Histogram::SampleSet::Accumulate(Sample value, Count count,
|
||||
size_t index) {
|
||||
DCHECK(count == 1 || count == -1);
|
||||
counts_[index] += count;
|
||||
int64_t amount = static_cast<int64_t>(count) * value;
|
||||
sum_ += amount;
|
||||
sum_squares_ += amount * value;
|
||||
redundant_count_ += count;
|
||||
sum_ += static_cast<int64_t>(count) * value;
|
||||
DCHECK_GE(counts_[index], 0);
|
||||
DCHECK_GE(sum_, 0);
|
||||
DCHECK_GE(redundant_count_, 0);
|
||||
}
|
||||
|
||||
void Histogram::SampleSet::AccumulateWithLinearStats(Sample value,
|
||||
Count count,
|
||||
size_t index) {
|
||||
Accumulate(value, count, index);
|
||||
sum_squares_ += static_cast<int64_t>(count) * value * value;
|
||||
}
|
||||
|
||||
void Histogram::SampleSet::AccumulateWithExponentialStats(Sample value,
|
||||
Count count,
|
||||
size_t index) {
|
||||
AccumulateWithLinearStats(value, count, index);
|
||||
Accumulate(value, count, index);
|
||||
DCHECK_GE(value, 0);
|
||||
double value_log = log(static_cast<double>(value) + 1);
|
||||
log_sum_ += count * value_log;
|
||||
|
|
|
@ -374,6 +374,8 @@ class Histogram {
|
|||
double log_sum_squares_; // sum of squares of logs of samples
|
||||
|
||||
private:
|
||||
void Accumulate(Sample value, Count count, size_t index);
|
||||
|
||||
// Allow tests to corrupt our innards for testing purposes.
|
||||
FRIEND_TEST(HistogramTest, CorruptSampleCounts);
|
||||
|
||||
|
|
|
@ -527,20 +527,26 @@ ReflectHistogramAndSamples(JSContext *cx, JSObject *obj, Histogram *h,
|
|||
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, "histogram_type", INT_TO_JSVAL(h->histogram_type()), NULL, NULL, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), NULL, NULL, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "log_sum", DOUBLE_TO_JSVAL(ss.log_sum()), NULL, NULL, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "log_sum_squares", DOUBLE_TO_JSVAL(ss.log_sum_squares()), NULL, NULL, JSPROP_ENUMERATE))) {
|
||||
&& JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), NULL, NULL, JSPROP_ENUMERATE))) {
|
||||
return REFLECT_FAILURE;
|
||||
}
|
||||
|
||||
// Export |sum_squares| as two separate 32-bit properties so that we
|
||||
// can accurately reconstruct it on the analysis side.
|
||||
uint64_t sum_squares = ss.sum_squares();
|
||||
uint32_t lo = sum_squares;
|
||||
uint32_t hi = sum_squares >> 32;
|
||||
if (!(JS_DefineProperty(cx, obj, "sum_squares_lo", INT_TO_JSVAL(lo), NULL, NULL, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "sum_squares_hi", INT_TO_JSVAL(hi), NULL, NULL, JSPROP_ENUMERATE))) {
|
||||
return REFLECT_FAILURE;
|
||||
if (h->histogram_type() == Histogram::HISTOGRAM) {
|
||||
if (!(JS_DefineProperty(cx, obj, "log_sum", DOUBLE_TO_JSVAL(ss.log_sum()), NULL, NULL, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "log_sum_squares", DOUBLE_TO_JSVAL(ss.log_sum_squares()), NULL, NULL, JSPROP_ENUMERATE))) {
|
||||
return REFLECT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
// Export |sum_squares| as two separate 32-bit properties so that we
|
||||
// can accurately reconstruct it on the analysis side.
|
||||
uint64_t sum_squares = ss.sum_squares();
|
||||
// Cast to avoid implicit truncation warnings.
|
||||
uint32_t lo = static_cast<uint32_t>(sum_squares);
|
||||
uint32_t hi = static_cast<uint32_t>(sum_squares >> 32);
|
||||
if (!(JS_DefineProperty(cx, obj, "sum_squares_lo", INT_TO_JSVAL(lo), NULL, NULL, JSPROP_ENUMERATE)
|
||||
&& JS_DefineProperty(cx, obj, "sum_squares_hi", INT_TO_JSVAL(hi), NULL, NULL, JSPROP_ENUMERATE))) {
|
||||
return REFLECT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
const size_t count = h->bucket_count();
|
||||
|
|
|
@ -255,12 +255,17 @@ TelemetryPing.prototype = {
|
|||
bucket_count: r.length,
|
||||
histogram_type: hgram.histogram_type,
|
||||
values: {},
|
||||
sum: hgram.sum,
|
||||
sum_squares_lo: hgram.sum_squares_lo,
|
||||
sum_squares_hi: hgram.sum_squares_hi,
|
||||
log_sum: hgram.log_sum,
|
||||
log_sum_squares: hgram.log_sum_squares
|
||||
sum: hgram.sum
|
||||
};
|
||||
|
||||
if (hgram.histogram_type == Telemetry.HISTOGRAM_EXPONENTIAL) {
|
||||
retgram.log_sum = hgram.log_sum;
|
||||
retgram.log_sum_squares = hgram.log_sum_squares;
|
||||
} else {
|
||||
retgram.sum_squares_lo = hgram.sum_squares_lo;
|
||||
retgram.sum_squares_hi = hgram.sum_squares_hi;
|
||||
}
|
||||
|
||||
let first = true;
|
||||
let last = 0;
|
||||
|
||||
|
|
|
@ -211,9 +211,7 @@ function checkPayload(request, reason, successfulPings) {
|
|||
values: {0:1, 1:0},
|
||||
sum: 0,
|
||||
sum_squares_lo: 0,
|
||||
sum_squares_hi: 0,
|
||||
log_sum: 0,
|
||||
log_sum_squares: 0
|
||||
sum_squares_hi: 0
|
||||
};
|
||||
let flag = payload.histograms[TELEMETRY_TEST_FLAG];
|
||||
do_check_eq(uneval(flag), uneval(expected_flag));
|
||||
|
@ -226,9 +224,7 @@ function checkPayload(request, reason, successfulPings) {
|
|||
values: {0:1, 1:successfulPings, 2:0},
|
||||
sum: successfulPings,
|
||||
sum_squares_lo: successfulPings,
|
||||
sum_squares_hi: 0,
|
||||
log_sum: 0,
|
||||
log_sum_squares: 0
|
||||
sum_squares_hi: 0
|
||||
};
|
||||
let tc = payload.histograms[TELEMETRY_SUCCESS];
|
||||
do_check_eq(uneval(tc), uneval(expected_tc));
|
||||
|
|
|
@ -27,13 +27,20 @@ function test_histogram(histogram_type, name, min, max, bucket_count) {
|
|||
h.add(v);
|
||||
}
|
||||
var s = h.snapshot();
|
||||
// verify sum
|
||||
// verify properties
|
||||
do_check_eq(sum, s.sum);
|
||||
// Doing the math to verify sum_squares was reflected correctly is
|
||||
// tedious in JavaScript. Just make sure we have something.
|
||||
do_check_neq(s.sum_squares_lo + s.sum_squares_hi, 0);
|
||||
do_check_eq(log_sum, s.log_sum);
|
||||
do_check_eq(log_sum_squares, s.log_sum_squares);
|
||||
if (histogram_type == Telemetry.HISTOGRAM_EXPONENTIAL) {
|
||||
do_check_eq(log_sum, s.log_sum);
|
||||
do_check_eq(log_sum_squares, s.log_sum_squares);
|
||||
do_check_false("sum_squares_lo" in s);
|
||||
do_check_false("sum_squares_hi" in s);
|
||||
} else {
|
||||
// Doing the math to verify sum_squares was reflected correctly is
|
||||
// tedious in JavaScript. Just make sure we have something.
|
||||
do_check_neq(s.sum_squares_lo + s.sum_squares_hi, 0);
|
||||
do_check_false("log_sum" in s);
|
||||
do_check_false("log_sum_squares" in s);
|
||||
}
|
||||
|
||||
// there should be exactly one element per bucket
|
||||
for each(var i in s.counts) {
|
||||
|
@ -60,6 +67,13 @@ function test_histogram(histogram_type, name, min, max, bucket_count) {
|
|||
do_check_eq(i, 0);
|
||||
}
|
||||
do_check_eq(s.sum, 0);
|
||||
if (histogram_type == Telemetry.HISTOGRAM_EXPONENTIAL) {
|
||||
do_check_eq(s.log_sum, 0);
|
||||
do_check_eq(s.log_sum_squares, 0);
|
||||
} else {
|
||||
do_check_eq(s.sum_squares_lo, 0);
|
||||
do_check_eq(s.sum_squares_hi, 0);
|
||||
}
|
||||
|
||||
h.add(0);
|
||||
h.add(1);
|
||||
|
@ -160,10 +174,13 @@ function compareHistograms(h1, h2) {
|
|||
do_check_eq(s1.min, s2.min);
|
||||
do_check_eq(s1.max, s2.max);
|
||||
do_check_eq(s1.sum, s2.sum);
|
||||
do_check_eq(s1.sum_squares_lo, s2.sum_squares_lo);
|
||||
do_check_eq(s1.sum_squares_hi, s2.sum_squares_hi);
|
||||
do_check_eq(s1.log_sum, s2.log_sum);
|
||||
do_check_eq(s1.log_sum_squares, s2.log_sum_squares);
|
||||
if (s1.histogram_type == Telemetry.HISTOGRAM_EXPONENTIAL) {
|
||||
do_check_eq(s1.log_sum, s2.log_sum);
|
||||
do_check_eq(s1.log_sum_squares, s2.log_sum_squares);
|
||||
} else {
|
||||
do_check_eq(s1.sum_squares_lo, s2.sum_squares_lo);
|
||||
do_check_eq(s1.sum_squares_hi, s2.sum_squares_hi);
|
||||
}
|
||||
|
||||
do_check_eq(s1.counts.length, s2.counts.length);
|
||||
for (let i = 0; i < s1.counts.length; i++)
|
||||
|
|
Загрузка…
Ссылка в новой задаче