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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 virtual ~StatsTableThread() {} |
Nico
2012/04/05 17:52:34
Why is this needed?
Ryan Sleevi
2012/04/05 19:12:07
D'oh! It isn't. This crept in when I was using an
| |
81 | |
82 virtual void Run() OVERRIDE; | |
83 | |
81 private: | 84 private: |
82 int id_; | 85 int id_; |
83 }; | 86 }; |
84 | 87 |
85 void StatsTableThread::Run() { | 88 void StatsTableThread::Run() { |
86 // Each thread will open the shared memory and set counters | 89 // Each thread will open the shared memory and set counters |
87 // concurrently in a loop. We'll use some pauses to | 90 // concurrently in a loop. We'll use some pauses to |
88 // mixup the thread scheduling. | 91 // mixup the thread scheduling. |
89 | 92 |
90 StatsCounter zero_counter(kCounterZero); | 93 StatsCounter zero_counter(kCounterZero); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 PlatformThread::Sleep(kDuration); | 410 PlatformThread::Sleep(kDuration); |
408 } | 411 } |
409 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); | 412 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); |
410 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); | 413 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); |
411 EXPECT_EQ(2, table.GetCounterValue("c:bar")); | 414 EXPECT_EQ(2, table.GetCounterValue("c:bar")); |
412 | 415 |
413 DeleteShmem(kTableName); | 416 DeleteShmem(kTableName); |
414 } | 417 } |
415 | 418 |
416 } // namespace base | 419 } // namespace base |
OLD | NEW |