| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/file_metrics_provider.h" | 5 #include "components/metrics/file_metrics_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/memory_mapped_file.h" | 11 #include "base/files/memory_mapped_file.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_base.h" | 14 #include "base/metrics/histogram_base.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/metrics/persistent_histogram_allocator.h" | 16 #include "base/metrics/persistent_histogram_allocator.h" |
| 17 #include "base/metrics/persistent_memory_allocator.h" | 17 #include "base/metrics/persistent_memory_allocator.h" |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "components/metrics/metrics_pref_names.h" | 21 #include "components/metrics/metrics_pref_names.h" |
| 22 #include "components/metrics/metrics_service.h" | 22 #include "components/metrics/metrics_service.h" |
| 23 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
| 24 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
| 25 #include "components/variations/variations_associated_data.h" | |
| 26 | 25 |
| 27 namespace metrics { | 26 namespace metrics { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 // These structures provide values used to define how files are opened and | 30 // These structures provide values used to define how files are opened and |
| 32 // accessed. It obviates the need for multiple code-paths within several of | 31 // accessed. It obviates the need for multiple code-paths within several of |
| 33 // the methods. | 32 // the methods. |
| 34 struct SourceOptions { | 33 struct SourceOptions { |
| 35 // The flags to be used to open a file on disk. | 34 // The flags to be used to open a file on disk. |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // will continue to be used by the caller after that method returns. Once | 483 // will continue to be used by the caller after that method returns. Once |
| 485 // here, though, all actions to be done on the data have been completed. | 484 // here, though, all actions to be done on the data have been completed. |
| 486 for (const std::unique_ptr<SourceInfo>& source : sources_for_previous_run_) | 485 for (const std::unique_ptr<SourceInfo>& source : sources_for_previous_run_) |
| 487 DeleteFileAsync(source->path); | 486 DeleteFileAsync(source->path); |
| 488 sources_for_previous_run_.clear(); | 487 sources_for_previous_run_.clear(); |
| 489 } | 488 } |
| 490 | 489 |
| 491 bool FileMetricsProvider::HasInitialStabilityMetrics() { | 490 bool FileMetricsProvider::HasInitialStabilityMetrics() { |
| 492 DCHECK(thread_checker_.CalledOnValidThread()); | 491 DCHECK(thread_checker_.CalledOnValidThread()); |
| 493 | 492 |
| 494 // Check if there is an experiment that disables stability metrics. | |
| 495 std::string unreported = variations::GetVariationParamValueByFeature( | |
| 496 base::kPersistentHistogramsFeature, "send_unreported_metrics"); | |
| 497 if (unreported == "no") | |
| 498 sources_for_previous_run_.clear(); | |
| 499 | |
| 500 // Measure the total time spent checking all sources as well as the time | 493 // Measure the total time spent checking all sources as well as the time |
| 501 // per individual file. This method is called during startup and thus blocks | 494 // per individual file. This method is called during startup and thus blocks |
| 502 // the initial showing of the browser window so it's important to know the | 495 // the initial showing of the browser window so it's important to know the |
| 503 // total delay. | 496 // total delay. |
| 504 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.Total"); | 497 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.Total"); |
| 505 | 498 |
| 506 // Check all sources for previous run to see if they need to be read. | 499 // Check all sources for previous run to see if they need to be read. |
| 507 for (auto iter = sources_for_previous_run_.begin(); | 500 for (auto iter = sources_for_previous_run_.begin(); |
| 508 iter != sources_for_previous_run_.end();) { | 501 iter != sources_for_previous_run_.end();) { |
| 509 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.File"); | 502 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.File"); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 // important to know how much total "jank" may be introduced. | 563 // important to know how much total "jank" may be introduced. |
| 571 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.Total"); | 564 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.Total"); |
| 572 | 565 |
| 573 for (std::unique_ptr<SourceInfo>& source : sources_mapped_) { | 566 for (std::unique_ptr<SourceInfo>& source : sources_mapped_) { |
| 574 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.File"); | 567 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.File"); |
| 575 MergeHistogramDeltasFromSource(source.get()); | 568 MergeHistogramDeltasFromSource(source.get()); |
| 576 } | 569 } |
| 577 } | 570 } |
| 578 | 571 |
| 579 } // namespace metrics | 572 } // namespace metrics |
| OLD | NEW |