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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 private: | 115 private: |
116 DISALLOW_COPY_AND_ASSIGN(SourceInfo); | 116 DISALLOW_COPY_AND_ASSIGN(SourceInfo); |
117 }; | 117 }; |
118 | 118 |
119 FileMetricsProvider::FileMetricsProvider( | 119 FileMetricsProvider::FileMetricsProvider( |
120 const scoped_refptr<base::TaskRunner>& task_runner, | 120 const scoped_refptr<base::TaskRunner>& task_runner, |
121 PrefService* local_state) | 121 PrefService* local_state) |
122 : task_runner_(task_runner), | 122 : task_runner_(task_runner), |
123 pref_service_(local_state), | 123 pref_service_(local_state), |
124 weak_factory_(this) { | 124 weak_factory_(this) { |
| 125 base::StatisticsRecorder::RegisterHistogramProvider( |
| 126 weak_factory_.GetWeakPtr()); |
125 } | 127 } |
126 | 128 |
127 FileMetricsProvider::~FileMetricsProvider() {} | 129 FileMetricsProvider::~FileMetricsProvider() {} |
128 | 130 |
129 void FileMetricsProvider::RegisterSource(const base::FilePath& path, | 131 void FileMetricsProvider::RegisterSource(const base::FilePath& path, |
130 SourceType type, | 132 SourceType type, |
131 SourceAssociation source_association, | 133 SourceAssociation source_association, |
132 const base::StringPiece prefs_key) { | 134 const base::StringPiece prefs_key) { |
133 DCHECK(thread_checker_.CalledOnValidThread()); | 135 DCHECK(thread_checker_.CalledOnValidThread()); |
134 | 136 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 DCHECK(!source->allocator); | 517 DCHECK(!source->allocator); |
516 RecordSourceAsRead(source); | 518 RecordSourceAsRead(source); |
517 DeleteFileAsync(source->path); | 519 DeleteFileAsync(source->path); |
518 sources_for_previous_run_.erase(temp); | 520 sources_for_previous_run_.erase(temp); |
519 } | 521 } |
520 } | 522 } |
521 | 523 |
522 return !sources_for_previous_run_.empty(); | 524 return !sources_for_previous_run_.empty(); |
523 } | 525 } |
524 | 526 |
525 void FileMetricsProvider::MergeHistogramDeltas() { | |
526 DCHECK(thread_checker_.CalledOnValidThread()); | |
527 | |
528 // Measure the total time spent processing all sources as well as the time | |
529 // per individual file. This method is called on the UI thread so it's | |
530 // important to know how much total "jank" may be introduced. | |
531 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.Total"); | |
532 | |
533 for (std::unique_ptr<SourceInfo>& source : sources_mapped_) { | |
534 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.File"); | |
535 MergeHistogramDeltasFromSource(source.get()); | |
536 } | |
537 } | |
538 | |
539 void FileMetricsProvider::RecordInitialHistogramSnapshots( | 527 void FileMetricsProvider::RecordInitialHistogramSnapshots( |
540 base::HistogramSnapshotManager* snapshot_manager) { | 528 base::HistogramSnapshotManager* snapshot_manager) { |
541 DCHECK(thread_checker_.CalledOnValidThread()); | 529 DCHECK(thread_checker_.CalledOnValidThread()); |
542 | 530 |
543 // Measure the total time spent processing all sources as well as the time | 531 // Measure the total time spent processing all sources as well as the time |
544 // per individual file. This method is called during startup and thus blocks | 532 // per individual file. This method is called during startup and thus blocks |
545 // the initial showing of the browser window so it's important to know the | 533 // the initial showing of the browser window so it's important to know the |
546 // total delay. | 534 // total delay. |
547 SCOPED_UMA_HISTOGRAM_TIMER( | 535 SCOPED_UMA_HISTOGRAM_TIMER( |
548 "UMA.FileMetricsProvider.InitialSnapshotTime.Total"); | 536 "UMA.FileMetricsProvider.InitialSnapshotTime.Total"); |
549 | 537 |
550 for (const std::unique_ptr<SourceInfo>& source : sources_for_previous_run_) { | 538 for (const std::unique_ptr<SourceInfo>& source : sources_for_previous_run_) { |
551 SCOPED_UMA_HISTOGRAM_TIMER( | 539 SCOPED_UMA_HISTOGRAM_TIMER( |
552 "UMA.FileMetricsProvider.InitialSnapshotTime.File"); | 540 "UMA.FileMetricsProvider.InitialSnapshotTime.File"); |
553 | 541 |
554 // The source needs to have an allocator attached to it in order to read | 542 // The source needs to have an allocator attached to it in order to read |
555 // histograms out of it. | 543 // histograms out of it. |
556 DCHECK(!source->read_complete); | 544 DCHECK(!source->read_complete); |
557 DCHECK(source->allocator); | 545 DCHECK(source->allocator); |
558 | 546 |
559 // Dump all histograms contained within the source to the snapshot-manager. | 547 // Dump all histograms contained within the source to the snapshot-manager. |
560 RecordHistogramSnapshotsFromSource(snapshot_manager, source.get()); | 548 RecordHistogramSnapshotsFromSource(snapshot_manager, source.get()); |
561 | 549 |
562 // Update the last-seen time so it isn't read again unless it changes. | 550 // Update the last-seen time so it isn't read again unless it changes. |
563 RecordSourceAsRead(source.get()); | 551 RecordSourceAsRead(source.get()); |
564 } | 552 } |
565 } | 553 } |
566 | 554 |
| 555 void FileMetricsProvider::MergeHistogramDeltas() { |
| 556 DCHECK(thread_checker_.CalledOnValidThread()); |
| 557 |
| 558 // Measure the total time spent processing all sources as well as the time |
| 559 // per individual file. This method is called on the UI thread so it's |
| 560 // important to know how much total "jank" may be introduced. |
| 561 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.Total"); |
| 562 |
| 563 for (std::unique_ptr<SourceInfo>& source : sources_mapped_) { |
| 564 SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime.File"); |
| 565 MergeHistogramDeltasFromSource(source.get()); |
| 566 } |
| 567 } |
| 568 |
567 } // namespace metrics | 569 } // namespace metrics |
OLD | NEW |