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

Unified Diff: base/process/process_metrics_linux.cc

Issue 139103007: Use TimeTicks instead of gettimeofday in ProcessMetrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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: base/process/process_metrics_linux.cc
diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc
index f6ab819f5fc405f9788a75ad186172beec404e67..78a39c63eb6e4e705dba197161171614d30bfb02 100644
--- a/base/process/process_metrics_linux.cc
+++ b/base/process/process_metrics_linux.cc
@@ -181,20 +181,16 @@ bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
}
double ProcessMetrics::GetCPUUsage() {
- struct timeval now;
- int retval = gettimeofday(&now, NULL);
- if (retval)
- return 0;
- int64 time = TimeValToMicroseconds(now);
+ TimeTicks time = TimeTicks::Now();
- if (last_cpu_time_ == 0) {
+ if (last_cpu_ == 0) {
// First call, just set the last values.
- last_cpu_time_ = time;
+ last_cpu_walltime_ = time;
last_cpu_ = GetProcessCPU(process_);
return 0;
}
- int64 time_delta = time - last_cpu_time_;
+ int64 time_delta = (time - last_cpu_walltime_).InMicroseconds();
DCHECK_NE(time_delta, 0);
if (time_delta == 0)
return 0;
@@ -209,7 +205,7 @@ double ProcessMetrics::GetCPUUsage() {
int percentage = 100 * (cpu_time - last_cpu_time).InSecondsF() /
TimeDelta::FromMicroseconds(time_delta).InSecondsF();
- last_cpu_time_ = time;
+ last_cpu_walltime_ = time;
last_cpu_ = cpu;
return percentage;
@@ -262,7 +258,6 @@ bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
ProcessMetrics::ProcessMetrics(ProcessHandle process)
: process_(process),
- last_cpu_time_(0),
last_system_time_(0),
last_cpu_(0) {
processor_count_ = base::SysInfo::NumberOfProcessors();

Powered by Google App Engine
This is Rietveld 408576698