Chromium Code Reviews| 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 class IndependentFlattener : public base::HistogramFlattener { | |
|
Alexei Svitkine (slow)
2017/06/08 23:59:30
Nit: Short comment please
bcwhite
2017/06/09 15:09:27
Done.
| |
| 58 public: | |
| 59 IndependentFlattener(MetricsLog* log) : log_(log) {} | |
|
Alexei Svitkine (slow)
2017/06/08 23:59:30
explicit
bcwhite
2017/06/09 15:09:27
Done.
| |
| 60 | |
| 61 // base::HistogramFlattener: | |
| 62 void RecordDelta(const base::HistogramBase& histogram, | |
| 63 const base::HistogramSamples& snapshot) override { | |
| 64 log_->RecordHistogramDelta(histogram.histogram_name(), snapshot); | |
| 65 } | |
| 66 void InconsistencyDetected( | |
| 67 base::HistogramBase::Inconsistency problem) override {} | |
| 68 void UniqueInconsistencyDetected( | |
| 69 base::HistogramBase::Inconsistency problem) override {} | |
| 70 void InconsistencyDetectedInLoggedCount(int amount) override {} | |
| 71 | |
| 72 private: | |
| 73 MetricsLog* const log_; | |
| 74 }; | |
|
Alexei Svitkine (slow)
2017/06/08 23:59:30
Nit: DISALLOW
bcwhite
2017/06/09 15:09:27
I always forget that!
Done.
| |
| 75 | |
| 54 // Any id less than 16 bytes is considered to be a testing id. | 76 // Any id less than 16 bytes is considered to be a testing id. |
| 55 bool IsTestingID(const std::string& id) { | 77 bool IsTestingID(const std::string& id) { |
| 56 return id.size() < 16; | 78 return id.size() < 16; |
| 57 } | 79 } |
| 58 | 80 |
| 59 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, | 81 void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, |
| 60 SystemProfileProto* system_profile) { | 82 SystemProfileProto* system_profile) { |
| 61 for (std::vector<ActiveGroupId>::const_iterator it = | 83 for (std::vector<ActiveGroupId>::const_iterator it = |
| 62 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { | 84 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { |
| 63 SystemProfileProto::FieldTrial* field_trial = | 85 SystemProfileProto::FieldTrial* field_trial = |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 EnvironmentRecorder recorder(local_state_); | 334 EnvironmentRecorder recorder(local_state_); |
| 313 std::string serialized_proto = | 335 std::string serialized_proto = |
| 314 recorder.SerializeAndRecordEnvironmentToPrefs(*system_profile); | 336 recorder.SerializeAndRecordEnvironmentToPrefs(*system_profile); |
| 315 | 337 |
| 316 GlobalPersistentSystemProfile::GetInstance()->SetSystemProfile( | 338 GlobalPersistentSystemProfile::GetInstance()->SetSystemProfile( |
| 317 serialized_proto); | 339 serialized_proto); |
| 318 | 340 |
| 319 return serialized_proto; | 341 return serialized_proto; |
| 320 } | 342 } |
| 321 | 343 |
| 344 bool MetricsLog::LoadIndependentMetrics(MetricsProvider* metrics_provider) { | |
| 345 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | |
| 346 IndependentFlattener flattener(this); | |
| 347 base::HistogramSnapshotManager snapshot_manager(&flattener); | |
| 348 | |
| 349 return metrics_provider->ProvideIndependentMetrics(system_profile, | |
| 350 &snapshot_manager); | |
| 351 } | |
| 352 | |
| 322 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { | 353 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { |
| 323 DCHECK(app_version); | 354 DCHECK(app_version); |
| 324 app_version->clear(); | 355 app_version->clear(); |
| 325 | 356 |
| 326 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 357 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 327 EnvironmentRecorder recorder(local_state_); | 358 EnvironmentRecorder recorder(local_state_); |
| 328 bool success = recorder.LoadEnvironmentFromPrefs(system_profile); | 359 bool success = recorder.LoadEnvironmentFromPrefs(system_profile); |
| 329 if (success) | 360 if (success) |
| 330 *app_version = system_profile->app_version(); | 361 *app_version = system_profile->app_version(); |
| 331 return success; | 362 return success; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 354 uma_proto_.omnibox_event_size() - internal::kOmniboxEventLimit); | 385 uma_proto_.omnibox_event_size() - internal::kOmniboxEventLimit); |
| 355 } | 386 } |
| 356 } | 387 } |
| 357 | 388 |
| 358 void MetricsLog::GetEncodedLog(std::string* encoded_log) { | 389 void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
| 359 DCHECK(closed_); | 390 DCHECK(closed_); |
| 360 uma_proto_.SerializeToString(encoded_log); | 391 uma_proto_.SerializeToString(encoded_log); |
| 361 } | 392 } |
| 362 | 393 |
| 363 } // namespace metrics | 394 } // namespace metrics |
| OLD | NEW |