summaryrefslogtreecommitdiffstats
path: root/base/process_util_unittest.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-19 01:57:39 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-19 01:57:39 +0000
commitd2ed2383f5820e1fc26c9ac709b00bc8cdc8d086 (patch)
tree361278c499794f39d2b5c3c218fc59a7a98f7016 /base/process_util_unittest.cc
parentc2788ecbcd5c443fb129f63b7b86f83e944b4950 (diff)
downloadchromium_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_unittest.cc')
-rw-r--r--base/process_util_unittest.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index b75bdb8..40e303c 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -276,6 +276,26 @@ TEST_F(ProcessUtilTest, GetParentProcessId) {
base::ProcessId ppid = GetParentProcessId(GetCurrentProcId());
EXPECT_EQ(ppid, getppid());
}
+
+TEST_F(ProcessUtilTest, ParseProcStatCPU) {
+ // /proc/self/stat for a process running "top".
+ const char kTopStat[] = "960 (top) S 16230 960 16230 34818 960 "
+ "4202496 471 0 0 0 "
+ "12 16 0 0 " // <- These are the goods.
+ "20 0 1 0 121946157 15077376 314 18446744073709551615 4194304 "
+ "4246868 140733983044336 18446744073709551615 140244213071219 "
+ "0 0 0 138047495 0 0 0 17 1 0 0 0 0 0";
+ EXPECT_EQ(12 + 16, ParseProcStatCPU(kTopStat));
+
+ // cat /proc/self/stat on a random other machine I have.
+ const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 "
+ "0 142 0 0 0 "
+ "0 0 0 0 " // <- No CPU, apparently.
+ "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 "
+ "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0";
+
+ EXPECT_EQ(0, ParseProcStatCPU(kSelfStat));
+}
#endif
#endif // defined(OS_POSIX)