diff options
author | Gabriel Charette <gab@chromium.org> | 2016-02-03 19:45:52 -0500 |
---|---|---|
committer | Gabriel Charette <gab@chromium.org> | 2016-02-04 01:08:41 +0000 |
commit | d76590e3f0096e1ddb59b518abde53d0cda8d5a0 (patch) | |
tree | 676e8f05767e4997dbed68871f8f005eceaf3190 | |
parent | ab8c39fdc4c33a58d6fdf1dac9bb658faeb5ec28 (diff) | |
download | chromium_src-d76590e3f0096e1ddb59b518abde53d0cda8d5a0.zip chromium_src-d76590e3f0096e1ddb59b518abde53d0cda8d5a0.tar.gz chromium_src-d76590e3f0096e1ddb59b518abde53d0cda8d5a0.tar.bz2 |
[Merge M48] Add Startup.TimeSinceLastStartup histogram.
This histogram shows the time between 2 consecutive startups.
BUG=547794
Review URL: https://codereview.chromium.org/1558203003
Cr-Commit-Position: refs/heads/master@{#368354}
(cherry picked from commit 44cd7819dc6be0e640b6a1e03964d61210415a12)
Conflicts:
components/startup_metric_utils.gypi
components/startup_metric_utils/browser/BUILD.gn
components/startup_metric_utils/browser/startup_metric_utils.cc
components/startup_metric_utils/browser/startup_metric_utils.h
tools/metrics/histograms/histograms.xml
R=fdoray@chromium.org
TBR=fdoray@chromium.org
Review URL: https://codereview.chromium.org/1667903003 .
Cr-Commit-Position: refs/branch-heads/2564@{#664}
Cr-Branched-From: 1283eca15bd9f772387f75241576cde7bdec7f54-refs/heads/master@{#359700}
-rw-r--r-- | chrome/browser/chrome_browser_main.cc | 3 | ||||
-rw-r--r-- | chrome/browser/prefs/browser_prefs.cc | 2 | ||||
-rw-r--r-- | components/startup_metric_utils.gypi | 1 | ||||
-rw-r--r-- | components/startup_metric_utils/browser/BUILD.gn | 1 | ||||
-rw-r--r-- | components/startup_metric_utils/browser/startup_metric_utils.cc | 47 | ||||
-rw-r--r-- | components/startup_metric_utils/browser/startup_metric_utils.h | 13 | ||||
-rw-r--r-- | tools/metrics/histograms/histograms.xml | 9 |
7 files changed, 76 insertions, 0 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index 920bb2c..daed827 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -769,6 +769,9 @@ void ChromeBrowserMainParts::RecordBrowserStartupTime() { // Record collected startup metrics. startup_metric_utils::RecordBrowserMainMessageLoopStart( base::TimeTicks::Now(), is_first_run); + + startup_metric_utils::RecordTimeSinceLastStartup( + g_browser_process->local_state()); } // ----------------------------------------------------------------------------- diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 5fe77e7c..d8b8465 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -81,6 +81,7 @@ #include "components/rappor/rappor_service.h" #include "components/search_engines/template_url_prepopulate_data.h" #include "components/ssl_config/ssl_config_service_manager.h" +#include "components/startup_metric_utils/browser/startup_metric_utils.h" #include "components/sync_driver/sync_prefs.h" #include "components/syncable_prefs/pref_service_syncable.h" #include "components/translate/core/browser/translate_prefs.h" @@ -262,6 +263,7 @@ void RegisterLocalState(PrefRegistrySimple* registry) { RegisterScreenshotPrefs(registry); SigninManagerFactory::RegisterPrefs(registry); ssl_config::SSLConfigServiceManager::RegisterPrefs(registry); + startup_metric_utils::RegisterPrefs(registry); web_resource::PromoResourceService::RegisterPrefs(registry); #if defined(ENABLE_AUTOFILL_DIALOG) diff --git a/components/startup_metric_utils.gypi b/components/startup_metric_utils.gypi index f70e7a0..ad01dbb 100644 --- a/components/startup_metric_utils.gypi +++ b/components/startup_metric_utils.gypi @@ -9,6 +9,7 @@ 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', + '../base/base.gyp:base_prefs', ], 'include_dirs': [ '..', diff --git a/components/startup_metric_utils/browser/BUILD.gn b/components/startup_metric_utils/browser/BUILD.gn index 258e210..dfcf1e5 100644 --- a/components/startup_metric_utils/browser/BUILD.gn +++ b/components/startup_metric_utils/browser/BUILD.gn @@ -10,5 +10,6 @@ source_set("browser") { deps = [ "//base", + "//base:prefs", ] } diff --git a/components/startup_metric_utils/browser/startup_metric_utils.cc b/components/startup_metric_utils/browser/startup_metric_utils.cc index b1d413f..c83dc1a 100644 --- a/components/startup_metric_utils/browser/startup_metric_utils.cc +++ b/components/startup_metric_utils/browser/startup_metric_utils.cc @@ -9,6 +9,9 @@ #include "base/lazy_instance.h" #include "base/logging.h" #include "base/metrics/histogram_macros.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service.h" +#include "base/process/process_info.h" #include "base/strings/string_number_conversions.h" #include "base/sys_info.h" #include "base/threading/platform_thread.h" @@ -23,6 +26,9 @@ namespace startup_metric_utils { namespace { +const char kLastStartupTimestampPref[] = + "startup_metric.last_startup_timestamp"; + // Mark as volatile to defensively make sure usage is thread-safe. // Note that at the time of this writing, access is only on the UI thread. volatile bool g_non_browser_ui_displayed = false; @@ -159,6 +165,9 @@ bool GetHardFaultCountForCurrentProcess(uint32_t* hard_fault_count, #endif // defined(OS_WIN) +#define UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE(name, sample) \ + UMA_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, \ + base::TimeDelta::FromDays(30).InMinutes(), 50) // Helper macro for splitting out an UMA histogram based on cold or warm start. // |type| is the histogram type, and corresponds to an UMA macro like @@ -378,6 +387,11 @@ base::TimeTicks ExeMainEntryPointTicks() { } // namespace +void RegisterPrefs(PrefRegistrySimple* registry) { + DCHECK(registry); + registry->RegisterInt64Pref(kLastStartupTimestampPref, 0); +} + bool WasNonBrowserUIDisplayed() { return g_non_browser_ui_displayed; } @@ -472,6 +486,39 @@ void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, } } +void RecordTimeSinceLastStartup(PrefService* pref_service) { +#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) + DCHECK(pref_service); + + // Get the timestamp of the current startup. + const base::Time process_start_time = + base::CurrentProcessInfo::CreationTime(); + + // Get the timestamp of the last startup from |pref_service|. + const int64_t last_startup_timestamp_internal = + pref_service->GetInt64(kLastStartupTimestampPref); + if (last_startup_timestamp_internal != 0) { + // Log the Startup.TimeSinceLastStartup histogram. + const base::Time last_startup_timestamp = + base::Time::FromInternalValue(last_startup_timestamp_internal); + const base::TimeDelta time_since_last_startup = + process_start_time - last_startup_timestamp; + const int minutes_since_last_startup = time_since_last_startup.InMinutes(); + + // Ignore negative values, which can be caused by system clock changes. + if (minutes_since_last_startup >= 0) { + UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( + UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE, + "Startup.TimeSinceLastStartup", minutes_since_last_startup); + } + } + + // Write the timestamp of the current startup in |pref_service|. + pref_service->SetInt64(kLastStartupTimestampPref, + process_start_time.ToInternalValue()); +#endif // defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) +} + void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { static bool is_first_call = true; if (!is_first_call || ticks.is_null()) diff --git a/components/startup_metric_utils/browser/startup_metric_utils.h b/components/startup_metric_utils/browser/startup_metric_utils.h index c0391ff..fde9f36 100644 --- a/components/startup_metric_utils/browser/startup_metric_utils.h +++ b/components/startup_metric_utils/browser/startup_metric_utils.h @@ -9,6 +9,9 @@ #include "base/time/time.h" +class PrefRegistrySimple; +class PrefService; + // Utility functions to support metric collection for browser startup. Timings // should use TimeTicks whenever possible. OS-provided timings are still // received as Time out of cross-platform support necessity but are converted to @@ -36,6 +39,9 @@ enum StartupTemperature { UNDETERMINED_STARTUP_TEMPERATURE }; +// Registers startup related prefs in |registry|. +void RegisterPrefs(PrefRegistrySimple* registry); + // Returns true if any UI other than the browser window has been displayed // so far. Useful to test if UI has been displayed before the first browser // window was shown, which would invalidate any surrounding timing metrics. @@ -68,6 +74,13 @@ void RecordExeMainEntryPointTime(const base::Time& time); void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, bool is_first_run); +// Logs the Startup.TimeSinceLastStartup histogram. Obtains the timestamp of the +// last startup from |pref_service| and overwrites it with the timestamp of the +// current startup. If the startup temperature has been set by +// RecordBrowserMainMessageLoopStart, the time since last startup is also logged +// to an histogram suffixed with the startup temperature. +void RecordTimeSinceLastStartup(PrefService* pref_service); + // Call this with the time when the first browser window became visible. void RecordBrowserWindowDisplay(const base::TimeTicks& ticks); diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 75fd853..f3f225d 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -45799,6 +45799,14 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. </summary> </histogram> +<histogram name="Startup.TimeSinceLastStartup" units="minutes"> + <owner>fdoray@chromium.org</owner> + <summary> + Time elapsed since the last startup that went up to the main message loop + start. This is recorded just before the main message loop starts. + </summary> +</histogram> + <histogram name="Startup.WarmStartTimeFromRemoteProcessStart" units="milliseconds"> <owner>jeremy@chromium.org</owner> @@ -82290,6 +82298,7 @@ To add a new entry, add it with any value and run test to compute valid value. <affected-histogram name="Startup.LoadTime.ProcessCreateToDllMain"/> <affected-histogram name="Startup.LoadTime.ProcessCreateToExeMain"/> <affected-histogram name="Startup.SystemUptime"/> + <affected-histogram name="Startup.TimeSinceLastStartup"/> </histogram_suffixes> <histogram_suffixes name="StartupTimeBombAlarm" separator="."> |