Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: components/data_use_measurement/core/data_use_measurement.cc

Issue 2851923002: Fix overflow in user traffic content type histogram (Closed)
Patch Set: change array to int16 and added test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_use_measurement/core/data_use_measurement.cc
diff --git a/components/data_use_measurement/core/data_use_measurement.cc b/components/data_use_measurement/core/data_use_measurement.cc
index fcebeb8d070d079520f1ebde9a28275fcd20bc27..345eff248ebd54fbe695ae3e4fff42a3d0d5bbaa 100644
--- a/components/data_use_measurement/core/data_use_measurement.cc
+++ b/components/data_use_measurement/core/data_use_measurement.cc
@@ -100,6 +100,8 @@ DataUseMeasurement::DataUseMeasurement(
{
DCHECK(ascriber_);
DCHECK(url_request_classifier_);
+ memset(user_traffic_content_type_bytes_, 0,
+ sizeof(user_traffic_content_type_bytes_));
#if defined(OS_ANDROID)
int64_t bytes = 0;
@@ -445,12 +447,17 @@ void DataUseMeasurement::RecordContentTypeHistogram(
// Use the more primitive STATIC_HISTOGRAM_POINTER_BLOCK macro because the
// simple UMA_HISTOGRAM_ENUMERATION macros don't expose 'AddCount'.
if (is_user_traffic) {
- STATIC_HISTOGRAM_POINTER_BLOCK(
- "DataUse.ContentType.UserTraffic", AddCount(content_type, bytes),
- base::LinearHistogram::FactoryGet(
- "DataUse.ContentType.UserTraffic", 1, DataUseUserData::TYPE_MAX,
- DataUseUserData::TYPE_MAX + 1,
- base::HistogramBase::kUmaTargetedHistogramFlag));
+ bytes += user_traffic_content_type_bytes_[content_type];
+ if (bytes >= 1024) {
+ STATIC_HISTOGRAM_POINTER_BLOCK(
+ "DataUse.ContentType.UserTrafficKB",
+ AddCount(content_type, bytes / 1024),
+ base::LinearHistogram::FactoryGet(
+ "DataUse.ContentType.UserTrafficKB", 1, DataUseUserData::TYPE_MAX,
Ilya Sherman 2017/05/02 21:28:52 This histogram would still overflow if there are ~
Ilya Sherman 2017/05/02 21:29:58 Actually, slightly less than 4.5 TB, as I was calc
+ DataUseUserData::TYPE_MAX + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag));
+ }
+ user_traffic_content_type_bytes_[content_type] = bytes % 1024;
} else {
STATIC_HISTOGRAM_POINTER_BLOCK(
"DataUse.ContentType.Services", AddCount(content_type, bytes),

Powered by Google App Engine
This is Rietveld 408576698