| Index: base/process/process_metrics_unittest.cc
|
| diff --git a/base/process/process_metrics_unittest.cc b/base/process/process_metrics_unittest.cc
|
| index 69f5e837cb98bd0986d431b2bbc44d2b4c4a7744..270986f2409704ba3a98ba5db61ea22bd9dfeb26 100644
|
| --- a/base/process/process_metrics_unittest.cc
|
| +++ b/base/process/process_metrics_unittest.cc
|
| @@ -323,6 +323,47 @@ TEST(ProcessMetricsTest, ParseProcStatCPU) {
|
| "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0";
|
|
|
| EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat));
|
| +
|
| + // Some weird long-running process with a weird name that I created for the
|
| + // purposes of this test.
|
| + const char kWeirdNameStat[] = "26115 (Hello) You ())) ) R 24614 26115 24614"
|
| + " 34839 26115 4218880 227 0 0 0 "
|
| + "5186 11 0 0 "
|
| + "20 0 1 0 36933953 4296704 90 18446744073709551615 4194304 4196116 "
|
| + "140735857761568 140735857761160 4195644 0 0 0 0 0 0 0 17 14 0 0 0 0 0 "
|
| + "6295056 6295616 16519168 140735857770710 140735857770737 "
|
| + "140735857770737 140735857774557 0";
|
| + EXPECT_EQ(5186 + 11, base::ParseProcStatCPU(kWeirdNameStat));
|
| +}
|
| +
|
| +TEST(ProcessMetricsTest, GetCpuFromProcStats) {
|
| + // /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, base::GetCpuFromProcStats(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, base::GetCpuFromProcStats(kSelfStat));
|
| +
|
| + // Some weird long-running process with a weird name that I created for the
|
| + // purposes of this test.
|
| + const char kWeirdNameStat[] = "26115 (Hello) You ())) ) R 24614 26115 24614"
|
| + " 34839 26115 4218880 227 0 0 0 "
|
| + "5186 11 0 0 "
|
| + "20 0 1 0 36933953 4296704 90 18446744073709551615 4194304 4196116 "
|
| + "140735857761568 140735857761160 4195644 0 0 0 0 0 0 0 17 14 0 0 0 0 0 "
|
| + "6295056 6295616 16519168 140735857770710 140735857770737 "
|
| + "140735857770737 140735857774557 0";
|
| + EXPECT_EQ(5186 + 11, base::GetCpuFromProcStats(kWeirdNameStat));
|
| }
|
| #endif // defined(OS_LINUX) || defined(OS_ANDROID)
|
|
|
|
|