OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/metrics/stats_counters.h" | 5 #include "base/metrics/stats_counters.h" |
6 #include "base/metrics/stats_table.h" | 6 #include "base/metrics/stats_table.h" |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "base/test/multiprocess_test.h" | 10 #include "base/test/multiprocess_test.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // CounterMixed will be incremented by odd numbered threads and | 69 // CounterMixed will be incremented by odd numbered threads and |
70 // decremented by even threads. | 70 // decremented by even threads. |
71 const std::string kCounterMixed = "CounterMixed"; | 71 const std::string kCounterMixed = "CounterMixed"; |
72 // The number of thread loops that we will do. | 72 // The number of thread loops that we will do. |
73 const int kThreadLoops = 100; | 73 const int kThreadLoops = 100; |
74 | 74 |
75 class StatsTableThread : public SimpleThread { | 75 class StatsTableThread : public SimpleThread { |
76 public: | 76 public: |
77 StatsTableThread(std::string name, int id) | 77 StatsTableThread(std::string name, int id) |
78 : SimpleThread(name), | 78 : SimpleThread(name), |
79 id_(id) {} | 79 id_(id) {} |
80 virtual void Run(); | 80 |
| 81 virtual void Run() OVERRIDE; |
| 82 |
81 private: | 83 private: |
82 int id_; | 84 int id_; |
83 }; | 85 }; |
84 | 86 |
85 void StatsTableThread::Run() { | 87 void StatsTableThread::Run() { |
86 // Each thread will open the shared memory and set counters | 88 // Each thread will open the shared memory and set counters |
87 // concurrently in a loop. We'll use some pauses to | 89 // concurrently in a loop. We'll use some pauses to |
88 // mixup the thread scheduling. | 90 // mixup the thread scheduling. |
89 | 91 |
90 StatsCounter zero_counter(kCounterZero); | 92 StatsCounter zero_counter(kCounterZero); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 PlatformThread::Sleep(kDuration); | 409 PlatformThread::Sleep(kDuration); |
408 } | 410 } |
409 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); | 411 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); |
410 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); | 412 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); |
411 EXPECT_EQ(2, table.GetCounterValue("c:bar")); | 413 EXPECT_EQ(2, table.GetCounterValue("c:bar")); |
412 | 414 |
413 DeleteShmem(kTableName); | 415 DeleteShmem(kTableName); |
414 } | 416 } |
415 | 417 |
416 } // namespace base | 418 } // namespace base |
OLD | NEW |