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

Side by Side Diff: chrome/common/startup_metric_utils.cc

Issue 11785014: Record metrics for slow startups (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixup Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/common/startup_metric_utils.h" 5 #include "chrome/common/startup_metric_utils.h"
6 6
7 #include "base/hash_tables.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
10 #include "base/synchronization/lock.h"
11 #include "base/sys_info.h"
8 #include "base/time.h" 12 #include "base/time.h"
9 13
10 namespace { 14 namespace {
11 15
12 // Mark as volatile to defensively make sure usage is thread-safe. 16 // Mark as volatile to defensively make sure usage is thread-safe.
13 // Note that at the time of this writing, access is only on the UI thread. 17 // Note that at the time of this writing, access is only on the UI thread.
14 static volatile bool g_non_browser_ui_displayed = false; 18 volatile bool g_non_browser_ui_displayed = false;
15 19
16 const base::Time* MainEntryPointTimeInternal() { 20 const base::Time* MainEntryPointTimeInternal() {
17 static base::Time main_start_time = base::Time::Now(); 21 static base::Time main_start_time = base::Time::Now();
18 return &main_start_time; 22 return &main_start_time;
19 } 23 }
20 24
21 static bool g_main_entry_time_was_recorded = false; 25 typedef base::hash_map<std::string,base::TimeDelta> SubstemStartupTimeHash;
tonyg 2013/01/07 20:44:49 s/Substem/Subsystem/ ?
jeremy 2013/01/10 15:08:39 Done.
26
27 SubstemStartupTimeHash* GetSubstemStartupTimeHash() {
28 static SubstemStartupTimeHash* slow_startup_time_hash =
29 new SubstemStartupTimeHash;
30 return slow_startup_time_hash;
31 }
32
33 base::Lock* GetSubstemStartupTimeHashLock() {
34 base::Lock* slow_startup_time_hash_lock = new base::Lock;
Scott Hess - ex-Googler 2013/01/07 21:47:25 Is this supposed to protect the hash? Having it b
jeremy 2013/01/10 15:08:39 Doh!
35 return slow_startup_time_hash_lock;
36 }
37
38 bool g_main_entry_time_was_recorded = false;
22 } // namespace 39 } // namespace
23 40
24 namespace startup_metric_utils { 41 namespace startup_metric_utils {
25 42
26 bool WasNonBrowserUIDisplayed() { 43 bool WasNonBrowserUIDisplayed() {
27 return g_non_browser_ui_displayed; 44 return g_non_browser_ui_displayed;
28 } 45 }
29 46
30 void SetNonBrowserUIDisplayed() { 47 void SetNonBrowserUIDisplayed() {
31 g_non_browser_ui_displayed = true; 48 g_non_browser_ui_displayed = true;
32 } 49 }
33 50
34 void RecordMainEntryPointTime() { 51 void RecordMainEntryPointTime() {
35 DCHECK(!g_main_entry_time_was_recorded); 52 DCHECK(!g_main_entry_time_was_recorded);
36 g_main_entry_time_was_recorded = true; 53 g_main_entry_time_was_recorded = true;
37 MainEntryPointTimeInternal(); 54 MainEntryPointTimeInternal();
38 } 55 }
39 56
57 // Return the time recorded by RecordMainEntryPointTime().
40 const base::Time MainEntryStartTime() { 58 const base::Time MainEntryStartTime() {
41 DCHECK(g_main_entry_time_was_recorded); 59 DCHECK(g_main_entry_time_was_recorded);
42 return *MainEntryPointTimeInternal(); 60 return *MainEntryPointTimeInternal();
43 } 61 }
44 62
63 void OnBrowserStartupComplete() {
64 // Bail if uptime < 7 minutes, to filter out cases where Chrome may have been
65 // autostarted and the machine is under io pressure.
66 const int64 kSevenMinutesInMilliseconds =
67 base::TimeDelta::FromMinutes(7).InMilliseconds();
68 if (base::SysInfo::Uptime() < kSevenMinutesInMilliseconds)
69 return;
70
71 // The Startup.BrowserMessageLoopStartTime histogram recorded in
72 // chrome_browser_main.cc exhibits instability in the field which limits its
73 // usefulness in all scenarios except when we have a very large sample size.
74 // Attempt to mitigate this with a new metric:
75 // * Measure time from main entry rather than the OS' notion of process start
76 // time.
77 // * Only measure launches that occur 7 minutes after boot to try to avoid
78 // cases where Chrome is auto-started and IO is heavily loaded.
Scott Hess - ex-Googler 2013/01/07 21:47:25 Redundant with previous comment and test.
Scott Hess - ex-Googler 2013/01/07 21:47:25 Redundant with previous comment/test.
79 const base::TimeDelta kStartupTimeMin(base::TimeDelta::FromMilliseconds(1));
80 const base::TimeDelta kStartupTimeMax(base::TimeDelta::FromMinutes(5));
81 static const size_t kStartupTimeBuckets(100);
82
83 base::TimeDelta startup_time_from_main_entry =
84 base::Time::Now() - MainEntryStartTime();
tonyg 2013/01/07 20:44:49 nit: indent only 4 spaces
jeremy 2013/01/10 15:08:39 Done.
85 HISTOGRAM_CUSTOM_TIMES(
Scott Hess - ex-Googler 2013/01/07 21:47:25 UMA_?
jeremy 2013/01/10 15:08:39 Done.
86 "Startup.BrowserMessageLoopStartTimeFromMainEntry",
87 startup_time_from_main_entry,
88 kStartupTimeMin,
89 kStartupTimeMax,
90 kStartupTimeBuckets);
Scott Hess - ex-Googler 2013/01/07 21:47:25 Is this of material gain versus UMA_HISTOGRAM_LONG
jeremy 2013/01/10 15:08:39 Done.
91
92 // Record histograms for the subsystem times for startups > 10 seconds.
93 const base::TimeDelta kTenSeconds = base::TimeDelta::FromSeconds(10);
94 if (startup_time_from_main_entry < kTenSeconds)
95 return;
96 {
97 base::AutoLock locker(*GetSubstemStartupTimeHashLock());
98 SubstemStartupTimeHash* time_hash = GetSubstemStartupTimeHash();
99 for (auto i = time_hash->begin(); i != time_hash->end(); ++i) {
100 std::string histogram_name = i->first;
Scott Hess - ex-Googler 2013/01/07 21:47:25 const, and as long as you're making i->first more
jeremy 2013/01/10 15:08:39 Done. I thought of doing that for i->second, but
101 base::Histogram* counter = base::Histogram::FactoryTimeGet(
102 histogram_name,
103 kStartupTimeMin,
104 kStartupTimeMax,
105 kStartupTimeBuckets,
106 base::Histogram::kUmaTargetedHistogramFlag);
Scott Hess - ex-Googler 2013/01/07 21:47:25 Hmm, so I guess you can't use the macro for this,
jeremy 2013/01/10 15:08:39 Agree, do you have any suggestions for good parame
Scott Hess - ex-Googler 2013/01/10 20:43:13 Well ... what kinds of information would be useful
107 counter->AddTime(i->second);
108 }
109 }
110 }
111
112 ScopedSlowStartupUMA::~ScopedSlowStartupUMA() {
113 base::AutoLock locker(*GetSubstemStartupTimeHashLock());
114 (*GetSubstemStartupTimeHash())[histogram_name_] =
115 base::TimeTicks::Now() - start_time_;
116 }
117
45 } // namespace startup_metric_utils 118 } // namespace startup_metric_utils
OLDNEW
« chrome/common/startup_metric_utils.h ('K') | « chrome/common/startup_metric_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698