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

Unified Diff: base/process/process_metrics_mac.cc

Issue 139103007: Use TimeTicks instead of gettimeofday in ProcessMetrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reverty Created 6 years, 8 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
« no previous file with comments | « base/process/process_metrics_linux.cc ('k') | base/process/process_metrics_openbsd.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_mac.cc
diff --git a/base/process/process_metrics_mac.cc b/base/process/process_metrics_mac.cc
index 85668619782f7429bfa2e3fa06d734986e23f809..1b2e61bdb73886e23091d28d28970aaa2752a91a 100644
--- a/base/process/process_metrics_mac.cc
+++ b/base/process/process_metrics_mac.cc
@@ -267,15 +267,10 @@ double ProcessMetrics::GetCPUUsage() {
timeradd(&user_timeval, &task_timeval, &task_timeval);
timeradd(&system_timeval, &task_timeval, &task_timeval);
- struct timeval now;
- int retval = gettimeofday(&now, NULL);
- if (retval)
- return 0;
-
- int64 time = TimeValToMicroseconds(now);
+ TimeTicks time = TimeTicks::Now();
int64 task_time = TimeValToMicroseconds(task_timeval);
- if (last_cpu_time_ == 0) {
+ if (last_system_time_ == 0) {
// First call, just set the last values.
last_cpu_time_ = time;
last_system_time_ = task_time;
@@ -283,7 +278,7 @@ double ProcessMetrics::GetCPUUsage() {
}
int64 system_time_delta = task_time - last_system_time_;
- int64 time_delta = time - last_cpu_time_;
+ int64 time_delta = (time - last_cpu_time_).InMicroseconds();
DCHECK_NE(0U, time_delta);
if (time_delta == 0)
return 0;
@@ -314,14 +309,9 @@ int ProcessMetrics::GetIdleWakeupsPerSecond() {
}
uint64_t absolute_idle_wakeups = power_info_data.task_platform_idle_wakeups;
- struct timeval now;
- int retval = gettimeofday(&now, NULL);
- if (retval)
- return 0;
-
- int64 time = TimeValToMicroseconds(now);
+ TimeTicks time = TimeTicks::Now();
- if (last_idle_wakeups_time_ == 0) {
+ if (last_absolute_idle_wakeups_ == 0) {
// First call, just set the last values.
last_idle_wakeups_time_ = time;
last_absolute_idle_wakeups_ = absolute_idle_wakeups;
@@ -329,7 +319,7 @@ int ProcessMetrics::GetIdleWakeupsPerSecond() {
}
int64 wakeups_delta = absolute_idle_wakeups - last_absolute_idle_wakeups_;
- int64 time_delta = time - last_idle_wakeups_time_;
+ int64 time_delta = (time - last_idle_wakeups_time_).InMicroseconds();
DCHECK_NE(0U, time_delta);
if (time_delta == 0)
return 0;
@@ -349,9 +339,7 @@ bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
ProcessMetrics::ProcessMetrics(ProcessHandle process,
ProcessMetrics::PortProvider* port_provider)
: process_(process),
- last_cpu_time_(0),
last_system_time_(0),
- last_idle_wakeups_time_(0),
last_absolute_idle_wakeups_(0),
port_provider_(port_provider) {
processor_count_ = SysInfo::NumberOfProcessors();
« no previous file with comments | « base/process/process_metrics_linux.cc ('k') | base/process/process_metrics_openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698