| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_ | 5 #ifndef COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_ |
| 6 #define COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_ | 6 #define COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 | 11 |
| 12 class PrefRegistrySimple; | 12 class PrefRegistrySimple; |
| 13 class PrefService; | 13 class PrefService; |
| 14 | 14 |
| 15 // Utility functions to support metric collection for browser startup. Timings | 15 // Utility functions to support metric collection for browser startup. Timings |
| 16 // should use TimeTicks whenever possible. OS-provided timings are still | 16 // should use TimeTicks whenever possible. OS-provided timings are still |
| 17 // received as Time out of cross-platform support necessity but are converted to | 17 // received as Time out of cross-platform support necessity but are converted to |
| 18 // TimeTicks as soon as possible in an attempt to reduce the potential skew | 18 // TimeTicks as soon as possible in an attempt to reduce the potential skew |
| 19 // between the two basis. See crbug.com/544131 for reasoning. | 19 // between the two basis. See crbug.com/544131 for reasoning. |
| 20 | 20 |
| 21 namespace startup_metric_utils { | 21 namespace startup_metric_utils { |
| 22 | 22 |
| 23 // An enumeration of startup temperatures. This must be kept in sync with the | 23 // An enumeration of startup temperatures. This must be kept in sync with the |
| 24 // UMA StartupType enumeration defined in histograms.xml. | 24 // UMA StartupType enumeration defined in histograms.xml. |
| 25 enum StartupTemperature { | 25 enum StartupTemperature { |
| 26 // The startup was a cold start: nearly all of the Chrome binaries and | 26 // The startup was a cold start: nearly all of the binaries and resources were |
| 27 // resources were brought into memory using hard faults. | 27 // brought into memory using hard faults. |
| 28 COLD_STARTUP_TEMPERATURE = 0, | 28 COLD_STARTUP_TEMPERATURE = 0, |
| 29 // The startup was a warm start: the Chrome binaries and resources were | 29 // The startup was a warm start: the binaries and resources were mostly |
| 30 // mostly already resident in memory and effectively no hard faults were | 30 // already resident in memory and effectively no hard faults were observed. |
| 31 // observed. | |
| 32 WARM_STARTUP_TEMPERATURE = 1, | 31 WARM_STARTUP_TEMPERATURE = 1, |
| 33 // The startup type couldn't quite be classified as warm or cold, but rather | 32 // The startup type couldn't quite be classified as warm or cold, but rather |
| 34 // was somewhere in between. | 33 // was somewhere in between. |
| 35 LUKEWARM_STARTUP_TEMPERATURE = 2, | 34 LUKEWARM_STARTUP_TEMPERATURE = 2, |
| 36 // This must be after all meaningful values. | 35 // This must be after all meaningful values. |
| 37 STARTUP_TEMPERATURE_COUNT, | 36 STARTUP_TEMPERATURE_COUNT, |
| 38 // Startup temperature wasn't yet determined. | 37 // Startup temperature wasn't yet determined. |
| 39 UNDETERMINED_STARTUP_TEMPERATURE | 38 UNDETERMINED_STARTUP_TEMPERATURE |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 // Registers startup related prefs in |registry|. | 41 // Registers startup related prefs in |registry|. |
| 43 void RegisterPrefs(PrefRegistrySimple* registry); | 42 void RegisterPrefs(PrefRegistrySimple* registry); |
| 44 | 43 |
| 45 // Returns true if any UI other than the browser window has been displayed | 44 // Returns true if any UI other than the browser window has been displayed |
| 46 // so far. Useful to test if UI has been displayed before the first browser | 45 // so far. Useful to test if UI has been displayed before the first browser |
| 47 // window was shown, which would invalidate any surrounding timing metrics. | 46 // window was shown, which would invalidate any surrounding timing metrics. |
| 48 bool WasNonBrowserUIDisplayed(); | 47 bool WasNonBrowserUIDisplayed(); |
| 49 | 48 |
| 50 // Call this when displaying UI that might potentially delay the appearance | 49 // Call this when displaying UI that might potentially delay startup events. |
| 51 // of the initial browser window on Chrome startup. | |
| 52 // | 50 // |
| 53 // Note on usage: This function is idempotent and its overhead is low enough | 51 // Note on usage: This function is idempotent and its overhead is low enough |
| 54 // in comparison with UI display that it's OK to call it on every | 52 // in comparison with UI display that it's OK to call it on every |
| 55 // UI invocation regardless of whether the browser window has already | 53 // UI invocation regardless of whether the browser window has already |
| 56 // been displayed or not. | 54 // been displayed or not. |
| 57 void SetNonBrowserUIDisplayed(); | 55 void SetNonBrowserUIDisplayed(); |
| 58 | 56 |
| 59 // Call this with the creation time of the startup (initial/main) process. | 57 // Call this with the creation time of the startup (initial/main) process. |
| 60 void RecordStartupProcessCreationTime(const base::Time& time); | 58 void RecordStartupProcessCreationTime(const base::Time& time); |
| 61 | 59 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, | 72 void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, |
| 75 bool is_first_run); | 73 bool is_first_run); |
| 76 | 74 |
| 77 // Logs the Startup.TimeSinceLastStartup histogram. Obtains the timestamp of the | 75 // Logs the Startup.TimeSinceLastStartup histogram. Obtains the timestamp of the |
| 78 // last startup from |pref_service| and overwrites it with the timestamp of the | 76 // last startup from |pref_service| and overwrites it with the timestamp of the |
| 79 // current startup. If the startup temperature has been set by | 77 // current startup. If the startup temperature has been set by |
| 80 // RecordBrowserMainMessageLoopStart, the time since last startup is also logged | 78 // RecordBrowserMainMessageLoopStart, the time since last startup is also logged |
| 81 // to an histogram suffixed with the startup temperature. | 79 // to an histogram suffixed with the startup temperature. |
| 82 void RecordTimeSinceLastStartup(PrefService* pref_service); | 80 void RecordTimeSinceLastStartup(PrefService* pref_service); |
| 83 | 81 |
| 82 // Logs the Startup.SameVersionStartupCount histogram. Relies on |pref_service| |
| 83 // to know information about the previous startups and store information for |
| 84 // future ones. |
| 85 void RecordStartupCount(PrefService* pref_service); |
| 86 |
| 84 // Call this with the time when the first browser window became visible. | 87 // Call this with the time when the first browser window became visible. |
| 85 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks); | 88 void RecordBrowserWindowDisplay(const base::TimeTicks& ticks); |
| 86 | 89 |
| 87 // Call this with the time delta that the browser spent opening its tabs. | 90 // Call this with the time delta that the browser spent opening its tabs. |
| 88 void RecordBrowserOpenTabsDelta(const base::TimeDelta& delta); | 91 void RecordBrowserOpenTabsDelta(const base::TimeDelta& delta); |
| 89 | 92 |
| 90 // Call this with the time when the first web contents loaded its main frame, | 93 // Call this with the time when the first web contents loaded its main frame, |
| 91 // only if the first web contents was unimpended in its attempt to do so. | 94 // only if the first web contents was unimpended in its attempt to do so. |
| 92 void RecordFirstWebContentsMainFrameLoad(const base::TimeTicks& ticks); | 95 void RecordFirstWebContentsMainFrameLoad(const base::TimeTicks& ticks); |
| 93 | 96 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 119 base::TimeTicks MainEntryPointTicks(); | 122 base::TimeTicks MainEntryPointTicks(); |
| 120 | 123 |
| 121 // Returns the startup type. This is only currently supported on the Windows | 124 // Returns the startup type. This is only currently supported on the Windows |
| 122 // platform and will simply return UNCERTAIN_STARTUP_TYPE on other platforms. | 125 // platform and will simply return UNCERTAIN_STARTUP_TYPE on other platforms. |
| 123 // This is only valid after a call to RecordBrowserMainMessageLoopStart(). | 126 // This is only valid after a call to RecordBrowserMainMessageLoopStart(). |
| 124 StartupTemperature GetStartupTemperature(); | 127 StartupTemperature GetStartupTemperature(); |
| 125 | 128 |
| 126 } // namespace startup_metric_utils | 129 } // namespace startup_metric_utils |
| 127 | 130 |
| 128 #endif // COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_ | 131 #endif // COMPONENTS_STARTUP_METRIC_UTILS_BROWSER_STARTUP_METRIC_UTILS_H_ |
| OLD | NEW |