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

Side by Side Diff: base/process/process_metrics_linux.cc

Issue 1160533002: Change outputting ints in win/linux GetCpuUsage to doubles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/process/process_metrics_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/process_metrics.h" 5 #include "base/process/process_metrics.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (time_delta == 0) 221 if (time_delta == 0)
222 return 0; 222 return 0;
223 223
224 int cpu = GetProcessCPU(process_); 224 int cpu = GetProcessCPU(process_);
225 225
226 // We have the number of jiffies in the time period. Convert to percentage. 226 // We have the number of jiffies in the time period. Convert to percentage.
227 // Note this means we will go *over* 100 in the case where multiple threads 227 // Note this means we will go *over* 100 in the case where multiple threads
228 // are together adding to more than one CPU's worth. 228 // are together adding to more than one CPU's worth.
229 TimeDelta cpu_time = internal::ClockTicksToTimeDelta(cpu); 229 TimeDelta cpu_time = internal::ClockTicksToTimeDelta(cpu);
230 TimeDelta last_cpu_time = internal::ClockTicksToTimeDelta(last_cpu_); 230 TimeDelta last_cpu_time = internal::ClockTicksToTimeDelta(last_cpu_);
231 int percentage = 100 * (cpu_time - last_cpu_time).InSecondsF() / 231 double percentage = 100.0 * (cpu_time - last_cpu_time).InSecondsF() /
232 TimeDelta::FromMicroseconds(time_delta).InSecondsF(); 232 TimeDelta::FromMicroseconds(time_delta).InSecondsF();
233 233
234 last_cpu_time_ = time; 234 last_cpu_time_ = time;
235 last_cpu_ = cpu; 235 last_cpu_ = cpu;
236 236
237 return percentage; 237 return percentage;
238 } 238 }
239 239
240 // To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING 240 // To have /proc/self/io file you must enable CONFIG_TASK_IO_ACCOUNTING
241 // in your kernel configuration. 241 // in your kernel configuration.
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 #if defined(OS_LINUX) 907 #if defined(OS_LINUX)
908 int ProcessMetrics::GetIdleWakeupsPerSecond() { 908 int ProcessMetrics::GetIdleWakeupsPerSecond() {
909 uint64 wake_ups; 909 uint64 wake_ups;
910 const char kWakeupStat[] = "se.statistics.nr_wakeups"; 910 const char kWakeupStat[] = "se.statistics.nr_wakeups";
911 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? 911 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ?
912 CalculateIdleWakeupsPerSecond(wake_ups) : 0; 912 CalculateIdleWakeupsPerSecond(wake_ups) : 0;
913 } 913 }
914 #endif // defined(OS_LINUX) 914 #endif // defined(OS_LINUX)
915 915
916 } // namespace base 916 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/process/process_metrics_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698