Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / mac / mac_startup_profiler.h
blob05dcf6cc245e77641153213318fcc7f2d39b5b5e
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 #ifndef CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_
6 #define CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_
8 #include <map>
10 #include "base/memory/singleton.h"
11 #include "base/time/time.h"
13 // A lightweight profiler of startup performance. Records UMA metrics for the
14 // time delta between Chrome's launch and major initialization phases.
15 class MacStartupProfiler {
16 public:
17 // Returns pointer to the singleton instance for the current process.
18 static MacStartupProfiler* GetInstance();
20 MacStartupProfiler();
21 ~MacStartupProfiler();
23 // These locations correspond to major phases of Chrome startup.
24 // Profiling of these locations should occur at the beginning of the method
25 // indicated by the enum name.
26 // The ordering of the enum matches the order in which the initialization
27 // phases are reached.
28 enum Location {
29 PRE_MAIN_MESSAGE_LOOP_START,
30 AWAKE_FROM_NIB,
31 POST_MAIN_MESSAGE_LOOP_START,
32 PRE_PROFILE_INIT,
33 POST_PROFILE_INIT,
34 WILL_FINISH_LAUNCHING,
35 DID_FINISH_LAUNCHING,
38 // Record timestamp for the given location event.
39 void Profile(Location location);
41 // Call once to record all UMA metrics for all profiled locations.
42 void RecordMetrics();
44 private:
45 friend struct base::DefaultSingletonTraits<MacStartupProfiler>;
47 // Returns the name of the histogram for the given location.
48 const std::string HistogramName(Location location);
50 // Records UMA metrics for a specific location.
51 void RecordHistogram(Location location, const base::TimeDelta& delta);
53 // Keeps track of the time at which each initialization phase was reached.
54 std::map<Location, base::Time> profiled_times_;
56 // Whether UMA metrics have been recorded. Only record UMA metrics once.
57 bool recorded_metrics_;
59 DISALLOW_COPY_AND_ASSIGN(MacStartupProfiler);
62 #endif // CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_