Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1008)

Unified Diff: components/metrics/file_metrics_provider.cc

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Ilya Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/metrics/file_metrics_provider.cc
diff --git a/components/metrics/file_metrics_provider.cc b/components/metrics/file_metrics_provider.cc
index 44df25c5fd67a62230ded244d2844314996e24ad..d085d8e2dea9a6ac3c5a6eaf24fa41239ab3ca75 100644
--- a/components/metrics/file_metrics_provider.cc
+++ b/components/metrics/file_metrics_provider.cc
@@ -69,6 +69,7 @@ FileMetricsProvider::~FileMetricsProvider() {}
void FileMetricsProvider::RegisterFile(const base::FilePath& path,
FileType type,
+ FileAssociation file_association,
const base::StringPiece prefs_key) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -84,7 +85,15 @@ void FileMetricsProvider::RegisterFile(const base::FilePath& path,
file->prefs_key));
}
- files_to_check_.push_back(std::move(file));
+ switch (file_association) {
+ case ASSOCIATE_CURRENT_RUN:
+ files_to_check_.push_back(std::move(file));
+ break;
+ case ASSOCIATE_PREVIOUS_RUN:
+ DCHECK_EQ(FILE_HISTOGRAMS_ATOMIC, file->type);
+ files_for_previous_run_.push_back(std::move(file));
+ break;
+ }
}
// static
@@ -187,7 +196,7 @@ void FileMetricsProvider::RecordHistogramSnapshotsFromFile(
if (!histogram)
break;
if (file->type == FILE_HISTOGRAMS_ATOMIC)
- snapshot_manager->PrepareAbsoluteTakingOwnership(std::move(histogram));
+ snapshot_manager->PrepareFinalDeltaTakingOwnership(std::move(histogram));
else
snapshot_manager->PrepareDeltaTakingOwnership(std::move(histogram));
++histogram_count;
@@ -268,6 +277,46 @@ void FileMetricsProvider::OnDidCreateMetricsLog() {
// check is run off of the worker-pool so as to not cause delays on the
// main UI thread (which is currently where metric collection is done).
ScheduleFilesCheck();
+
+ // Clear any data for initial metrics since they're always reported
+ // before the first call to this method.
Ilya Sherman 2016/05/05 22:22:52 Please document here why it's not appropriate for
bcwhite 2016/05/06 16:59:27 Done.
+#if DCHECK_IS_ON()
+ for (const std::unique_ptr<FileInfo>& file : files_for_previous_run_)
+ DCHECK(file->read_complete);
+#endif
+ files_for_previous_run_.clear();
+}
+
+bool FileMetricsProvider::HasInitialStabilityMetrics() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Check all files for previous run to see if they need to be read.
+ for (auto iter = files_for_previous_run_.begin();
+ iter != files_for_previous_run_.end();) {
+ SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialCheckTime");
+
+ auto temp = iter++;
+ FileInfo* file = temp->get();
+
+ // This would normally be done on a background I/O thread but there
+ // hasn't been a chance to run any at the time this method is called.
+ // Do the check in-line.
+ AccessResult result = CheckAndMapNewMetrics(file);
+ UMA_HISTOGRAM_ENUMERATION("UMA.FileMetricsProvider.InitialAccessResult",
+ result, ACCESS_RESULT_MAX);
+
+ // If it couldn't be accessed, remove it from the list. There is only ever
+ // one chance to record it no point keeping it around for later. Also mark
Ilya Sherman 2016/05/05 22:22:52 nit: "it no" -> "it, so no"
bcwhite 2016/05/06 16:59:27 Done.
+ // it as having been read since uploading it with a future browser run
+ // would associate it the previous run which would no longer be the run
+ // from which it came.
+ if (result != ACCESS_RESULT_SUCCESS) {
+ RecordFileAsSeen(file);
+ files_for_previous_run_.erase(temp);
+ }
+ }
+
+ return !files_for_previous_run_.empty();
}
void FileMetricsProvider::RecordHistogramSnapshots(
@@ -279,6 +328,8 @@ void FileMetricsProvider::RecordHistogramSnapshots(
if (file->read_complete)
continue;
+ SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.SnapshotTime");
Ilya Sherman 2016/05/05 22:22:52 Please also add a histogram to measure the snapsho
bcwhite 2016/05/06 16:59:27 Done.
+
// If the file is mapped or loaded then it needs to have an allocator
// attached to it in order to read histograms out of it.
if (file->mapped || !file->data.empty())
@@ -300,4 +351,25 @@ void FileMetricsProvider::RecordHistogramSnapshots(
}
}
+void FileMetricsProvider::RecordInitialHistogramSnapshots(
+ base::HistogramSnapshotManager* snapshot_manager) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ for (const std::unique_ptr<FileInfo>& file : files_for_previous_run_) {
+ SCOPED_UMA_HISTOGRAM_TIMER("UMA.FileMetricsProvider.InitialSnapshotTime");
+
+ // The file needs to have an allocator attached to it in order to read
+ // histograms out of it.
+ DCHECK(file->mapped || !file->data.empty());
+ CreateAllocatorForFile(file.get());
+ DCHECK(file->allocator);
+
+ // Dump all histograms contained within the file to the snapshot-manager.
+ RecordHistogramSnapshotsFromFile(snapshot_manager, file.get());
+
+ // Update the last-seen time so it isn't read again unless it changes.
+ RecordFileAsSeen(file.get());
+ }
+}
+
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698