OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/external_metrics.h" | 5 #include "chrome/browser/chromeos/external_metrics.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 using content::UserMetricsAction; | 30 using content::UserMetricsAction; |
31 | 31 |
32 namespace chromeos { | 32 namespace chromeos { |
33 | 33 |
34 // The interval between external metrics collections in seconds | 34 // The interval between external metrics collections in seconds |
35 static const int kExternalMetricsCollectionIntervalSeconds = 30; | 35 static const int kExternalMetricsCollectionIntervalSeconds = 30; |
36 | 36 |
37 class SystemHistogram : public base::Histogram { | |
38 public: | |
39 static bool CheckValues(const std::string& name, | |
40 int minimum, | |
41 int maximum, | |
42 size_t bucket_count) { | |
hshi1
2012/08/03 02:24:24
nit: please vertically left-align the arguments
zel
2012/08/03 02:29:45
Done.
| |
43 return base::Histogram::InspectConstructionArguments( | |
44 name, &minimum, &maximum, &bucket_count); | |
45 } | |
46 }; | |
47 | |
37 ExternalMetrics::ExternalMetrics() | 48 ExternalMetrics::ExternalMetrics() |
38 : test_recorder_(NULL) { | 49 : test_recorder_(NULL) { |
39 } | 50 } |
40 | 51 |
41 ExternalMetrics::~ExternalMetrics() {} | 52 ExternalMetrics::~ExternalMetrics() {} |
42 | 53 |
43 void ExternalMetrics::Start() { | 54 void ExternalMetrics::Start() { |
44 // Register user actions external to the browser. | 55 // Register user actions external to the browser. |
45 // chrome/tools/extract_actions.py won't understand these lines, so all of | 56 // chrome/tools/extract_actions.py won't understand these lines, so all of |
46 // these are explicitly added in that script. | 57 // these are explicitly added in that script. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 | 93 |
83 void ExternalMetrics::RecordHistogram(const char* histogram_data) { | 94 void ExternalMetrics::RecordHistogram(const char* histogram_data) { |
84 int sample, min, max, nbuckets; | 95 int sample, min, max, nbuckets; |
85 char name[128]; // length must be consistent with sscanf format below. | 96 char name[128]; // length must be consistent with sscanf format below. |
86 int n = sscanf(histogram_data, "%127s %d %d %d %d", | 97 int n = sscanf(histogram_data, "%127s %d %d %d %d", |
87 name, &sample, &min, &max, &nbuckets); | 98 name, &sample, &min, &max, &nbuckets); |
88 if (n != 5) { | 99 if (n != 5) { |
89 LOG(ERROR) << "bad histogram request: " << histogram_data; | 100 LOG(ERROR) << "bad histogram request: " << histogram_data; |
90 return; | 101 return; |
91 } | 102 } |
103 | |
104 if (!SystemHistogram::CheckValues(name, min, max, nbuckets)) { | |
105 LOG(ERROR) << "Invalid histogram " << name | |
106 << ", min=" << min | |
107 << ", max=" << max | |
108 << ", nbuckets=" << nbuckets; | |
109 return; | |
110 } | |
92 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram | 111 // Do not use the UMA_HISTOGRAM_... macros here. They cache the Histogram |
93 // instance and thus only work if |name| is constant. | 112 // instance and thus only work if |name| is constant. |
94 base::Histogram* counter = base::Histogram::FactoryGet( | 113 base::Histogram* counter = base::Histogram::FactoryGet( |
95 name, min, max, nbuckets, base::Histogram::kUmaTargetedHistogramFlag); | 114 name, min, max, nbuckets, base::Histogram::kUmaTargetedHistogramFlag); |
96 counter->Add(sample); | 115 counter->Add(sample); |
97 } | 116 } |
98 | 117 |
99 void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) { | 118 void ExternalMetrics::RecordLinearHistogram(const char* histogram_data) { |
100 int sample, max; | 119 int sample, max; |
101 char name[128]; // length must be consistent with sscanf format below. | 120 char name[128]; // length must be consistent with sscanf format below. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 void ExternalMetrics::ScheduleCollector() { | 251 void ExternalMetrics::ScheduleCollector() { |
233 bool result; | 252 bool result; |
234 result = BrowserThread::PostDelayedTask( | 253 result = BrowserThread::PostDelayedTask( |
235 BrowserThread::FILE, FROM_HERE, | 254 BrowserThread::FILE, FROM_HERE, |
236 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this), | 255 base::Bind(&chromeos::ExternalMetrics::CollectEventsAndReschedule, this), |
237 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds)); | 256 base::TimeDelta::FromSeconds(kExternalMetricsCollectionIntervalSeconds)); |
238 DCHECK(result); | 257 DCHECK(result); |
239 } | 258 } |
240 | 259 |
241 } // namespace chromeos | 260 } // namespace chromeos |
OLD | NEW |