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

Side by Side Diff: chrome/browser/mac/mac_startup_profiler.cc

Issue 393753002: mac: Add a profiler for startup time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test Created 6 years, 5 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
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/mac/mac_startup_profiler.h"
6
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9
10 // static
11 MacStartupProfiler* MacStartupProfiler::GetInstance() {
12 return Singleton<MacStartupProfiler>::get();
13 }
14
15 MacStartupProfiler::MacStartupProfiler()
16 : recorded_metrics_(false), launch_time_valid_(false) {
17 }
18
19 MacStartupProfiler::~MacStartupProfiler() {
20 }
21
22 void MacStartupProfiler::RecordLaunchTime() {
23 launch_time_ = base::Time::Now();
24 launch_time_valid_ = true;
25 }
26
27 void MacStartupProfiler::Profile(Location location) {
28 DCHECK(launch_time_valid_);
29 map_.insert(std::make_pair(location, base::Time::Now()));
Ilya Sherman 2014/07/15 18:14:24 nit: IMO "map_[location] = base::Time::Now();" is
erikchen 2014/07/15 21:39:42 Done.
30 }
31
32 void MacStartupProfiler::RecordMetrics() {
33 DCHECK(launch_time_valid_);
34 DCHECK(!recorded_metrics_);
35
36 recorded_metrics_ = true;
37
38 for (std::map<Location, base::Time>::iterator it = map_.begin();
Ilya Sherman 2014/07/15 18:14:24 nit: Can this be a const_iterator?
erikchen 2014/07/15 21:39:42 yes, done
39 it != map_.end();
40 ++it) {
41 const base::Time& location_time = it->second;
42 base::TimeDelta delta = location_time - launch_time_;
43 RecordHistogram(it->first, delta);
44 }
45 }
46
47 const char* MacStartupProfiler::HistogramName(Location location) {
48 #define HISTOGRAM_PREFIX "OSX.Startup."
Ilya Sherman 2014/07/15 18:14:24 Please return a string and use normal string conca
erikchen 2014/07/15 21:39:42 The preprocessor macro uses fewer lines of code, a
49 switch (location) {
50 case PRE_MAIN_MESSAGE_LOOP_START:
51 return HISTOGRAM_PREFIX "PreMainMessageLoopStart";
52 case AWAKE_FROM_NIB:
53 return HISTOGRAM_PREFIX "AwakeFromNib";
54 case POST_MAIN_MESSAGE_LOOP_START:
55 return HISTOGRAM_PREFIX "PostMainMessageLoopStart";
56 case PRE_PROFILE_INIT:
57 return HISTOGRAM_PREFIX "PreProfileInit";
58 case POST_PROFILE_INIT:
59 return HISTOGRAM_PREFIX "PostProfileInit";
60 case WILL_FINISH_LAUNCHING:
61 return HISTOGRAM_PREFIX "WillFinishLaunching";
62 case DID_FINISH_LAUNCHING:
63 return HISTOGRAM_PREFIX "DidFinishLaunching";
64 }
65 #undef HISTOGRAM_PREFIX
66 }
67
68 void MacStartupProfiler::RecordHistogram(Location location,
69 const base::TimeDelta& delta) {
70 const char* name = HistogramName(location);
71 base::TimeDelta min = base::TimeDelta::FromMilliseconds(10);
72 base::TimeDelta max = base::TimeDelta::FromMinutes(1);
73 int buckets = 100;
Ilya Sherman 2014/07/15 18:14:24 Are you sure that the parameters for, say, UMA_HIS
erikchen 2014/07/15 21:39:42 This is no longer relevant, since I'm not using a
74
75 // The UMA_HISTOGRAM_CUSTOM_TIMES macro requires a separate declaration for
76 // each different name.
Ilya Sherman 2014/07/15 18:14:24 Given that you do this below, why not just inline
erikchen 2014/07/15 21:39:42 inlining HistogramName() does not actually work (t
Ilya Sherman 2014/07/15 22:41:59 FWIW, by inlining HistogramName(), I meant not hav
77 switch (location) {
78 case PRE_MAIN_MESSAGE_LOOP_START:
79 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
80 return;
81 case AWAKE_FROM_NIB:
82 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
83 return;
84 case POST_MAIN_MESSAGE_LOOP_START:
85 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
86 return;
87 case PRE_PROFILE_INIT:
88 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
89 return;
90 case POST_PROFILE_INIT:
91 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
92 return;
93 case WILL_FINISH_LAUNCHING:
94 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
95 return;
96 case DID_FINISH_LAUNCHING:
97 UMA_HISTOGRAM_CUSTOM_TIMES(name, delta, min, max, buckets);
98 return;
99 }
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698