Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4900)

Unified Diff: chrome/browser/mac/mac_startup_profiler.h

Issue 393753002: mac: Add a profiler for startup time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d9513e81cdfede88e596d4269253e3574ed4482f
--- /dev/null
+++ b/chrome/browser/mac/mac_startup_profiler.h
@@ -0,0 +1,65 @@
+// 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 {
+ 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.
+ 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 char* HistogramName(Location location);
+
+ // Records UMA metrics for a specific location.
+ void RecordHistogram(Location location, const base::TimeDelta& delta);
+
+ 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.
+ bool recorded_metrics_;
+ base::Time launch_time_;
+ 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.
+
+ DISALLOW_COPY_AND_ASSIGN(MacStartupProfiler);
+};
+
+#endif // CHROME_BROWSER_MAC_MAC_STARTUP_PROFILER_H_

Powered by Google App Engine
This is Rietveld 408576698