Home | History | Annotate | Download | only in performance_monitor
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_METRIC_H_
      6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_METRIC_H_
      7 
      8 #include <string>
      9 #include "base/time/time.h"
     10 
     11 namespace performance_monitor {
     12 
     13 // IMPORTANT: To add new metrics, please
     14 // - Place the new metric above METRIC_NUMBER_OF_METRICS.
     15 // - Add a member to the MetricKeyChar enum in key_builder.cc.
     16 // - Add the appropriate messages in generated_resources.grd.
     17 // - Add the appropriate functions in
     18 //   chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h.
     19 enum MetricType {
     20   METRIC_UNDEFINED,
     21 
     22   // CPU and memory usage are combined for all Chrome-related processes.
     23   METRIC_CPU_USAGE,
     24   METRIC_PRIVATE_MEMORY_USAGE,
     25   METRIC_SHARED_MEMORY_USAGE,
     26 
     27   // Timing measurements; these are all independent metrics (e.g., session
     28   // restore time is independent of startup time, even though they may happen
     29   // in sequence). Test startup time refers to any non-normal startup time, e.g.
     30   // when we run test suites.
     31   METRIC_STARTUP_TIME,
     32   METRIC_TEST_STARTUP_TIME,
     33   METRIC_SESSION_RESTORE_TIME,
     34   METRIC_PAGE_LOAD_TIME,
     35 
     36   // Total number of bytes read since PerformanceMonitor first started running.
     37   METRIC_NETWORK_BYTES_READ,
     38 
     39   METRIC_NUMBER_OF_METRICS
     40 };
     41 
     42 struct Metric {
     43  public:
     44   Metric();
     45   Metric(MetricType metric_type,
     46          const base::Time& metric_time,
     47          const double metric_value);
     48   Metric(MetricType metric_type,
     49          const std::string& metric_time,
     50          const std::string& metric_value);
     51   ~Metric();
     52 
     53   // Check the value in the metric to make sure that it is reasonable. Since
     54   // some metric-gathering methods will fail and return incorrect values, we
     55   // need to try to weed these out as best we can.
     56   bool IsValid() const;
     57 
     58   // This converts the double stored in value to a string format. This will
     59   // not perform any checking on the validity of the metric, and only makes
     60   // sense if the metric IsValid().
     61   std::string ValueAsString() const;
     62 
     63   MetricType type;
     64   base::Time time;
     65   double value;
     66 };
     67 
     68 }  // namespace performance_monitor
     69 
     70 #endif  // CHROME_BROWSER_PERFORMANCE_MONITOR_METRIC_H_
     71