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

Unified Diff: base/process/process_metrics_linux.cc

Issue 21302005: Add CurrentProcessInfo::CreationTime() for Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac Created 7 years, 4 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_info_win.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_linux.cc
diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc
index 0171020f063cc68bfe78a281c0bfe56b7ab974af..1c86ee467c98f34e82b82b8d57de48f16cea45e9 100644
--- a/base/process/process_metrics_linux.cc
+++ b/base/process/process_metrics_linux.cc
@@ -167,16 +167,6 @@ bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const {
}
double ProcessMetrics::GetCPUUsage() {
- // This queries the /proc-specific scaling factor which is
- // conceptually the system hertz. To dump this value on another
- // system, try
- // od -t dL /proc/self/auxv
- // and look for the number after 17 in the output; mine is
- // 0000040 17 100 3 134512692
- // which means the answer is 100.
- // It may be the case that this value is always 100.
- static const int kHertz = sysconf(_SC_CLK_TCK);
-
struct timeval now;
int retval = gettimeofday(&now, NULL);
if (retval)
@@ -200,8 +190,10 @@ double ProcessMetrics::GetCPUUsage() {
// We have the number of jiffies in the time period. Convert to percentage.
// Note this means we will go *over* 100 in the case where multiple threads
// are together adding to more than one CPU's worth.
- int percentage = 100 * (cpu - last_cpu_) /
- (kHertz * TimeDelta::FromMicroseconds(time_delta).InSecondsF());
+ TimeDelta cpu_time = internal::ClockTicksToTimeDelta(cpu);
+ TimeDelta last_cpu_time = internal::ClockTicksToTimeDelta(last_cpu_);
+ int percentage = 100 * (cpu_time - last_cpu_time).InSecondsF() /
+ TimeDelta::FromMicroseconds(time_delta).InSecondsF();
last_time_ = time;
last_cpu_ = cpu;
« no previous file with comments | « base/process/process_info_win.cc ('k') | chrome/browser/chrome_browser_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698