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

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: remove DCHECK_IS_ON from .h files because it's not always defined and don't want to add the include Created 4 years, 8 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..02c7a7fd730bbebdceb042fd4d2d0fce606e0437 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_.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,44 @@ 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 stability metrics since they're always reported
+ // before the first call to this method.
Ilya Sherman 2016/05/04 06:48:07 Hrm, why not clear them when they're reported?
bcwhite 2016/05/04 14:12:51 They have to live until the reporting is complete
Ilya Sherman 2016/05/05 07:22:37 FileInfo just provides file metadata, right? How
bcwhite 2016/05/05 16:01:17 It has all the information related to the file, in
+#if DCHECK_IS_ON()
+ for (std::unique_ptr<FileInfo>& file : files_for_previous_)
Ilya Sherman 2016/05/04 06:48:07 nit: "const auto&"?
bcwhite 2016/05/04 14:12:51 Done.
+ DCHECK(file->read_complete);
+#endif
+ files_for_previous_.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_.begin();
+ iter != files_for_previous_.end();) {
+ auto temp = iter++;
Ilya Sherman 2016/05/04 06:48:07 "iter++" is strongly discouraged, because it can b
bcwhite 2016/05/04 14:12:51 Post-increment is definitely more efficient but ++
Ilya Sherman 2016/05/05 07:22:37 I disagree pretty strongly on this point. For a l
bcwhite 2016/05/05 16:01:17 My expectations differ from yours, then, because i
+ 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.
Ilya Sherman 2016/05/04 06:48:07 Hmm, this sounds a bit disconcerting. Are we doin
bcwhite 2016/05/04 14:12:51 This method is called during startup and must retu
Ilya Sherman 2016/05/05 07:22:37 Erm, why does this block startup? If that's true,
bcwhite 2016/05/05 16:01:17 All metrics work is done on the main UI thread. A
Ilya Sherman 2016/05/05 22:22:52 Hmm, I see that you're right. I still find this p
+ AccessResult result = CheckAndMapNewMetrics(file);
+ UMA_HISTOGRAM_ENUMERATION("UMA.FileMetricsProvider.StabilityAccessResult",
+ 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
+ // 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_.erase(temp);
+ }
+ }
+
+ return !files_for_previous_.empty();
}
void FileMetricsProvider::RecordHistogramSnapshots(
@@ -300,4 +347,23 @@ void FileMetricsProvider::RecordHistogramSnapshots(
}
}
+void FileMetricsProvider::RecordStabilityHistogramSnapshots(
+ base::HistogramSnapshotManager* snapshot_manager) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ for (std::unique_ptr<FileInfo>& file : files_for_previous_) {
Ilya Sherman 2016/05/04 06:48:07 nit: "const auto&"?
bcwhite 2016/05/04 14:12:51 Done.
+ // 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());
Ilya Sherman 2016/05/04 06:48:07 Is this doing file I/O on the main thread?
bcwhite 2016/05/04 14:12:51 Yes, for the same reason as HasInitialStabilityMet
+ 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