| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/metrics/metrics_log_base.h" | 5 #include "components/metrics/metrics_log_base.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_base.h" | 7 #include "base/metrics/histogram_base.h" |
| 8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "components/metrics/metrics_hashes.h" | 9 #include "components/metrics/metrics_hashes.h" |
| 10 #include "components/metrics/proto/histogram_event.pb.h" | 10 #include "components/metrics/proto/histogram_event.pb.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 bool IsTestingID(const std::string& id) { | 28 bool IsTestingID(const std::string& id) { |
| 29 return id.size() < 16; | 29 return id.size() < 16; |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 MetricsLogBase::MetricsLogBase(const std::string& client_id, | 34 MetricsLogBase::MetricsLogBase(const std::string& client_id, |
| 35 int session_id, | 35 int session_id, |
| 36 LogType log_type, | 36 LogType log_type, |
| 37 const std::string& version_string) | 37 const std::string& version_string) |
| 38 : num_events_(0), | 38 : locked_(false), |
| 39 locked_(false), | |
| 40 log_type_(log_type) { | 39 log_type_(log_type) { |
| 41 DCHECK_NE(NO_LOG, log_type); | 40 DCHECK_NE(NO_LOG, log_type); |
| 42 if (IsTestingID(client_id)) | 41 if (IsTestingID(client_id)) |
| 43 uma_proto_.set_client_id(0); | 42 uma_proto_.set_client_id(0); |
| 44 else | 43 else |
| 45 uma_proto_.set_client_id(Hash(client_id)); | 44 uma_proto_.set_client_id(Hash(client_id)); |
| 46 | 45 |
| 47 uma_proto_.set_session_id(session_id); | 46 uma_proto_.set_session_id(session_id); |
| 48 uma_proto_.mutable_system_profile()->set_build_timestamp(GetBuildTime()); | 47 uma_proto_.mutable_system_profile()->set_build_timestamp(GetBuildTime()); |
| 49 uma_proto_.mutable_system_profile()->set_app_version(version_string); | 48 uma_proto_.mutable_system_profile()->set_app_version(version_string); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 DCHECK(locked_); | 92 DCHECK(locked_); |
| 94 uma_proto_.SerializeToString(encoded_log); | 93 uma_proto_.SerializeToString(encoded_log); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void MetricsLogBase::RecordUserAction(const std::string& key) { | 96 void MetricsLogBase::RecordUserAction(const std::string& key) { |
| 98 DCHECK(!locked_); | 97 DCHECK(!locked_); |
| 99 | 98 |
| 100 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); | 99 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); |
| 101 user_action->set_name_hash(Hash(key)); | 100 user_action->set_name_hash(Hash(key)); |
| 102 user_action->set_time(GetCurrentTime()); | 101 user_action->set_time(GetCurrentTime()); |
| 103 | |
| 104 ++num_events_; | |
| 105 } | 102 } |
| 106 | 103 |
| 107 void MetricsLogBase::RecordHistogramDelta(const std::string& histogram_name, | 104 void MetricsLogBase::RecordHistogramDelta(const std::string& histogram_name, |
| 108 const HistogramSamples& snapshot) { | 105 const HistogramSamples& snapshot) { |
| 109 DCHECK(!locked_); | 106 DCHECK(!locked_); |
| 110 DCHECK_NE(0, snapshot.TotalCount()); | 107 DCHECK_NE(0, snapshot.TotalCount()); |
| 111 | 108 |
| 112 // We will ignore the MAX_INT/infinite value in the last element of range[]. | 109 // We will ignore the MAX_INT/infinite value in the last element of range[]. |
| 113 | 110 |
| 114 HistogramEventProto* histogram_proto = uma_proto_.add_histogram_event(); | 111 HistogramEventProto* histogram_proto = uma_proto_.add_histogram_event(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 133 if (i + 1 < histogram_proto->bucket_size() && | 130 if (i + 1 < histogram_proto->bucket_size() && |
| 134 bucket->max() == histogram_proto->bucket(i + 1).min()) { | 131 bucket->max() == histogram_proto->bucket(i + 1).min()) { |
| 135 bucket->clear_max(); | 132 bucket->clear_max(); |
| 136 } else if (bucket->max() == bucket->min() + 1) { | 133 } else if (bucket->max() == bucket->min() + 1) { |
| 137 bucket->clear_min(); | 134 bucket->clear_min(); |
| 138 } | 135 } |
| 139 } | 136 } |
| 140 } | 137 } |
| 141 | 138 |
| 142 } // namespace metrics | 139 } // namespace metrics |
| OLD | NEW |