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

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: Comments from jeremy. 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 #include "components/startup_metric_utils/startup_metric_utils.h"
10
11 // static
12 MacStartupProfiler* MacStartupProfiler::GetInstance() {
13 return Singleton<MacStartupProfiler>::get();
14 }
15
16 MacStartupProfiler::MacStartupProfiler() : recorded_metrics_(false) {
17 }
18
19 MacStartupProfiler::~MacStartupProfiler() {
20 }
21
22 void MacStartupProfiler::Profile(Location location) {
23 profiled_times_[location] = base::Time::Now();
24 }
25
26 void MacStartupProfiler::RecordMetrics() {
27 const base::Time* launch_time = startup_metric_utils::MainEntryPointTime();
jeremy 2014/07/17 20:58:02 nit: launch_time -> main_entry_time or somesuch
erikchen 2014/07/17 21:05:03 I used your suggestion of main_entry_time.
28 DCHECK(launch_time);
29 DCHECK(!recorded_metrics_);
30
31 recorded_metrics_ = true;
32
33 for (std::map<Location, base::Time>::const_iterator it =
34 profiled_times_.begin();
35 it != profiled_times_.end();
36 ++it) {
37 const base::Time& location_time = it->second;
38 base::TimeDelta delta = location_time - *launch_time;
39 RecordHistogram(it->first, delta);
40 }
41 }
42
43 const std::string MacStartupProfiler::HistogramName(Location location) {
44 std::string prefix("Startup.OSX.");
45 switch (location) {
46 case PRE_MAIN_MESSAGE_LOOP_START:
47 return prefix + "PreMainMessageLoopStart";
48 case AWAKE_FROM_NIB:
49 return prefix + "AwakeFromNib";
50 case POST_MAIN_MESSAGE_LOOP_START:
51 return prefix + "PostMainMessageLoopStart";
52 case PRE_PROFILE_INIT:
53 return prefix + "PreProfileInit";
54 case POST_PROFILE_INIT:
55 return prefix + "PostProfileInit";
56 case WILL_FINISH_LAUNCHING:
57 return prefix + "WillFinishLaunching";
58 case DID_FINISH_LAUNCHING:
59 return prefix + "DockIconWillFinishBouncing";
60 }
61 }
62
63 void MacStartupProfiler::RecordHistogram(Location location,
64 const base::TimeDelta& delta) {
65 const std::string name(HistogramName(location));
66 base::TimeDelta min = base::TimeDelta::FromMilliseconds(10);
67 base::TimeDelta max = base::TimeDelta::FromMinutes(1);
68 int bucket_count = 100;
69
70 // No need to cache the histogram pointers, since each invocation of this
71 // method will be the first and only usage of a histogram with that given
72 // name.
73 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
74 name,
75 min,
76 max,
77 bucket_count,
78 base::HistogramBase::kUmaTargetedHistogramFlag);
79 histogram->AddTime(delta);
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698