Chromium Code Reviews| Index: chrome/browser/mac/mac_startup_profiler.h |
| diff --git a/chrome/browser/mac/mac_startup_profiler.h b/chrome/browser/mac/mac_startup_profiler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6d60ab1dab6ac4cb10199b20636e6088b11530d6 |
| --- /dev/null |
| +++ b/chrome/browser/mac/mac_startup_profiler.h |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ |
| +#define CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/memory/singleton.h" |
| +#include "base/time/time.h" |
| + |
| +// A lightweight profiler of startup performance. Records UMA metrics for the |
| +// time delta between Chrome's launch and major initialization phases. |
| +class MacStartupProfiler { |
|
jeremy
2014/07/16 08:19:24
This seems to parallel the code in components/star
erikchen
2014/07/16 22:00:33
I like to only record histograms that are intended
|
| + public: |
| + // Returns pointer to the singleton instance for the current process. |
| + static MacStartupProfiler* GetInstance(); |
| + |
| + MacStartupProfiler(); |
| + ~MacStartupProfiler(); |
| + |
| + // These locations correspond to major phases of Chrome startup. |
| + // Profiling of these locations should occur at the beginning of the method |
| + // indicated by the enum name. |
| + // The ordering of the enum matches the order in which the initialization |
| + // phases are reached. |
| + enum Location { |
| + PRE_MAIN_MESSAGE_LOOP_START, |
| + AWAKE_FROM_NIB, |
| + POST_MAIN_MESSAGE_LOOP_START, |
| + PRE_PROFILE_INIT, |
| + POST_PROFILE_INIT, |
| + WILL_FINISH_LAUNCHING, |
| + DID_FINISH_LAUNCHING, |
| + }; |
| + |
| + // This method should be called at the earliest convenient time after Chrome |
| + // has launched. |
|
jeremy
2014/07/16 08:19:24
We currently record Startup.BrowserMessageLoopStar
erikchen
2014/07/16 22:00:33
Ah, that is good to know. Thanks!
|
| + void RecordLaunchTime(); |
| + |
| + // Saves the current time for later processing. |
| + void Profile(Location location); |
| + |
| + // Records UMA metrics from all profiled locations. |
| + void RecordMetrics(); |
| + |
| + private: |
| + friend struct DefaultSingletonTraits<MacStartupProfiler>; |
| + |
| + // Returns the name of the histogram for the given location. |
| + const std::string HistogramName(Location location); |
| + |
| + // Records UMA metrics for a specific location. |
| + void RecordHistogram(Location location, const base::TimeDelta& delta); |
| + |
| + // Keeps track of the time at which each initialization phase was reached. |
| + std::map<Location, base::Time> profiled_times_; |
| + |
| + // Whether UMA metrics have been recorded. Only record UMA metrics once. |
| + bool recorded_metrics_; |
| + |
| + // The time at which Chrome was launched. |
| + base::Time launch_time_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MacStartupProfiler); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_ |