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

Unified Diff: components/startup_metric_utils/browser/startup_metric_utils.cc

Issue 1667903003: [Merge M48] Add Startup.TimeSinceLastStartup histogram. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: Created 4 years, 11 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: 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 b1d413f0bfae0deb1422a4e384f6ff9ee67481a8..c83dc1a97dcae2a9ebdf30c98e9a4a8184e1f70a 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())
« no previous file with comments | « components/startup_metric_utils/browser/startup_metric_utils.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698