summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorTarun Bansal <tbansal@google.com>2016-02-10 11:49:29 -0800
committerTarun Bansal <tbansal@google.com>2016-02-10 19:51:30 +0000
commit22cc50807f6d5c0a11b788da0bb5837391a7586d (patch)
tree23c1669022f44aaada6e6195c4d2882ec77dcce9 /components
parent974ef8f713cc4cff06cbe2b690b2b7f50d05bebf (diff)
downloadchromium_src-22cc50807f6d5c0a11b788da0bb5837391a7586d.zip
chromium_src-22cc50807f6d5c0a11b788da0bb5837391a7586d.tar.gz
chromium_src-22cc50807f6d5c0a11b788da0bb5837391a7586d.tar.bz2
Add histogram to count the tabs in TrafficStatsAmortizer
Add histogram to count the number of concurrent tabs seen across all DataUse objects buffered for a single amortization run by the TrafficStatsAmortizer. BUG=582859 Review URL: https://codereview.chromium.org/1656763002 Cr-Commit-Position: refs/heads/master@{#374195} (cherry picked from commit a5e36dbaa32cd45ff9693335b983a5a79c4e019b) Review URL: https://codereview.chromium.org/1690623003 . Cr-Commit-Position: refs/branch-heads/2623@{#353} Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907}
Diffstat (limited to 'components')
-rw-r--r--components/data_usage/android/traffic_stats_amortizer.cc10
-rw-r--r--components/data_usage/android/traffic_stats_amortizer_unittest.cc89
2 files changed, 94 insertions, 5 deletions
diff --git a/components/data_usage/android/traffic_stats_amortizer.cc b/components/data_usage/android/traffic_stats_amortizer.cc
index 16d5090f..3acec99 100644
--- a/components/data_usage/android/traffic_stats_amortizer.cc
+++ b/components/data_usage/android/traffic_stats_amortizer.cc
@@ -6,6 +6,7 @@
#include <algorithm> // For std::min.
#include <cmath> // For std::modf.
+#include <set>
#include <utility>
#include "base/location.h"
@@ -163,6 +164,14 @@ int64_t GetTotalRxBytes(const DataUseBuffer& data_use_sequence) {
return sum;
}
+void RecordConcurrentTabsHistogram(const DataUseBuffer& data_use_buffer) {
+ std::set<int32_t> unique_tabs;
+ for (const auto& data_use_buffer_pair : data_use_buffer)
+ unique_tabs.insert(data_use_buffer_pair.first->tab_id);
+ UMA_HISTOGRAM_COUNTS_100("TrafficStatsAmortizer.ConcurrentTabs",
+ unique_tabs.size());
+}
+
} // namespace
TrafficStatsAmortizer::TrafficStatsAmortizer()
@@ -332,6 +341,7 @@ void TrafficStatsAmortizer::AmortizeNow() {
UMA_HISTOGRAM_COUNTS(
"TrafficStatsAmortizer.PostAmortizationRunDataUseBytes.Rx",
GetByteCountAsHistogramSample(GetTotalRxBytes(buffered_data_use_)));
+ RecordConcurrentTabsHistogram(buffered_data_use_);
}
UMA_HISTOGRAM_TIMES(
diff --git a/components/data_usage/android/traffic_stats_amortizer_unittest.cc b/components/data_usage/android/traffic_stats_amortizer_unittest.cc
index 90d87d3..e949b40 100644
--- a/components/data_usage/android/traffic_stats_amortizer_unittest.cc
+++ b/components/data_usage/android/traffic_stats_amortizer_unittest.cc
@@ -57,6 +57,7 @@ const char kAmortizationDelayHistogram[] =
"TrafficStatsAmortizer.AmortizationDelay";
const char kBufferSizeOnFlushHistogram[] =
"TrafficStatsAmortizer.BufferSizeOnFlush";
+const char kConcurrentTabs[] = "TrafficStatsAmortizer.ConcurrentTabs";
// The maximum sample value that can be recorded in a histogram.
const base::HistogramBase::Sample kMaxRecordableSample =
@@ -68,16 +69,34 @@ base::HistogramBase::Sample GetDelaySample(const base::TimeDelta& delay) {
return static_cast<base::HistogramBase::Sample>(delay.InMilliseconds());
}
+// Synthesizes a fake scoped_ptr<DataUse> with the given |url|, |tab_id|,
+// |tx_bytes| and |rx_bytes|, using arbitrary values for all other fields.
+scoped_ptr<DataUse> CreateDataUseWithURLAndTab(const GURL& url,
+ int32_t tab_id,
+ int64_t tx_bytes,
+ int64_t rx_bytes) {
+ return scoped_ptr<DataUse>(
+ new DataUse(url, base::TimeTicks() /* request_start */,
+ GURL("http://examplefirstparty.com"), tab_id,
+ net::NetworkChangeNotifier::CONNECTION_2G, "example_mcc_mnc",
+ tx_bytes, rx_bytes));
+}
+
// Synthesizes a fake scoped_ptr<DataUse> with the given |url|, |tx_bytes| and
// |rx_bytes|, using arbitrary values for all other fields.
scoped_ptr<DataUse> CreateDataUseWithURL(const GURL& url,
int64_t tx_bytes,
int64_t rx_bytes) {
- return scoped_ptr<DataUse>(
- new DataUse(url, base::TimeTicks() /* request_start */,
- GURL("http://examplefirstparty.com"), 10 /* tab_id */,
- net::NetworkChangeNotifier::CONNECTION_2G, "example_mcc_mnc",
- tx_bytes, rx_bytes));
+ return CreateDataUseWithURLAndTab(url, 10, tx_bytes, rx_bytes);
+}
+
+// Synthesizes a fake scoped_ptr<DataUse> with the given |tab_id|, |tx_bytes|
+// and |rx_bytes|, using arbitrary values for all other fields.
+scoped_ptr<DataUse> CreateDataUseWithTab(int32_t tab_id,
+ int64_t tx_bytes,
+ int64_t rx_bytes) {
+ return CreateDataUseWithURLAndTab(GURL("http://example.com"), tab_id,
+ tx_bytes, rx_bytes);
}
// Synthesizes a fake scoped_ptr<DataUse> with the given |tx_bytes| and
@@ -296,6 +315,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithTrafficStatsAlwaysUnavailable) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
}
@@ -325,6 +345,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeDataUse) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 2, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
// Simulate the second amortization run.
@@ -362,6 +383,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeDataUse) {
GetDelaySample(kTrafficStatsQueryDelay + kTrafficStatsQueryDelay / 2),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 2, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
}
@@ -384,6 +406,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithExtraBytes) {
histogram_tester.ExpectUniqueSample(
kAmortizationDelayHistogram, GetDelaySample(kTrafficStatsQueryDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeWithNegativeOverhead) {
@@ -404,6 +427,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithNegativeOverhead) {
histogram_tester.ExpectUniqueSample(
kAmortizationDelayHistogram, GetDelaySample(kTrafficStatsQueryDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeWithMaxIntByteCounts) {
@@ -431,6 +455,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithMaxIntByteCounts) {
histogram_tester.ExpectUniqueSample(
kAmortizationDelayHistogram, GetDelaySample(kTrafficStatsQueryDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeWithMaxIntScaleFactor) {
@@ -456,6 +481,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithMaxIntScaleFactor) {
histogram_tester.ExpectUniqueSample(
kAmortizationDelayHistogram, GetDelaySample(kTrafficStatsQueryDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroScaleFactor) {
@@ -480,6 +506,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroScaleFactor) {
histogram_tester.ExpectUniqueSample(
kAmortizationDelayHistogram, GetDelaySample(kTrafficStatsQueryDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroPreAmortizationBytes) {
@@ -505,6 +532,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroPreAmortizationBytes) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
{
@@ -526,6 +554,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroPreAmortizationBytes) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
}
@@ -552,6 +581,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroTxPreAmortizationBytes) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
{
@@ -572,6 +602,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroTxPreAmortizationBytes) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
}
@@ -598,6 +629,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroRxPreAmortizationBytes) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
{
@@ -618,6 +650,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeWithZeroRxPreAmortizationBytes) {
GetDelaySample(kTrafficStatsQueryDelay),
1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
}
@@ -656,6 +689,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeAtMaxDelay) {
histogram_tester.ExpectUniqueSample(kAmortizationDelayHistogram,
GetDelaySample(kMaxAmortizationDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 1, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeAtMaxBufferSize) {
@@ -687,6 +721,7 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeAtMaxBufferSize) {
histogram_tester.ExpectUniqueSample(kAmortizationDelayHistogram, 0, 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram,
kExpectedBufSize, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
}
TEST_F(TrafficStatsAmortizerTest, AmortizeCombinedDataUse) {
@@ -752,6 +787,50 @@ TEST_F(TrafficStatsAmortizerTest, AmortizeCombinedDataUse) {
histogram_tester.ExpectUniqueSample(
kAmortizationDelayHistogram, GetDelaySample(kTrafficStatsQueryDelay), 1);
histogram_tester.ExpectUniqueSample(kBufferSizeOnFlushHistogram, 4, 1);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 1, 1);
+}
+
+TEST_F(TrafficStatsAmortizerTest, ConcurrentTabsHistogram) {
+ SkipFirstAmortizationRun();
+
+ {
+ // Test data usage reported multiple times for two tabs.
+ base::HistogramTester histogram_tester;
+ amortizer()->SetNextTrafficStats(true, 0, 0);
+ amortizer()->AmortizeDataUse(
+ CreateDataUseWithTab(1, 50, 500),
+ ExpectDataUseCallback(CreateDataUseWithTab(1, 100, 1000)));
+ amortizer()->AmortizeDataUse(
+ CreateDataUseWithTab(2, 100, 1000),
+ ExpectDataUseCallback(CreateDataUseWithTab(2, 200, 2000)));
+ amortizer()->AmortizeDataUse(
+ CreateDataUseWithTab(1, 50, 500),
+ ExpectDataUseCallback(CreateDataUseWithTab(1, 100, 1000)));
+ amortizer()->AmortizeDataUse(
+ CreateDataUseWithTab(2, 100, 1000),
+ ExpectDataUseCallback(CreateDataUseWithTab(2, 200, 2000)));
+ amortizer()->SetNextTrafficStats(true, 600, 6000);
+ AdvanceTime(kTrafficStatsQueryDelay);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, 2, 1);
+ histogram_tester.ExpectUniqueSample(kPreAmortizationTxHistogram, 300, 1);
+ histogram_tester.ExpectUniqueSample(kPreAmortizationRxHistogram, 3000, 1);
+ histogram_tester.ExpectUniqueSample(kPostAmortizationTxHistogram, 600, 1);
+ histogram_tester.ExpectUniqueSample(kPostAmortizationRxHistogram, 6000, 1);
+ }
+
+ // Test data usage for 1-5 tabs.
+ for (int32_t total_tabs = 1; total_tabs <= 5; ++total_tabs) {
+ base::HistogramTester histogram_tester;
+
+ for (int32_t i = 1; i <= total_tabs; ++i) {
+ amortizer()->AmortizeDataUse(
+ CreateDataUseWithTab(i, 100, 1000),
+ ExpectDataUseCallback(CreateDataUseWithTab(i, 200, 2000)));
+ }
+ amortizer()->AddTrafficStats(total_tabs * 200, total_tabs * 2000);
+ AdvanceTime(kTrafficStatsQueryDelay);
+ histogram_tester.ExpectUniqueSample(kConcurrentTabs, total_tabs, 1);
+ }
}
} // namespace