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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/build_time.h" | 12 #include "base/build_time.h" |
13 #include "base/cpu.h" | 13 #include "base/cpu.h" |
| 14 #include "base/metrics/histogram_base.h" |
| 15 #include "base/metrics/histogram_flattener.h" |
14 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
15 #include "base/metrics/histogram_samples.h" | 17 #include "base/metrics/histogram_samples.h" |
| 18 #include "base/metrics/histogram_snapshot_manager.h" |
16 #include "base/metrics/metrics_hashes.h" | 19 #include "base/metrics/metrics_hashes.h" |
17 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
18 #include "base/time/time.h" | 21 #include "base/time/time.h" |
19 #include "build/build_config.h" | 22 #include "build/build_config.h" |
20 #include "components/metrics/environment_recorder.h" | 23 #include "components/metrics/environment_recorder.h" |
21 #include "components/metrics/histogram_encoder.h" | 24 #include "components/metrics/histogram_encoder.h" |
22 #include "components/metrics/metrics_pref_names.h" | 25 #include "components/metrics/metrics_pref_names.h" |
23 #include "components/metrics/metrics_provider.h" | 26 #include "components/metrics/metrics_provider.h" |
24 #include "components/metrics/metrics_service_client.h" | 27 #include "components/metrics/metrics_service_client.h" |
25 #include "components/metrics/persistent_system_profile.h" | 28 #include "components/metrics/persistent_system_profile.h" |
(...skipping 18 matching lines...) Expand all Loading... |
44 namespace metrics { | 47 namespace metrics { |
45 | 48 |
46 namespace internal { | 49 namespace internal { |
47 // Maximum number of events before truncation. | 50 // Maximum number of events before truncation. |
48 extern const int kOmniboxEventLimit = 5000; | 51 extern const int kOmniboxEventLimit = 5000; |
49 extern const int kUserActionEventLimit = 5000; | 52 extern const int kUserActionEventLimit = 5000; |
50 } | 53 } |
51 | 54 |
52 namespace { | 55 namespace { |
53 | 56 |
| 57 // A simple class to write histogram data to a log. |
| 58 class IndependentFlattener : public base::HistogramFlattener { |
| 59 public: |
| 60 explicit IndependentFlattener(MetricsLog* log) : log_(log) {} |
| 61 |
| 62 // base::HistogramFlattener: |
| 63 void RecordDelta(const base::HistogramBase& histogram, |
| 64 const base::HistogramSamples& snapshot) override { |
| 65 log_->RecordHistogramDelta(histogram.histogram_name(), snapshot); |
| 66 } |
| 67 void InconsistencyDetected( |
| 68 base::HistogramBase::Inconsistency problem) override {} |
| 69 void UniqueInconsistencyDetected( |
| 70 base::HistogramBase::Inconsistency problem) override {} |
| 71 void InconsistencyDetectedInLoggedCount(int amount) override {} |
| 72 |
| 73 private: |
| 74 MetricsLog* const log_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(IndependentFlattener); |
| 77 }; |
| 78 |
54 // Any id less than 16 bytes is considered to be a testing id. | 79 // Any id less than 16 bytes is considered to be a testing id. |
55 bool IsTestingID(const std::string& id) { | 80 bool IsTestingID(const std::string& id) { |
56 return id.size() < 16; | 81 return id.size() < 16; |
57 } | 82 } |
58 | 83 |
59 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, | 84 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, |
60 SystemProfileProto* system_profile) { | 85 SystemProfileProto* system_profile) { |
61 for (std::vector<ActiveGroupId>::const_iterator it = | 86 for (std::vector<ActiveGroupId>::const_iterator it = |
62 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { | 87 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { |
63 SystemProfileProto::FieldTrial* field_trial = | 88 SystemProfileProto::FieldTrial* field_trial = |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 EnvironmentRecorder recorder(local_state_); | 337 EnvironmentRecorder recorder(local_state_); |
313 std::string serialized_proto = | 338 std::string serialized_proto = |
314 recorder.SerializeAndRecordEnvironmentToPrefs(*system_profile); | 339 recorder.SerializeAndRecordEnvironmentToPrefs(*system_profile); |
315 | 340 |
316 GlobalPersistentSystemProfile::GetInstance()->SetSystemProfile( | 341 GlobalPersistentSystemProfile::GetInstance()->SetSystemProfile( |
317 serialized_proto); | 342 serialized_proto); |
318 | 343 |
319 return serialized_proto; | 344 return serialized_proto; |
320 } | 345 } |
321 | 346 |
| 347 bool MetricsLog::LoadIndependentMetrics(MetricsProvider* metrics_provider) { |
| 348 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 349 IndependentFlattener flattener(this); |
| 350 base::HistogramSnapshotManager snapshot_manager(&flattener); |
| 351 |
| 352 return metrics_provider->ProvideIndependentMetrics(system_profile, |
| 353 &snapshot_manager); |
| 354 } |
| 355 |
322 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { | 356 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { |
323 DCHECK(app_version); | 357 DCHECK(app_version); |
324 app_version->clear(); | 358 app_version->clear(); |
325 | 359 |
326 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 360 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
327 EnvironmentRecorder recorder(local_state_); | 361 EnvironmentRecorder recorder(local_state_); |
328 bool success = recorder.LoadEnvironmentFromPrefs(system_profile); | 362 bool success = recorder.LoadEnvironmentFromPrefs(system_profile); |
329 if (success) | 363 if (success) |
330 *app_version = system_profile->app_version(); | 364 *app_version = system_profile->app_version(); |
331 return success; | 365 return success; |
(...skipping 22 matching lines...) Expand all Loading... |
354 uma_proto_.omnibox_event_size() - internal::kOmniboxEventLimit); | 388 uma_proto_.omnibox_event_size() - internal::kOmniboxEventLimit); |
355 } | 389 } |
356 } | 390 } |
357 | 391 |
358 void MetricsLog::GetEncodedLog(std::string* encoded_log) { | 392 void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
359 DCHECK(closed_); | 393 DCHECK(closed_); |
360 uma_proto_.SerializeToString(encoded_log); | 394 uma_proto_.SerializeToString(encoded_log); |
361 } | 395 } |
362 | 396 |
363 } // namespace metrics | 397 } // namespace metrics |
OLD | NEW |