OLD | NEW |
---|---|
(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 #ifndef CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ | |
6 #define CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/memory/singleton.h" | |
11 #include "base/time/time.h" | |
12 | |
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(); | |
19 | |
20 MacStartupProfiler(); | |
21 ~MacStartupProfiler(); | |
22 | |
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, | |
36 }; | |
37 | |
38 // This method should be called at the earliest convenient time after Chrome | |
39 // has launched. | |
40 void RecordLaunchTime(); | |
jeremy
2014/07/17 11:10:18
Can you remove this and instead use the timestamp
erikchen
2014/07/17 18:14:06
Done.
| |
41 | |
42 // Saves the current time for later processing. | |
jeremy
2014/07/17 11:10:18
nit: this comment isn't very clear, how about some
erikchen
2014/07/17 18:14:06
Used your suggested comment.
| |
43 void Profile(Location location); | |
44 | |
45 // Records UMA metrics from all profiled locations. | |
46 void RecordMetrics(); | |
jeremy
2014/07/17 11:10:18
nit:
// Call once to record all UMA metrics for al
erikchen
2014/07/17 18:14:06
Used your suggested comment.
| |
47 | |
48 private: | |
49 friend struct DefaultSingletonTraits<MacStartupProfiler>; | |
50 | |
51 // Returns the name of the histogram for the given location. | |
52 const std::string HistogramName(Location location); | |
53 | |
54 // Records UMA metrics for a specific location. | |
55 void RecordHistogram(Location location, const base::TimeDelta& delta); | |
56 | |
57 // Keeps track of the time at which each initialization phase was reached. | |
58 std::map<Location, base::Time> profiled_times_; | |
59 | |
60 // Whether UMA metrics have been recorded. Only record UMA metrics once. | |
61 bool recorded_metrics_; | |
62 | |
63 // The time at which Chrome was launched. | |
64 base::Time launch_time_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(MacStartupProfiler); | |
67 }; | |
68 | |
69 #endif // CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ | |
OLD | NEW |