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

Side by Side Diff: chrome/browser/chromeos/external_metrics.cc

Issue 10825169: Added check for invalid histogram data, added additional diagnostics to find the source of troubles… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698