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

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: Send histogram to UMA. 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();
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 Startup.OSX so this is clustered together with oth
erikchen 2014/07/17 18:14:06 Done.
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;
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,
78 min,
79 max,
80 bucket_count,
81 base::HistogramBase::kUmaTargetedHistogramFlag);
82 histogram->AddTime(delta);
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698