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

Unified Diff: base/process/process_metrics_win.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_openbsd.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_win.cc
diff --git a/base/process/process_metrics_win.cc b/base/process/process_metrics_win.cc
index 0dd19cbbf31350c4870b3cf1bcebe4d1bca35413..b1810b4c92134e2827998e61965c4266ad912cc0 100644
--- a/base/process/process_metrics_win.cc
+++ b/base/process/process_metrics_win.cc
@@ -195,14 +195,11 @@ static uint64 FileTimeToUTC(const FILETIME& ftime) {
}
double ProcessMetrics::GetCPUUsage() {
- FILETIME now;
FILETIME creation_time;
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
- GetSystemTimeAsFileTime(&now);
-
if (!GetProcessTimes(process_, &creation_time, &exit_time,
&kernel_time, &user_time)) {
// We don't assert here because in some cases (such as in the Task Manager)
@@ -212,9 +209,9 @@ double ProcessMetrics::GetCPUUsage() {
}
int64 system_time = (FileTimeToUTC(kernel_time) + FileTimeToUTC(user_time)) /
processor_count_;
- int64 time = FileTimeToUTC(now);
+ TimeTicks time = TimeTicks::Now();
- if ((last_system_time_ == 0) || (last_cpu_time_ == 0)) {
+ if (last_system_time_ == 0) {
// First call, just set the last values.
last_system_time_ = system_time;
last_cpu_time_ = time;
@@ -222,7 +219,8 @@ double ProcessMetrics::GetCPUUsage() {
}
int64 system_time_delta = system_time - last_system_time_;
- int64 time_delta = time - last_cpu_time_;
+ // FILETIME is in 100-nanosecond units, so this needs microseconds times 10.
+ int64 time_delta = (time - last_cpu_time_).InMicroseconds() * 10;
DCHECK_NE(0U, time_delta);
if (time_delta == 0)
return 0;
@@ -269,7 +267,6 @@ bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
ProcessMetrics::ProcessMetrics(ProcessHandle process)
: process_(process),
processor_count_(base::SysInfo::NumberOfProcessors()),
- last_cpu_time_(0),
last_system_time_(0) {
}
« no previous file with comments | « base/process/process_metrics_openbsd.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698