diff options
-rw-r--r-- | chrome/browser/metrics/metrics_log.cc | 26 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log.h | 4 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.cc | 31 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 5 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
5 files changed, 33 insertions, 34 deletions
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 37a6b7f..03dd925 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -5,6 +5,7 @@ #include "chrome/browser/metrics/metrics_log.h" #include "base/base64.h" +#include "base/time.h" #include "base/basictypes.h" #include "base/file_util.h" #include "base/file_version_info.h" @@ -329,6 +330,22 @@ int64 MetricsLog::GetBuildTime() { return integral_build_time; } +// static +int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { + base::TimeTicks now = base::TimeTicks::Now(); + static base::TimeTicks last_updated_time(now); + int64 incremental_time = (now - last_updated_time).InSeconds(); + last_updated_time = now; + + if (incremental_time > 0) { + int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); + metrics_uptime += incremental_time; + pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); + } + + return incremental_time; +} + std::string MetricsLog::GetInstallDate() const { PrefService* pref = g_browser_process->local_state(); if (pref) { @@ -394,11 +411,6 @@ void MetricsLog::WriteStabilityElement() { pref->GetInteger(prefs::kStabilityDebuggerNotPresent)); pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); - // Uptime is stored as a string, since there's no int64 in Value/JSON. - WriteAttribute("uptimesec", - WideToUTF8(pref->GetString(prefs::kStabilityUptimeSec))); - pref->SetString(prefs::kStabilityUptimeSec, L"0"); - WritePluginStabilityElements(pref); } @@ -486,6 +498,10 @@ void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { WriteIntAttribute("childprocesscrashcount", count); pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); } + + int64 recent_duration = GetIncrementalUptime(pref); + if (recent_duration) + WriteInt64Attribute("uptimesec", recent_duration); } void MetricsLog::WritePluginList( diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h index c1d5ff2..de17a36 100644 --- a/chrome/browser/metrics/metrics_log.h +++ b/chrome/browser/metrics/metrics_log.h @@ -112,6 +112,10 @@ class MetricsLog { // reliability stats, from other builds, can be abandoned. static int64 GetBuildTime(); + // Get the amount of uptime in seconds since this function was last called. + // This updates the cumulative uptime metric for uninstall as a side effect. + static int64 GetIncrementalUptime(PrefService* pref); + // Use |extension| in all uploaded appversions in addition to the standard // version string. static void set_version_extension(const std::string& extension) { diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 6b4ebbb..edd7cd9 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -318,7 +318,6 @@ void MetricsService::RegisterPrefs(PrefService* local_state) { local_state->RegisterInt64Pref(prefs::kMetricsClientIDTimestamp, 0); local_state->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); local_state->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); - local_state->RegisterInt64Pref(prefs::kStabilityUptimeSec, 0); local_state->RegisterStringPref(prefs::kStabilityStatsVersion, L""); local_state->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); @@ -377,9 +376,8 @@ void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); - local_state->SetString(prefs::kStabilityLaunchTimeSec, L"0"); - local_state->SetString(prefs::kStabilityLastTimestampSec, L"0"); - local_state->SetString(prefs::kStabilityUptimeSec, L"0"); + local_state->SetInt64(prefs::kStabilityLaunchTimeSec, 0); + local_state->SetInt64(prefs::kStabilityLastTimestampSec, 0); local_state->ClearPref(prefs::kStabilityPluginStats); @@ -697,25 +695,12 @@ void MetricsService::InitializeMetricsState() { pref->SetBoolean(prefs::kStabilitySessionEndCompleted, true); } - int64 last_start_time = pref->GetInt64(prefs::kStabilityLaunchTimeSec); - int64 last_end_time = pref->GetInt64(prefs::kStabilityLastTimestampSec); - int64 uptime = pref->GetInt64(prefs::kStabilityUptimeSec); - - // Same idea as uptime, except this one never gets reset and is used at - // uninstallation. - int64 uninstall_metrics_uptime = - pref->GetInt64(prefs::kUninstallMetricsUptimeSec); - - if (last_start_time && last_end_time) { - // TODO(JAR): Exclude sleep time. ... which must be gathered in UI loop. - int64 uptime_increment = last_end_time - last_start_time; - uptime += uptime_increment; - pref->SetInt64(prefs::kStabilityUptimeSec, uptime); - - uninstall_metrics_uptime += uptime_increment; - pref->SetInt64(prefs::kUninstallMetricsUptimeSec, - uninstall_metrics_uptime); - } + // Initialize uptime counters. + int64 startup_uptime = MetricsLog::GetIncrementalUptime(pref); + DCHECK(0 == startup_uptime); + // For backwards compatibility, leave this intact in case Omaha is checking + // them. prefs::kStabilityLastTimestampSec may also be useless now. + // TODO(jar): Delete these if they have no uses. pref->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); // Bookkeeping for the uninstall metrics. diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 3f464ab..70de4c7 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -435,11 +435,6 @@ const wchar_t kStabilityLaunchTimeSec[] = const wchar_t kStabilityLastTimestampSec[] = L"user_experience_metrics.stability.last_timestamp_sec"; -// Number of milliseconds that the main application process was up since -// the last report. -const wchar_t kStabilityUptimeSec[] = - L"user_experience_metrics.stability.uptime_sec"; - // This is the location of a list of dictionaries of plugin stability stats. const wchar_t kStabilityPluginStats[] = L"user_experience_metrics.stability.plugin_stats2"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index b0b1811..f8b49e1 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -155,7 +155,6 @@ extern const wchar_t kStabilityRendererCrashCount[]; extern const wchar_t kStabilityExtensionRendererCrashCount[]; extern const wchar_t kStabilityLaunchTimeSec[]; extern const wchar_t kStabilityLastTimestampSec[]; -extern const wchar_t kStabilityUptimeSec[]; extern const wchar_t kStabilityRendererHangCount[]; extern const wchar_t kStabilityChildProcessCrashCount[]; |