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.h" | 5 #include "components/metrics/metrics_log.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/build_time.h" | 13 #include "base/build_time.h" |
14 #include "base/cpu.h" | 14 #include "base/cpu.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/metrics/histogram_samples.h" | 17 #include "base/metrics/histogram_samples.h" |
18 #include "base/prefs/pref_registry_simple.h" | 18 #include "base/prefs/pref_registry_simple.h" |
19 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
20 #include "base/sha1.h" | 20 #include "base/sha1.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
26 #include "components/metrics/histogram_encoder.h" | |
27 #include "components/metrics/metrics_hashes.h" | 26 #include "components/metrics/metrics_hashes.h" |
28 #include "components/metrics/metrics_pref_names.h" | 27 #include "components/metrics/metrics_pref_names.h" |
29 #include "components/metrics/metrics_provider.h" | 28 #include "components/metrics/metrics_provider.h" |
30 #include "components/metrics/metrics_service_client.h" | 29 #include "components/metrics/metrics_service_client.h" |
31 #include "components/metrics/proto/histogram_event.pb.h" | 30 #include "components/metrics/proto/histogram_event.pb.h" |
32 #include "components/metrics/proto/system_profile.pb.h" | 31 #include "components/metrics/proto/system_profile.pb.h" |
33 #include "components/metrics/proto/user_action_event.pb.h" | 32 #include "components/metrics/proto/user_action_event.pb.h" |
34 #include "components/variations/active_field_trials.h" | 33 #include "components/variations/active_field_trials.h" |
35 | 34 |
36 #if defined(OS_ANDROID) | 35 #if defined(OS_ANDROID) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 DCHECK(!closed_); | 171 DCHECK(!closed_); |
173 | 172 |
174 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); | 173 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); |
175 user_action->set_name_hash(Hash(key)); | 174 user_action->set_name_hash(Hash(key)); |
176 user_action->set_time(GetCurrentTime()); | 175 user_action->set_time(GetCurrentTime()); |
177 } | 176 } |
178 | 177 |
179 void MetricsLog::RecordHistogramDelta(const std::string& histogram_name, | 178 void MetricsLog::RecordHistogramDelta(const std::string& histogram_name, |
180 const base::HistogramSamples& snapshot) { | 179 const base::HistogramSamples& snapshot) { |
181 DCHECK(!closed_); | 180 DCHECK(!closed_); |
182 EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_); | 181 DCHECK_NE(0, snapshot.TotalCount()); |
| 182 |
| 183 // We will ignore the MAX_INT/infinite value in the last element of range[]. |
| 184 |
| 185 HistogramEventProto* histogram_proto = uma_proto_.add_histogram_event(); |
| 186 histogram_proto->set_name_hash(Hash(histogram_name)); |
| 187 histogram_proto->set_sum(snapshot.sum()); |
| 188 |
| 189 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done(); |
| 190 it->Next()) { |
| 191 base::Histogram::Sample min; |
| 192 base::Histogram::Sample max; |
| 193 base::Histogram::Count count; |
| 194 it->Get(&min, &max, &count); |
| 195 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); |
| 196 bucket->set_min(min); |
| 197 bucket->set_max(max); |
| 198 bucket->set_count(count); |
| 199 } |
| 200 |
| 201 // Omit fields to save space (see rules in histogram_event.proto comments). |
| 202 for (int i = 0; i < histogram_proto->bucket_size(); ++i) { |
| 203 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i); |
| 204 if (i + 1 < histogram_proto->bucket_size() && |
| 205 bucket->max() == histogram_proto->bucket(i + 1).min()) { |
| 206 bucket->clear_max(); |
| 207 } else if (bucket->max() == bucket->min() + 1) { |
| 208 bucket->clear_min(); |
| 209 } |
| 210 } |
183 } | 211 } |
184 | 212 |
185 void MetricsLog::RecordStabilityMetrics( | 213 void MetricsLog::RecordStabilityMetrics( |
186 const std::vector<MetricsProvider*>& metrics_providers, | 214 const std::vector<MetricsProvider*>& metrics_providers, |
187 base::TimeDelta incremental_uptime, | 215 base::TimeDelta incremental_uptime, |
188 base::TimeDelta uptime) { | 216 base::TimeDelta uptime) { |
189 DCHECK(!closed_); | 217 DCHECK(!closed_); |
190 DCHECK(HasEnvironment()); | 218 DCHECK(HasEnvironment()); |
191 DCHECK(!HasStabilityMetrics()); | 219 DCHECK(!HasStabilityMetrics()); |
192 | 220 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 DCHECK(!closed_); | 427 DCHECK(!closed_); |
400 closed_ = true; | 428 closed_ = true; |
401 } | 429 } |
402 | 430 |
403 void MetricsLog::GetEncodedLog(std::string* encoded_log) { | 431 void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
404 DCHECK(closed_); | 432 DCHECK(closed_); |
405 uma_proto_.SerializeToString(encoded_log); | 433 uma_proto_.SerializeToString(encoded_log); |
406 } | 434 } |
407 | 435 |
408 } // namespace metrics | 436 } // namespace metrics |
OLD | NEW |