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

Unified Diff: chrome/browser/metrics/first_web_contents_profiler.cc

Issue 760763002: Add startup metrics that measure the performance of the first web contents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve documentation. Created 6 years, 1 month 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
« no previous file with comments | « chrome/browser/metrics/first_web_contents_profiler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/first_web_contents_profiler.cc
diff --git a/chrome/browser/metrics/first_web_contents_profiler.cc b/chrome/browser/metrics/first_web_contents_profiler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b1d2a90cd9cc1dd5ce8d13d95af5c1ea27d9bb76
--- /dev/null
+++ b/chrome/browser/metrics/first_web_contents_profiler.cc
@@ -0,0 +1,112 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/metrics/first_web_contents_profiler.h"
+
+#include "base/metrics/histogram.h"
+#include "base/process/process_info.h"
+#include "base/time/time.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_iterator.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+
+namespace {
+
+const int kHistogramMinTimeMilliseconds = 200;
+const int kHistogramMaxTimeSeconds = 45;
+
+// Startup histograms are always bimodal. I strongly suspect that the two modes
+// correspond to devices with an SSD vs. devices with an HDD. As such, neither
+// the mean nor the median are particularly relevant.
+//
+// Most changes to startup improvement will be incremenetal, and have a
+// relatively small effect on one or both of the modes. It's important that the
+// bucket count is sufficiently large that these changes can be measured to
+// determine whether their intended effect matches the actual effect.
+//
+// I want to be able to differentiate between 1% improvements, so the
+// logarithmic difference between buckets must be 0.01.
Ilya Sherman 2014/11/26 22:04:08 What is the connection between 1% and a logarithmi
+//
+// Total logarithmic difference between top/bottom buckets = lg(45 * 1000 /
+// 200) = 7.81
+// The number of buckets needed for a logarithmic difference of 0.01 is 7.81 /
+// 0.01 = 781.
+const int kHistogramBucketSize = 781;
+
+} // namespace
+
+scoped_ptr<FirstWebContentsProfiler>
+FirstWebContentsProfiler::CreateProfilerForFirstWebContents(
+ FirstWebContentsProfilerDelegate* delegate) {
+ DCHECK(delegate);
+ for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
+ Browser* browser = *iterator;
+ content::WebContents* web_contents =
+ browser->tab_strip_model()->GetActiveWebContents();
+ if (web_contents) {
+ return scoped_ptr<FirstWebContentsProfiler>(
+ new FirstWebContentsProfiler(web_contents, delegate));
+ }
+ }
+ return nullptr;
+}
+
+FirstWebContentsProfiler::FirstWebContentsProfiler(
+ content::WebContents* web_contents,
+ FirstWebContentsProfilerDelegate* delegate)
+ : content::WebContentsObserver(web_contents),
+ collected_paint_metric_(false),
+ collected_load_metric_(false),
+ delegate_(delegate) {
+}
+
+void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() {
+ if (collected_paint_metric_)
+ return;
+ collected_paint_metric_ = true;
+ const base::Time process_creation_time =
+ base::CurrentProcessInfo::CreationTime();
+ if (!process_creation_time.is_null()) {
+ base::TimeDelta elapsed = base::Time::Now() - process_creation_time;
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "Startup.FirstWebContents.NonEmptyPaint", elapsed,
+ base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds),
+ base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds),
+ kHistogramBucketSize);
+ }
+
+ if (IsFinishedCollectingMetrics())
+ FinishedCollectingMetrics();
+}
+
+void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() {
+ if (collected_load_metric_)
+ return;
+ collected_load_metric_ = true;
+ const base::Time process_creation_time =
+ base::CurrentProcessInfo::CreationTime();
+ if (!process_creation_time.is_null()) {
+ base::TimeDelta elapsed = base::Time::Now() - process_creation_time;
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "Startup.FirstWebContents.MainFrameLoad", elapsed,
+ base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds),
+ base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds),
+ kHistogramBucketSize);
+ }
+
+ if (IsFinishedCollectingMetrics())
+ FinishedCollectingMetrics();
+}
+
+void FirstWebContentsProfiler::WebContentsDestroyed() {
+ FinishedCollectingMetrics();
+}
+
+bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() {
+ return collected_paint_metric_ && collected_load_metric_;
+}
+
+void FirstWebContentsProfiler::FinishedCollectingMetrics() {
+ delegate_->ProfilerFinishedCollectingMetrics();
+}
« no previous file with comments | « chrome/browser/metrics/first_web_contents_profiler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698