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 const char* kValindStatusContents = |
| 274 "Name: bash\n" |
| 275 "PPid: 3452\n" |
| 276 "TracerPid: 0\n" |
| 277 "Uid: 1000 1000 1000 1000\n" |
| 278 "Gid: 100 100 100 100\n" |
| 279 "FDSize: 256\n" |
| 280 "Groups: 16 33 100\n" |
| 281 "VmPeak: 9136 kB\n" |
| 282 "VmSize: 7896 kB\n" |
| 283 "VmHWM: 7572 kB\n" |
| 284 "VmLib: 1708 kB\n" |
| 285 "SigQ: 0/3067\n" |
| 286 "SigPnd: 0000000000000000\n" |
| 287 "ShdPnd: 0000000000000000\n" |
| 288 "CapBnd: ffffffffffffffff\n" |
| 289 "Seccomp: 0\n" |
| 290 "Cpus_allowed: 00000001\n" |
| 291 "nonvoluntary_ctxt_switches: 545\n"; |
| 292 |
| 293 size_t vm_size; |
| 294 bool res = |
| 295 ParseProcStatusAndGetField(kValindStatusContents, "VmSize", &vm_size); |
| 296 EXPECT_TRUE(res); |
| 297 EXPECT_EQ(7896 * 1024u, vm_size); |
| 298 } |
271 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 299 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
272 | 300 |
273 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) || \ | 301 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) || \ |
274 defined(OS_LINUX) || defined(OS_ANDROID) | 302 defined(OS_LINUX) || defined(OS_ANDROID) |
275 TEST(SystemMetrics2Test, GetSystemMemoryInfo) { | 303 TEST(SystemMetrics2Test, GetSystemMemoryInfo) { |
276 base::SystemMemoryInfoKB info; | 304 base::SystemMemoryInfoKB info; |
277 EXPECT_TRUE(base::GetSystemMemoryInfo(&info)); | 305 EXPECT_TRUE(base::GetSystemMemoryInfo(&info)); |
278 | 306 |
279 // Ensure each field received a value. | 307 // Ensure each field received a value. |
280 EXPECT_GT(info.total, 0); | 308 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); | 388 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); |
361 } | 389 } |
362 } | 390 } |
363 // The Thread destructor will stop them. | 391 // The Thread destructor will stop them. |
364 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); | 392 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); |
365 } | 393 } |
366 #endif // defined(OS_LINUX) | 394 #endif // defined(OS_LINUX) |
367 | 395 |
368 } // namespace debug | 396 } // namespace debug |
369 } // namespace base | 397 } // namespace base |
OLD | NEW |