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

Side by Side Diff: chrome/browser/performance_monitor/metric.cc

Issue 10907121: Add guards to metric values; erase bad events/metrics from db (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_use_units
Patch Set: Created 8 years, 3 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
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/performance_monitor/metric.h" 5 #include "chrome/browser/performance_monitor/metric.h"
6 6
7 #include "base/basictypes.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
9 10
10 namespace performance_monitor { 11 namespace performance_monitor {
11 12
13 namespace {
14
15 // These constants are designed to keep metrics reasonable. However, due to the
16 // variety of system configurations which can run chrome, these values may not
17 // catch *all* erroneous values. For instance, on a one-CPU machine, any CPU
18 // usage > 100 is erroneous, but on a 16-CPU machine, it's perfectly normal.
19 // These are "best-guesses" in order to weed out obviously-false values.
20 const double kMinUndefined = 0.0;
21 const double kMaxUndefined = 0.0; // No undefined metric is valid.
22 const double kMinCpuUsage = 0.0;
23 const double kMaxCpuUsage = 100000.0; // 100% on a 1000-CPU machine.
24 const double kMinPrivateMemoryUsage = 0.0;
25 const double kMaxPrivateMemoryUsage =
26 1024.0 * 1024.0 * 1024.0 * 1024.0; // 1 TB
27 const double kMinSharedMemoryUsage = 0.0;
28 const double kMaxSharedMemoryUsage = 1024.0 * 1024.0 * 1024.0 * 1024.0; // 1 TB
29 const double kMinStartupTime = 0.0;
30 const double kMaxStartupTime = 1000000 * 60 * 15; // 15 minutes
31 const double kMinTestStartupTime = 0.0;
32 const double kMaxTestStartupTime = 1000000 * 60 * 15; // 15 minutes
33 const double kMinSessionRestoreTime = 0.0;
34 const double kMaxSessionRestoreTime = 1000000 * 60 * 15; // 15 minutes
35 const double kMinPageLoadTime = 0.0;
36 const double kMaxPageLoadTime = 1000000 * 60 * 15; // 15 minutes
37 const double kMinNetworkBytesRead = 0.0;
38 // There really isn't a feasible "max" for network bytes read (even numbers in
39 // high TB are potentially possible).
40 const double kMaxNetworkBytesRead = static_cast<double>(kint64max);
41
42 struct MetricBound {
43 double min;
44 double max;
45 };
46
47 const MetricBound kMetricBounds[] = {
48 { kMinUndefined, kMaxUndefined },
49 { kMinCpuUsage, kMaxCpuUsage },
50 { kMinPrivateMemoryUsage, kMaxPrivateMemoryUsage },
51 { kMinSharedMemoryUsage, kMaxSharedMemoryUsage },
52 { kMinStartupTime, kMaxStartupTime },
53 { kMinTestStartupTime, kMaxTestStartupTime },
54 { kMinSessionRestoreTime, kMaxSessionRestoreTime },
55 { kMinPageLoadTime, kMaxPageLoadTime },
56 { kMinNetworkBytesRead, kMaxNetworkBytesRead },
57 };
58
59 COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kMetricBounds) == METRIC_NUMBER_OF_METRICS,
60 metric_bounds_size_doesnt_match_metric_count);
61
62 } // namespace
63
12 Metric::Metric() { 64 Metric::Metric() {
13 value = 0.0; 65 value = 0.0;
14 } 66 }
15 67
16 Metric::Metric(const base::Time& metric_time, const double metric_value) 68 Metric::Metric(MetricType metric_type,
17 : time(metric_time), value(metric_value) { 69 const base::Time& metric_time,
70 const double metric_value)
71 : type(metric_type), time(metric_time), value(metric_value) {
18 } 72 }
19 73
20 Metric::Metric(const std::string& metric_time, 74 Metric::Metric(MetricType metric_type,
21 const std::string& metric_value) { 75 const std::string& metric_time,
76 const std::string& metric_value) : type(metric_type) {
22 int64 conversion = 0; 77 int64 conversion = 0;
23 base::StringToInt64(metric_time, &conversion); 78 base::StringToInt64(metric_time, &conversion);
24 time = base::Time::FromInternalValue(conversion); 79 time = base::Time::FromInternalValue(conversion);
25 CHECK(base::StringToDouble(metric_value, &value)); 80 CHECK(base::StringToDouble(metric_value, &value));
26 } 81 }
27 82
28 Metric::~Metric() { 83 Metric::~Metric() {
29 } 84 }
30 85
86 bool Metric::Validate() const {
eaugusti 2012/09/07 23:10:55 Should this validate the type too?
Devlin 2012/09/10 17:49:14 Done (it'll already return false on Undefined metr
87 return value < kMetricBounds[type].max && value > kMetricBounds[type].min;
88 }
89
90 std::string Metric::ValueAsString() const {
91 return base::DoubleToString(value);
92 }
93
31 } // namespace performance_monitor 94 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698