Allow the minimum time between banner trigger visits to be varied via field trials.
[chromium-blink-merge.git] / chrome / browser / mac / mac_startup_profiler.cc
blob15580fbb6ef708f2ef8477d548c2e47cd19ef0da
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.
5 #include "chrome/browser/mac/mac_startup_profiler.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9 #include "components/startup_metric_utils/startup_metric_utils.h"
11 // static
12 MacStartupProfiler* MacStartupProfiler::GetInstance() {
13 return Singleton<MacStartupProfiler>::get();
16 MacStartupProfiler::MacStartupProfiler() : recorded_metrics_(false) {
19 MacStartupProfiler::~MacStartupProfiler() {
22 void MacStartupProfiler::Profile(Location location) {
23 profiled_times_[location] = base::Time::Now();
26 void MacStartupProfiler::RecordMetrics() {
27 const base::Time main_entry_time = startup_metric_utils::MainEntryPointTime();
28 DCHECK(!main_entry_time.is_null());
29 DCHECK(!recorded_metrics_);
31 recorded_metrics_ = true;
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 - main_entry_time;
39 RecordHistogram(it->first, delta);
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";
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;
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);