diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 01:57:39 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-19 01:57:39 +0000 |
commit | d2ed2383f5820e1fc26c9ac709b00bc8cdc8d086 (patch) | |
tree | 361278c499794f39d2b5c3c218fc59a7a98f7016 /base/process_util.h | |
parent | c2788ecbcd5c443fb129f63b7b86f83e944b4950 (diff) | |
download | chromium_src-d2ed2383f5820e1fc26c9ac709b00bc8cdc8d086.zip chromium_src-d2ed2383f5820e1fc26c9ac709b00bc8cdc8d086.tar.gz chromium_src-d2ed2383f5820e1fc26c9ac709b00bc8cdc8d086.tar.bz2 |
linux: implement GetCPUUsage() so the task manager shows CPU
Discussed in part here:
http://groups.google.com/group/chromium-dev/browse_thread/thread/8e91f66f9af6ccec
This implements option 3, which turned out to be pretty simple.
BUG=19864
Review URL: http://codereview.chromium.org/215020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26647 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util.h')
-rw-r--r-- | base/process_util.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/base/process_util.h b/base/process_util.h index 17ee3c7..89e6346 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -95,6 +95,11 @@ ProcessId GetParentProcessId(ProcessHandle process); // Returns the path to the executable of the given process. FilePath GetProcessExecutablePath(ProcessHandle process); + +// Parse the data found in /proc/<pid>/stat and return the sum of the +// CPU-related ticks. Returns -1 on parse error. +// Exposed for testing. +int ParseProcStatCPU(const std::string& input); #endif #if defined(OS_POSIX) @@ -329,6 +334,9 @@ struct FreeMBytes { void* largest_ptr; }; +// Convert a POSIX timeval to microseconds. +int64 TimeValToMicroseconds(const struct timeval& tv); + // Provides performance metrics for a specified process (CPU usage, memory and // IO counters). To use it, invoke CreateProcessMetrics() to get an instance // for a specific process, then access the information with the different get @@ -391,10 +399,16 @@ class ProcessMetrics { int processor_count_; - // Used to store the previous times so we can compute the CPU usage. + // Used to store the previous times and CPU usage counts so we can + // compute the CPU usage between calls. int64 last_time_; int64 last_system_time_; +#if defined(OS_LINUX) + // Jiffie count at the last_time_ we updated. + int last_cpu_; +#endif + DISALLOW_EVIL_CONSTRUCTORS(ProcessMetrics); }; |