OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <sstream> | 7 #include <sstream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 "pgrefill_movable 0\n"; | 261 "pgrefill_movable 0\n"; |
262 EXPECT_TRUE(ParseProcVmstat(valid_input1, &meminfo)); | 262 EXPECT_TRUE(ParseProcVmstat(valid_input1, &meminfo)); |
263 EXPECT_EQ(meminfo.pswpin, 179); | 263 EXPECT_EQ(meminfo.pswpin, 179); |
264 EXPECT_EQ(meminfo.pswpout, 406); | 264 EXPECT_EQ(meminfo.pswpout, 406); |
265 EXPECT_EQ(meminfo.pgmajfault, 487192); | 265 EXPECT_EQ(meminfo.pgmajfault, 487192); |
266 EXPECT_TRUE(ParseProcVmstat(valid_input2, &meminfo)); | 266 EXPECT_TRUE(ParseProcVmstat(valid_input2, &meminfo)); |
267 EXPECT_EQ(meminfo.pswpin, 12); | 267 EXPECT_EQ(meminfo.pswpin, 12); |
268 EXPECT_EQ(meminfo.pswpout, 901); | 268 EXPECT_EQ(meminfo.pswpout, 901); |
269 EXPECT_EQ(meminfo.pgmajfault, 2023); | 269 EXPECT_EQ(meminfo.pgmajfault, 2023); |
270 } | 270 } |
271 | |
272 TEST(ProcessMetricsTest, ParseProcStatusFile) { | |
273 std::string valid_status_contents = | |
Lei Zhang
2015/10/07 16:10:54
const char kValindStatusContents[]; // and you ca
ssid
2015/10/07 17:11:34
I just followed the pattern in the file to stay co
| |
274 "Name: bash\n" | |
275 "State: S (sleeping)\n" | |
276 "Tgid: 3515\n" | |
277 "Pid: 3515\n" | |
278 "PPid: 3452\n" | |
279 "TracerPid: 0\n" | |
280 "Uid: 1000 1000 1000 1000\n" | |
281 "Gid: 100 100 100 100\n" | |
282 "FDSize: 256\n" | |
283 "Groups: 16 33 100\n" | |
284 "VmPeak: 9136 kB\n" | |
285 "VmSize: 7896 kB\n" | |
286 "VmLck: 0 kB\n" | |
287 "VmPin: 0 kB\n" | |
288 "VmHWM: 7572 kB\n" | |
289 "VmRSS: 6316 kB\n" | |
290 "VmData: 5224 kB\n" | |
291 "VmStk: 88 kB\n" | |
292 "VmExe: 572 kB\n" | |
293 "VmLib: 1708 kB\n" | |
294 "VmPMD: 4 kB\n" | |
295 "VmPTE: 20 kB\n" | |
296 "VmSwap: 0 kB\n" | |
297 "Threads: 1\n" | |
298 "SigQ: 0/3067\n" | |
299 "SigPnd: 0000000000000000\n" | |
300 "ShdPnd: 0000000000000000\n" | |
301 "SigBlk: 0000000000010000\n" | |
302 "SigIgn: 0000000000384004\n" | |
303 "SigCgt: 000000004b813efb\n" | |
304 "CapInh: 0000000000000000\n" | |
305 "CapPrm: 0000000000000000\n" | |
306 "CapEff: 0000000000000000\n" | |
307 "CapBnd: ffffffffffffffff\n" | |
308 "Seccomp: 0\n" | |
309 "Cpus_allowed: 00000001\n" | |
310 "Cpus_allowed_list: 0\n" | |
311 "Mems_allowed: 1\n" | |
312 "Mems_allowed_list: 0\n" | |
313 "voluntary_ctxt_switches: 150\n" | |
314 "nonvoluntary_ctxt_switches: 545\n"; | |
315 | |
316 size_t vm_size; | |
317 bool res = | |
318 ParseProcStatusAndGetField(valid_status_contents, "VmSize", &vm_size); | |
319 EXPECT_TRUE(res); | |
320 EXPECT_EQ(vm_size, 7896 * 1024u); | |
Lei Zhang
2015/10/07 16:10:54
nit: EXPECT_EQ(expected, actual); // Otherwise on
ssid
2015/10/07 17:11:34
sorry, fixed.
| |
321 } | |
271 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 322 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
272 | 323 |
273 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) || \ | 324 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) || \ |
274 defined(OS_LINUX) || defined(OS_ANDROID) | 325 defined(OS_LINUX) || defined(OS_ANDROID) |
275 TEST(SystemMetrics2Test, GetSystemMemoryInfo) { | 326 TEST(SystemMetrics2Test, GetSystemMemoryInfo) { |
276 base::SystemMemoryInfoKB info; | 327 base::SystemMemoryInfoKB info; |
277 EXPECT_TRUE(base::GetSystemMemoryInfo(&info)); | 328 EXPECT_TRUE(base::GetSystemMemoryInfo(&info)); |
278 | 329 |
279 // Ensure each field received a value. | 330 // Ensure each field received a value. |
280 EXPECT_GT(info.total, 0); | 331 EXPECT_GT(info.total, 0); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); | 411 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); |
361 } | 412 } |
362 } | 413 } |
363 // The Thread destructor will stop them. | 414 // The Thread destructor will stop them. |
364 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); | 415 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); |
365 } | 416 } |
366 #endif // defined(OS_LINUX) | 417 #endif // defined(OS_LINUX) |
367 | 418 |
368 } // namespace debug | 419 } // namespace debug |
369 } // namespace base | 420 } // namespace base |
OLD | NEW |