Chromium Code Reviews| 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(); | |
| 41 | |
| 42 // Saves the current time for later processing. | |
| 43 void Profile(Location location); | |
| 44 | |
| 45 // Records UMA metrics from all profiled locations. | |
| 46 void RecordMetrics(); | |
| 47 | |
| 48 private: | |
| 49 friend struct DefaultSingletonTraits<MacStartupProfiler>; | |
| 50 | |
| 51 // Returns the name of the histogram for the given location. | |
| 52 const char* HistogramName(Location location); | |
| 53 | |
| 54 // Records UMA metrics for a specific location. | |
| 55 void RecordHistogram(Location location, const base::TimeDelta& delta); | |
| 56 | |
| 57 std::map<Location, base::Time> map_; | |
|
Ilya Sherman
2014/07/15 18:14:24
nit: Please give this a more descriptive name, e.g
erikchen
2014/07/15 21:39:42
Done.
| |
| 58 bool recorded_metrics_; | |
| 59 base::Time launch_time_; | |
| 60 bool launch_time_valid_; | |
|
Ilya Sherman
2014/07/15 18:14:24
nit: Can you omit launch_time_valid_, and just che
Ilya Sherman
2014/07/15 18:14:24
nit: Please document all of the member variables.
erikchen
2014/07/15 21:39:42
yes, done
erikchen
2014/07/15 21:39:42
Done.
| |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(MacStartupProfiler); | |
| 63 }; | |
| 64 | |
| 65 #endif // CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ | |
| OLD | NEW |