Chromium Code Reviews| Index: components/startup_metric_utils/browser/startup_metric_utils.cc |
| diff --git a/components/startup_metric_utils/browser/startup_metric_utils.cc b/components/startup_metric_utils/browser/startup_metric_utils.cc |
| index 5bc42d09e42c99d294ad3bd0b6dcaabda0a259c1..6b43e1673301f980c2637faf18d4a74f1a87b793 100644 |
| --- a/components/startup_metric_utils/browser/startup_metric_utils.cc |
| +++ b/components/startup_metric_utils/browser/startup_metric_utils.cc |
| @@ -11,6 +11,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" |
| @@ -27,6 +30,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; |
| @@ -96,6 +102,9 @@ typedef NTSTATUS (WINAPI *NtQuerySystemInformationPtr)( |
| SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG); |
| #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(), 100) |
|
Alexei Svitkine (slow)
2016/01/05 20:21:14
Do you need 100 buckets? I think 50 should be suff
fdoray
2016/01/05 20:36:14
Done. I agree that 50 buckets is enough.
|
| // 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 |
| @@ -374,6 +383,11 @@ bool GetHardFaultCountForCurrentProcess(uint32_t* hard_fault_count) { |
| } |
| #endif // defined(OS_WIN) |
| +void RegisterPrefs(PrefRegistrySimple* registry) { |
| + DCHECK(registry); |
| + registry->RegisterInt64Pref(kLastStartupTimestampPref, 0); |
| +} |
| + |
| bool WasNonBrowserUIDisplayed() { |
| return g_non_browser_ui_displayed; |
| } |
| @@ -469,6 +483,32 @@ void RecordBrowserMainMessageLoopStart(const base::TimeTicks& ticks, |
| } |
| } |
| +void RecordTimeSinceLastStartup(PrefService* pref_service) { |
| + 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; |
|
Alexei Svitkine (slow)
2016/01/05 20:21:14
In certain cases, you may get a negative value her
fdoray
2016/01/05 20:36:14
Done. We cannot conclude anything from negative va
|
| + UMA_HISTOGRAM_WITH_STARTUP_TEMPERATURE( |
| + UMA_HISTOGRAM_TIME_IN_MINUTES_MONTH_RANGE, |
| + "Startup.TimeSinceLastStartup", time_since_last_startup.InMinutes()); |
| + } |
| + |
| + // Write the timestamp of the current startup in |pref_service|. |
| + pref_service->SetInt64(kLastStartupTimestampPref, |
| + process_start_time.ToInternalValue()); |
| +} |
| + |
| void RecordBrowserWindowDisplay(const base::TimeTicks& ticks) { |
| static bool is_first_call = true; |
| if (!is_first_call || ticks.is_null()) |