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

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

Issue 1425263003: Use TimeTicks as much as possible in startup_metric_utils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adapt mojo as well + nit Created 5 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/browser/mac/mac_startup_profiler.h" 5 #include "chrome/browser/mac/mac_startup_profiler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 9 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
10 10
11 // static 11 // static
12 MacStartupProfiler* MacStartupProfiler::GetInstance() { 12 MacStartupProfiler* MacStartupProfiler::GetInstance() {
13 return base::Singleton<MacStartupProfiler>::get(); 13 return base::Singleton<MacStartupProfiler>::get();
14 } 14 }
15 15
16 MacStartupProfiler::MacStartupProfiler() : recorded_metrics_(false) { 16 MacStartupProfiler::MacStartupProfiler() : recorded_metrics_(false) {
17 } 17 }
18 18
19 MacStartupProfiler::~MacStartupProfiler() { 19 MacStartupProfiler::~MacStartupProfiler() {
20 } 20 }
21 21
22 void MacStartupProfiler::Profile(Location location) { 22 void MacStartupProfiler::Profile(Location location) {
23 profiled_times_[location] = base::Time::Now(); 23 profiled_ticks_[location] = base::TimeTicks::Now();
24 } 24 }
25 25
26 void MacStartupProfiler::RecordMetrics() { 26 void MacStartupProfiler::RecordMetrics() {
27 const base::Time main_entry_time = startup_metric_utils::MainEntryPointTime(); 27 const base::TimeTicks main_entry_ticks =
28 DCHECK(!main_entry_time.is_null()); 28 startup_metric_utils::MainEntryPointTicks();
29 DCHECK(!main_entry_ticks.is_null());
29 DCHECK(!recorded_metrics_); 30 DCHECK(!recorded_metrics_);
30 31
31 recorded_metrics_ = true; 32 recorded_metrics_ = true;
32 33
33 for (std::map<Location, base::Time>::const_iterator it = 34 for (const auto& entry : profiled_ticks_) {
34 profiled_times_.begin(); 35 const Location location = entry.first;
msw 2015/11/10 18:58:37 nit: could this also be a const ref? (or inline [b
gab 2015/11/10 19:18:49 It's an enum, refs for enums don't make much sense
35 it != profiled_times_.end(); 36 const base::TimeTicks& location_ticks = entry.second;
36 ++it) { 37 RecordHistogram(location, location_ticks - main_entry_ticks);
37 const base::Time& location_time = it->second;
38 base::TimeDelta delta = location_time - main_entry_time;
39 RecordHistogram(it->first, delta);
40 } 38 }
41 } 39 }
42 40
43 const std::string MacStartupProfiler::HistogramName(Location location) { 41 const std::string MacStartupProfiler::HistogramName(Location location) {
44 std::string prefix("Startup.OSX."); 42 std::string prefix("Startup.OSX.");
45 switch (location) { 43 switch (location) {
46 case PRE_MAIN_MESSAGE_LOOP_START: 44 case PRE_MAIN_MESSAGE_LOOP_START:
47 return prefix + "PreMainMessageLoopStart"; 45 return prefix + "PreMainMessageLoopStart";
48 case AWAKE_FROM_NIB: 46 case AWAKE_FROM_NIB:
49 return prefix + "AwakeFromNib"; 47 return prefix + "AwakeFromNib";
(...skipping 21 matching lines...) Expand all
71 // method will be the first and only usage of a histogram with that given 69 // method will be the first and only usage of a histogram with that given
72 // name. 70 // name.
73 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( 71 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
74 name, 72 name,
75 min, 73 min,
76 max, 74 max,
77 bucket_count, 75 bucket_count,
78 base::HistogramBase::kUmaTargetedHistogramFlag); 76 base::HistogramBase::kUmaTargetedHistogramFlag);
79 histogram->AddTime(delta); 77 histogram->AddTime(delta);
80 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698