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