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_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 FileInfo* file) { | 178 FileInfo* file) { |
179 DCHECK(thread_checker_.CalledOnValidThread()); | 179 DCHECK(thread_checker_.CalledOnValidThread()); |
180 base::PersistentHistogramAllocator::Iterator histogram_iter( | 180 base::PersistentHistogramAllocator::Iterator histogram_iter( |
181 file->allocator.get()); | 181 file->allocator.get()); |
182 | 182 |
183 int histogram_count = 0; | 183 int histogram_count = 0; |
184 while (true) { | 184 while (true) { |
185 scoped_ptr<base::HistogramBase> histogram = histogram_iter.GetNext(); | 185 scoped_ptr<base::HistogramBase> histogram = histogram_iter.GetNext(); |
186 if (!histogram) | 186 if (!histogram) |
187 break; | 187 break; |
188 if (file->type == FILE_HISTOGRAMS_ATOMIC) | 188 // The "delta" is calculated, which updates the "logged" counts, even |
189 snapshot_manager->PrepareAbsoluteTakingOwnership(std::move(histogram)); | 189 // for "atomic" files that may be read-only. This is possible because |
190 else | 190 // the file contents are copied into read/write memory which is then |
191 snapshot_manager->PrepareDeltaTakingOwnership(std::move(histogram)); | 191 // discarded after the reporting is complete. |
| 192 snapshot_manager->PrepareDeltaTakingOwnership(std::move(histogram)); |
192 ++histogram_count; | 193 ++histogram_count; |
193 } | 194 } |
194 | 195 |
195 DVLOG(1) << "Reported " << histogram_count << " histograms from " | 196 DVLOG(1) << "Reported " << histogram_count << " histograms from " |
196 << file->path.value(); | 197 << file->path.value(); |
197 } | 198 } |
198 | 199 |
199 void FileMetricsProvider::CreateAllocatorForFile(FileInfo* file) { | 200 void FileMetricsProvider::CreateAllocatorForFile(FileInfo* file) { |
200 DCHECK(!file->allocator); | 201 DCHECK(!file->allocator); |
201 | 202 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 294 |
294 // Dump all histograms contained within the file to the snapshot-manager. | 295 // Dump all histograms contained within the file to the snapshot-manager. |
295 RecordHistogramSnapshotsFromFile(snapshot_manager, file.get()); | 296 RecordHistogramSnapshotsFromFile(snapshot_manager, file.get()); |
296 | 297 |
297 // Update the last-seen time so it isn't read again unless it changes. | 298 // Update the last-seen time so it isn't read again unless it changes. |
298 RecordFileAsSeen(file.get()); | 299 RecordFileAsSeen(file.get()); |
299 } | 300 } |
300 } | 301 } |
301 | 302 |
302 } // namespace metrics | 303 } // namespace metrics |
OLD | NEW |