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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 EXPECT_EQ(12 + 16, base::ParseProcStatCPU(kTopStat)); | 316 EXPECT_EQ(12 + 16, base::ParseProcStatCPU(kTopStat)); |
317 | 317 |
318 // cat /proc/self/stat on a random other machine I have. | 318 // cat /proc/self/stat on a random other machine I have. |
319 const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 " | 319 const char kSelfStat[] = "5364 (cat) R 5354 5364 5354 34819 5364 " |
320 "0 142 0 0 0 " | 320 "0 142 0 0 0 " |
321 "0 0 0 0 " // <- No CPU, apparently. | 321 "0 0 0 0 " // <- No CPU, apparently. |
322 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " | 322 "16 0 1 0 1676099790 2957312 114 4294967295 134512640 134528148 " |
323 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; | 323 "3221224832 3221224344 3086339742 0 0 0 0 0 0 0 17 0 0 0"; |
324 | 324 |
325 EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat)); | 325 EXPECT_EQ(0, base::ParseProcStatCPU(kSelfStat)); |
| 326 |
| 327 // Some weird long-running process with a weird name that I created for the |
| 328 // purposes of this test. |
| 329 const char kWeirdNameStat[] = "26115 (Hello) You ())) ) R 24614 26115 24614" |
| 330 " 34839 26115 4218880 227 0 0 0 " |
| 331 "5186 11 0 0 " |
| 332 "20 0 1 0 36933953 4296704 90 18446744073709551615 4194304 4196116 " |
| 333 "140735857761568 140735857761160 4195644 0 0 0 0 0 0 0 17 14 0 0 0 0 0 " |
| 334 "6295056 6295616 16519168 140735857770710 140735857770737 " |
| 335 "140735857770737 140735857774557 0"; |
| 336 EXPECT_EQ(5186 + 11, base::ParseProcStatCPU(kWeirdNameStat)); |
326 } | 337 } |
327 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 338 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
328 | 339 |
329 // Disable on Android because base_unittests runs inside a Dalvik VM that | 340 // Disable on Android because base_unittests runs inside a Dalvik VM that |
330 // starts and stop threads (crbug.com/175563). | 341 // starts and stop threads (crbug.com/175563). |
331 #if defined(OS_LINUX) | 342 #if defined(OS_LINUX) |
332 // http://crbug.com/396455 | 343 // http://crbug.com/396455 |
333 TEST(ProcessMetricsTest, DISABLED_GetNumberOfThreads) { | 344 TEST(ProcessMetricsTest, DISABLED_GetNumberOfThreads) { |
334 const base::ProcessHandle current = base::GetCurrentProcessHandle(); | 345 const base::ProcessHandle current = base::GetCurrentProcessHandle(); |
335 const int initial_threads = base::GetNumberOfThreads(current); | 346 const int initial_threads = base::GetNumberOfThreads(current); |
336 ASSERT_GT(initial_threads, 0); | 347 ASSERT_GT(initial_threads, 0); |
337 const int kNumAdditionalThreads = 10; | 348 const int kNumAdditionalThreads = 10; |
338 { | 349 { |
339 scoped_ptr<base::Thread> my_threads[kNumAdditionalThreads]; | 350 scoped_ptr<base::Thread> my_threads[kNumAdditionalThreads]; |
340 for (int i = 0; i < kNumAdditionalThreads; ++i) { | 351 for (int i = 0; i < kNumAdditionalThreads; ++i) { |
341 my_threads[i].reset(new base::Thread("GetNumberOfThreadsTest")); | 352 my_threads[i].reset(new base::Thread("GetNumberOfThreadsTest")); |
342 my_threads[i]->Start(); | 353 my_threads[i]->Start(); |
343 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); | 354 ASSERT_EQ(base::GetNumberOfThreads(current), initial_threads + 1 + i); |
344 } | 355 } |
345 } | 356 } |
346 // The Thread destructor will stop them. | 357 // The Thread destructor will stop them. |
347 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); | 358 ASSERT_EQ(initial_threads, base::GetNumberOfThreads(current)); |
348 } | 359 } |
349 #endif // defined(OS_LINUX) | 360 #endif // defined(OS_LINUX) |
350 | 361 |
351 } // namespace debug | 362 } // namespace debug |
352 } // namespace base | 363 } // namespace base |
OLD | NEW |