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

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 isherman, round 2. 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() : recorded_metrics_(false) {
16 }
17
18 MacStartupProfiler::~MacStartupProfiler() {
19 }
20
21 void MacStartupProfiler::RecordLaunchTime() {
22 launch_time_ = base::Time::Now();
jeremy 2014/07/17 11:10:18 startup_metric_utils also captures the process sta
23 }
24
25 void MacStartupProfiler::Profile(Location location) {
26 DCHECK(!launch_time_.is_null());
27 profiled_times_[location] = base::Time::Now();
28 }
29
30 void MacStartupProfiler::RecordMetrics() {
31 DCHECK(!launch_time_.is_null());
32 DCHECK(!recorded_metrics_);
33
34 recorded_metrics_ = true;
35
36 for (std::map<Location, base::Time>::const_iterator it =
37 profiled_times_.begin();
38 it != profiled_times_.end();
39 ++it) {
40 const base::Time& location_time = it->second;
41 base::TimeDelta delta = location_time - launch_time_;
42 RecordHistogram(it->first, delta);
43 }
44 }
45
46 const std::string MacStartupProfiler::HistogramName(Location location) {
47 std::string prefix("OSX.Startup.");
jeremy 2014/07/17 11:10:18 Any reason not to call these Startup.OSX so that t
48 switch (location) {
49 case PRE_MAIN_MESSAGE_LOOP_START:
50 return prefix + "PreMainMessageLoopStart";
51 case AWAKE_FROM_NIB:
52 return prefix + "AwakeFromNib";
53 case POST_MAIN_MESSAGE_LOOP_START:
54 return prefix + "PostMainMessageLoopStart";
55 case PRE_PROFILE_INIT:
56 return prefix + "PreProfileInit";
57 case POST_PROFILE_INIT:
58 return prefix + "PostProfileInit";
59 case WILL_FINISH_LAUNCHING:
60 return prefix + "WillFinishLaunching";
61 case DID_FINISH_LAUNCHING:
62 return prefix + "DidFinishLaunching";
63 }
64 }
65
66 void MacStartupProfiler::RecordHistogram(Location location,
67 const base::TimeDelta& delta) {
68 const std::string name(HistogramName(location));
69 base::TimeDelta min = base::TimeDelta::FromMilliseconds(10);
70 base::TimeDelta max = base::TimeDelta::FromMinutes(1);
71 int bucket_count = 100;
jeremy 2014/07/16 08:19:24 The histogram times/bucket count were a big issue
erikchen 2014/07/16 22:00:33 I prefer to restrict my histogram ranges to the va
jeremy 2014/07/17 11:10:18 On an IO bound machine you may see some of these t
72
73 // No need to cache the histogram pointers, since each invocation of this
74 // method will be the first and only usage of a histogram with that given
75 // name.
76 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
77 name, min, max, bucket_count, base::HistogramBase::kNoFlags);
jeremy 2014/07/16 08:19:23 This is just a local histogram and doesn't go to U
erikchen 2014/07/16 22:00:33 That is not correct. These metrics are going to UM
Ilya Sherman 2014/07/16 22:02:40 Jeremy noticed something important that I didn't:
erikchen 2014/07/16 22:12:18 Ah, I see. I've fixed this.
Ilya Sherman 2014/07/16 22:14:21 Thanks, LG.
78 histogram->AddTime(delta);
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698