Skip to content

Commit

Permalink
Optimizations to histogram protobuf encoding.
Browse files Browse the repository at this point in the history
Omits several fields from being sent if their value is one of the
common field values.

BUG=590765

Review URL: https://codereview.chromium.org/1744283002

Cr-Commit-Position: refs/heads/master@{#378364}
  • Loading branch information
asvitkine-chromium authored and Commit bot committed Mar 1, 2016
1 parent 59b5b4b commit 0955394
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions components/metrics/histogram_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void EncodeHistogramDelta(const std::string& histogram_name,

HistogramEventProto* histogram_proto = uma_proto->add_histogram_event();
histogram_proto->set_name_hash(base::HashMetricName(histogram_name));
histogram_proto->set_sum(snapshot.sum());
if (snapshot.sum() != 0)
histogram_proto->set_sum(snapshot.sum());

for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done();
it->Next()) {
Expand All @@ -36,7 +37,9 @@ void EncodeHistogramDelta(const std::string& histogram_name,
HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
bucket->set_min(min);
bucket->set_max(max);
bucket->set_count(count);
// Note: The default for count is 1 in the proto, so omit it in that case.
if (count != 1)
bucket->set_count(count);
}

// Omit fields to save space (see rules in histogram_event.proto comments).
Expand Down
8 changes: 5 additions & 3 deletions components/metrics/proto/histogram_event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ message HistogramEventProto {
// The sum of all the sample values.
// Together with the total count of the sample values, this allows us to
// compute the average value. The count of all sample values is just the sum
// of the counts of all the buckets.
// of the counts of all the buckets. As of M51, when the value of this field
// would be 0, the field will be omitted instead.
optional int64 sum = 2;

// The per-bucket data.
Expand All @@ -40,8 +41,9 @@ message HistogramEventProto {
// clients to reduce the UMA upload size.
optional int32 bucket_index = 3 [deprecated = true];

// The number of entries in this bucket.
optional int64 count = 4;
// The number of entries in this bucket. As of M51, when the value of this
// field would be 1, the field will be omitted instead.
optional int64 count = 4 [default = 1];
}
repeated Bucket bucket = 3;
}

0 comments on commit 0955394

Please sign in to comment.