| 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" |
| 25 | 26 |
| 26 namespace metrics { | 27 namespace metrics { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // These structures provide values used to define how files are opened and | 31 // These structures provide values used to define how files are opened and |
| 31 // accessed. It obviates the need for multiple code-paths within several of | 32 // accessed. It obviates the need for multiple code-paths within several of |
| 32 // the methods. | 33 // the methods. |
| 33 struct SourceOptions { | 34 struct SourceOptions { |
| 34 // The flags to be used to open a file on disk. | 35 // The flags to be used to open a file on disk. |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 // will continue to be used by the caller after that method returns. Once | 465 // will continue to be used by the caller after that method returns. Once |
| 465 // here, though, all actions to be done on the data have been completed. | 466 // here, though, all actions to be done on the data have been completed. |
| 466 for (const std::unique_ptr<SourceInfo>& source : sources_for_previous_run_) | 467 for (const std::unique_ptr<SourceInfo>& source : sources_for_previous_run_) |
| 467 DeleteFileAsync(source->path); | 468 DeleteFileAsync(source->path); |
| 468 sources_for_previous_run_.clear(); | 469 sources_for_previous_run_.clear(); |
| 469 } | 470 } |
| 470 | 471 |
| 471 bool FileMetricsProvider::HasInitialStabilityMetrics() { | 472 bool FileMetricsProvider::HasInitialStabilityMetrics() { |
| 472 DCHECK(thread_checker_.CalledOnValidThread()); | 473 DCHECK(thread_checker_.CalledOnValidThread()); |
| 473 | 474 |
| 475 // Check if there is an experiment that disables stability metrics. |
| 476 std::string unreported = variations::GetVariationParamValueByFeature( |
| 477 base::kPersistentHistogramsFeature, "send_unreported_metrics"); |
| 478 if (unreported == "no") |
| 479 sources_for_previous_run_.clear(); |
| 480 |
| 474 // Measure the total time spent checking all sources as well as the time | 481 // Measure the total time spent checking all sources as well as the time |
| 475 // per individual file. This method is called during startup and thus blocks | 482 // per individual file. This method is called during startup and thus blocks |
| 476 // the initial showing of the browser window so it's important to know the | 483 // the initial showing of the browser window so it's important to know the |
| 477 // total delay. | 484 // total delay. |
| 478 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.Total"); | 485 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.Total"); |
| 479 | 486 |
| 480 // Check all sources for previous run to see if they need to be read. | 487 // Check all sources for previous run to see if they need to be read. |
| 481 for (auto iter = sources_for_previous_run_.begin(); | 488 for (auto iter = sources_for_previous_run_.begin(); |
| 482 iter != sources_for_previous_run_.end();) { | 489 iter != sources_for_previous_run_.end();) { |
| 483 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.File"); | 490 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime.File"); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 | 551 |
| 545 // Dump all histograms contained within the source to the snapshot-manager. | 552 // Dump all histograms contained within the source to the snapshot-manager. |
| 546 RecordHistogramSnapshotsFromSource(snapshot_manager, source.get()); | 553 RecordHistogramSnapshotsFromSource(snapshot_manager, source.get()); |
| 547 | 554 |
| 548 // Update the last-seen time so it isn't read again unless it changes. | 555 // Update the last-seen time so it isn't read again unless it changes. |
| 549 RecordSourceAsRead(source.get()); | 556 RecordSourceAsRead(source.get()); |
| 550 } | 557 } |
| 551 } | 558 } |
| 552 | 559 |
| 553 } // namespace metrics | 560 } // namespace metrics |
| OLD | NEW |