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

Side by Side 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: Comments from isherman. Created 6 years 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/metrics/first_web_contents_profiler.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/process/process_info.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_iterator.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13
14 namespace {
Ilya Sherman 2014/11/26 04:12:26 nit: Please leave a blank line after this one.
erikchen 2014/11/26 18:24:43 Done.
15 const int kHistogramMinTimeMilliseconds = 200;
16 const int kHistogramMaxTimeSeconds = 45;
17
18 // The buckets need to be sufficiently tight that small performance
19 // improvements can be measured. We want to be able to differentiate 1%
20 // improvements, which requires 781 buckets.
Ilya Sherman 2014/11/26 04:12:26 1% improvements to what? Histograms measure a pre
erikchen 2014/11/26 18:24:43 I'm tracking the two modes of a bi-modal distribut
21 // log(45 * 1000 / 200) / log (2) / 0.01 = 781.
Ilya Sherman 2014/11/26 04:12:26 nit: I expect we'll arrive at some different compu
Ilya Sherman 2014/11/26 04:12:26 Sorry, but I don't understand the relevance of thi
erikchen 2014/11/26 18:24:43 I've updated the explanation in patch set 3 to bre
erikchen 2014/11/26 18:24:43 Done.
22 const int kHistogramBucketSize = 781;
Ilya Sherman 2014/11/26 04:12:26 nit: Please leave a blank line after this one.
erikchen 2014/11/26 18:24:43 Done.
23 } // namespace
24
25 scoped_ptr<FirstWebContentsProfiler>
26 FirstWebContentsProfiler::CreateProfilerForFirstWebContents(
27 FirstWebContentsProfilerDelegate* delegate) {
28 DCHECK(delegate);
29 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
30 Browser* browser = *iterator;
31 content::WebContents* web_contents =
32 browser->tab_strip_model()->GetActiveWebContents();
33 if (web_contents) {
34 return scoped_ptr<FirstWebContentsProfiler>(
35 new FirstWebContentsProfiler(web_contents, delegate));
36 }
37 }
38 return nullptr;
39 }
40
41 FirstWebContentsProfiler::FirstWebContentsProfiler(
42 content::WebContents* web_contents,
43 FirstWebContentsProfilerDelegate* delegate)
44 : content::WebContentsObserver(web_contents),
45 collected_paint_metric_(false),
46 collected_load_metric_(false),
47 delegate_(delegate) {
48 }
49
50 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() {
51 if (collected_paint_metric_)
52 return;
53 collected_paint_metric_ = true;
54 const base::Time process_creation_time =
55 base::CurrentProcessInfo::CreationTime();
56 if (!process_creation_time.is_null()) {
57 base::TimeDelta elapsed = base::Time::Now() - process_creation_time;
58 UMA_HISTOGRAM_CUSTOM_TIMES(
59 "Startup.FirstWebContents.NonEmptyPaint", elapsed,
60 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds),
61 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds),
62 kHistogramBucketSize);
63 }
64
65 if (IsFinishedCollectingMetrics())
66 FinishedCollectingMetrics();
67 }
68
69 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() {
70 if (collected_load_metric_)
71 return;
72 collected_load_metric_ = true;
73 const base::Time process_creation_time =
74 base::CurrentProcessInfo::CreationTime();
75 if (!process_creation_time.is_null()) {
76 base::TimeDelta elapsed = base::Time::Now() - process_creation_time;
77 UMA_HISTOGRAM_CUSTOM_TIMES(
78 "Startup.FirstWebContents.MainFrameLoad", elapsed,
79 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds),
80 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds),
81 kHistogramBucketSize);
82 }
83
84 if (IsFinishedCollectingMetrics())
85 FinishedCollectingMetrics();
86 }
87
88 void FirstWebContentsProfiler::WebContentsDestroyed() {
89 FinishedCollectingMetrics();
90 }
91
92 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() {
93 return collected_paint_metric_ && collected_load_metric_;
94 }
95
96 void FirstWebContentsProfiler::FinishedCollectingMetrics() {
97 delegate_->ProfilerFinishedCollectingMetrics();
98 }
OLDNEW
« 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