summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 21:19:16 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-22 21:19:16 +0000
commitcffa814137f99b9b706bdd2e18578b3ebdc225e8 (patch)
treefb5e1f0de2827f5b366b1d252926331c72d8cd4a
parent6558d751afb9d2d205e6f8d4c40a7d7fb0e877db (diff)
downloadchromium_src-cffa814137f99b9b706bdd2e18578b3ebdc225e8.zip
chromium_src-cffa814137f99b9b706bdd2e18578b3ebdc225e8.tar.gz
chromium_src-cffa814137f99b9b706bdd2e18578b3ebdc225e8.tar.bz2
Merge 41216 - Switch to continuous reporting of uptime
Uptime was being reported only at startup, and then, for the previous session. This meant that folks with a long uptime would be very slow to report. This change moves the reporting to an incremental reporting, done as often as we report pageloads etc. (i.e., in each UMA upload). This also fixes several bugs relating to uptime calculation, by using TimeTicks (which show process time) rather than Time (which shows wall clock time, and is subject to corruption if the user changes the will clock time on the computer). It also resolves a bug that may have caused negative uptimes to be reported. BUG=37630 r=hunar Review URL: http://codereview.chromium.org/675001 TBR=jar@chromium.org Review URL: http://codereview.chromium.org/1146008 git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@42259 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/metrics/metrics_log.cc26
-rw-r--r--chrome/browser/metrics/metrics_log.h4
-rw-r--r--chrome/browser/metrics/metrics_service.cc31
-rw-r--r--chrome/common/pref_names.cc5
-rw-r--r--chrome/common/pref_names.h1
5 files changed, 33 insertions, 34 deletions
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 9e0ad2e..c3043a7 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/metrics/metrics_log.h"
+#include "base/time.h"
#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/file_version_info.h"
@@ -311,6 +312,22 @@ std::string MetricsLog::GetVersionString() {
return std::string();
}
+// 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) {
@@ -376,11 +393,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);
}
@@ -468,6 +480,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 69b6f62..647ebddc 100644
--- a/chrome/browser/metrics/metrics_log.h
+++ b/chrome/browser/metrics/metrics_log.h
@@ -106,6 +106,10 @@ class MetricsLog {
// Get the current version of the application as a string.
static std::string GetVersionString();
+ // 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);
+
protected:
// Returns a string containing the current time.
// Virtual so that it can be overridden for testing.
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 12bc07d..a5ebcc6 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -320,7 +320,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->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
local_state->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true);
@@ -378,9 +377,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);
@@ -694,25 +692,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 b23b892..aa2c2f1 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -410,11 +410,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 5eeb386..c6d1240 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -148,7 +148,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[];