Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / components / metrics / metrics_log_base.h
blob25a6bd08832f50b8942dd762f2a6665bd1c19c8b
1 // Copyright 2014 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.
5 // This file defines a set of user experience metrics data recorded by
6 // the MetricsService. This is the unit of data that is sent to the server.
8 #ifndef COMPONENTS_METRICS_METRICS_LOG_BASE_H_
9 #define COMPONENTS_METRICS_METRICS_LOG_BASE_H_
11 #include <string>
13 #include "base/basictypes.h"
14 #include "base/metrics/histogram.h"
15 #include "base/time/time.h"
16 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
18 namespace base {
19 class HistogramSamples;
20 } // namespace base
22 namespace metrics {
24 // This class provides base functionality for logging metrics data.
25 class MetricsLogBase {
26 public:
27 // TODO(asvitkine): Remove the NO_LOG value.
28 enum LogType {
29 INITIAL_STABILITY_LOG, // The initial log containing stability stats.
30 ONGOING_LOG, // Subsequent logs in a session.
31 NO_LOG, // Placeholder value for when there is no log.
34 // Creates a new metrics log of the specified type.
35 // client_id is the identifier for this profile on this installation
36 // session_id is an integer that's incremented on each application launch
37 MetricsLogBase(const std::string& client_id,
38 int session_id,
39 LogType log_type,
40 const std::string& version_string);
41 virtual ~MetricsLogBase();
43 // Computes the MD5 hash of the given string, and returns the first 8 bytes of
44 // the hash.
45 static uint64 Hash(const std::string& value);
47 // Get the GMT buildtime for the current binary, expressed in seconds since
48 // January 1, 1970 GMT.
49 // The value is used to identify when a new build is run, so that previous
50 // reliability stats, from other builds, can be abandoned.
51 static int64 GetBuildTime();
53 // Convenience function to return the current time at a resolution in seconds.
54 // This wraps base::TimeTicks, and hence provides an abstract time that is
55 // always incrementing for use in measuring time durations.
56 static int64 GetCurrentTime();
58 // Records a user-initiated action.
59 void RecordUserAction(const std::string& key);
61 // Record any changes in a given histogram for transmission.
62 void RecordHistogramDelta(const std::string& histogram_name,
63 const base::HistogramSamples& snapshot);
65 // Stop writing to this record and generate the encoded representation.
66 // None of the Record* methods can be called after this is called.
67 void CloseLog();
69 // Fills |encoded_log| with the serialized protobuf representation of the
70 // record. Must only be called after CloseLog() has been called.
71 void GetEncodedLog(std::string* encoded_log);
73 int num_events() { return num_events_; }
75 void set_hardware_class(const std::string& hardware_class) {
76 uma_proto_.mutable_system_profile()->mutable_hardware()->set_hardware_class(
77 hardware_class);
80 LogType log_type() const { return log_type_; }
82 protected:
83 bool locked() const { return locked_; }
85 metrics::ChromeUserMetricsExtension* uma_proto() { return &uma_proto_; }
86 const metrics::ChromeUserMetricsExtension* uma_proto() const {
87 return &uma_proto_;
90 // TODO(isherman): Remove this once the XML pipeline is outta here.
91 int num_events_; // the number of events recorded in this log
93 private:
94 // locked_ is true when record has been packed up for sending, and should
95 // no longer be written to. It is only used for sanity checking and is
96 // not a real lock.
97 bool locked_;
99 // The type of the log, i.e. initial or ongoing.
100 const LogType log_type_;
102 // Stores the protocol buffer representation for this log.
103 metrics::ChromeUserMetricsExtension uma_proto_;
105 DISALLOW_COPY_AND_ASSIGN(MetricsLogBase);
108 } // namespace metrics
110 #endif // COMPONENTS_METRICS_METRICS_LOG_BASE_H_