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/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 #include "base/metrics/stats_counters.h" | 6 #include "base/metrics/stats_counters.h" |
7 #include "base/metrics/stats_table.h" | 7 #include "base/metrics/stats_table.h" |
8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/test/multiprocess_test.h" | 12 #include "base/test/multiprocess_test.h" |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 #include "base/threading/simple_thread.h" | 14 #include "base/threading/simple_thread.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/multiprocess_func_list.h" | 16 #include "testing/multiprocess_func_list.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 | 19 |
20 class StatsTableTest : public MultiProcessTest { | 20 class StatsTableTest : public MultiProcessTest { |
21 public: | |
22 void DeleteShmem(const std::string& name) { | |
23 SharedMemory mem; | |
24 mem.Delete(name); | |
25 } | |
26 }; | 21 }; |
27 | 22 |
28 // Open a StatsTable and verify that we can write to each of the | 23 // Open a StatsTable and verify that we can write to each of the |
29 // locations in the table. | 24 // locations in the table. |
30 TEST_F(StatsTableTest, VerifySlots) { | 25 TEST_F(StatsTableTest, VerifySlots) { |
31 const std::string kTableName = "VerifySlotsStatTable"; | |
32 const int kMaxThreads = 1; | 26 const int kMaxThreads = 1; |
33 const int kMaxCounter = 5; | 27 const int kMaxCounter = 5; |
34 DeleteShmem(kTableName); | 28 StatsTable table(StatsTable::TableIdentifier(), kMaxThreads, kMaxCounter); |
35 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | |
36 | 29 |
37 // Register a single thread. | 30 // Register a single thread. |
38 std::string thread_name = "mainThread"; | 31 std::string thread_name = "mainThread"; |
39 int slot_id = table.RegisterThread(thread_name); | 32 int slot_id = table.RegisterThread(thread_name); |
40 EXPECT_NE(slot_id, 0); | 33 EXPECT_NE(slot_id, 0); |
41 | 34 |
42 // Fill up the table with counters. | 35 // Fill up the table with counters. |
43 std::string counter_base_name = "counter"; | 36 std::string counter_base_name = "counter"; |
44 for (int index = 0; index < kMaxCounter; index++) { | 37 for (int index = 0; index < kMaxCounter; index++) { |
45 std::string counter_name = counter_base_name; | 38 std::string counter_name = counter_base_name; |
46 base::StringAppendF(&counter_name, "counter.ctr%d", index); | 39 base::StringAppendF(&counter_name, "counter.ctr%d", index); |
47 int counter_id = table.FindCounter(counter_name); | 40 int counter_id = table.FindCounter(counter_name); |
48 EXPECT_GT(counter_id, 0); | 41 EXPECT_GT(counter_id, 0); |
49 } | 42 } |
50 | 43 |
51 // Try to allocate an additional thread. Verify it fails. | 44 // Try to allocate an additional thread. Verify it fails. |
52 slot_id = table.RegisterThread("too many threads"); | 45 slot_id = table.RegisterThread("too many threads"); |
53 EXPECT_EQ(slot_id, 0); | 46 EXPECT_EQ(slot_id, 0); |
54 | 47 |
55 // Try to allocate an additional counter. Verify it fails. | 48 // Try to allocate an additional counter. Verify it fails. |
56 int counter_id = table.FindCounter(counter_base_name); | 49 int counter_id = table.FindCounter(counter_base_name); |
57 EXPECT_EQ(counter_id, 0); | 50 EXPECT_EQ(counter_id, 0); |
58 | |
59 DeleteShmem(kTableName); | |
60 } | 51 } |
61 | 52 |
62 // CounterZero will continually be set to 0. | 53 // CounterZero will continually be set to 0. |
63 const std::string kCounterZero = "CounterZero"; | 54 const std::string kCounterZero = "CounterZero"; |
64 // Counter1313 will continually be set to 1313. | 55 // Counter1313 will continually be set to 1313. |
65 const std::string kCounter1313 = "Counter1313"; | 56 const std::string kCounter1313 = "Counter1313"; |
66 // CounterIncrement will be incremented each time. | 57 // CounterIncrement will be incremented each time. |
67 const std::string kCounterIncrement = "CounterIncrement"; | 58 const std::string kCounterIncrement = "CounterIncrement"; |
68 // CounterDecrement will be decremented each time. | 59 // CounterDecrement will be decremented each time. |
69 const std::string kCounterDecrement = "CounterDecrement"; | 60 const std::string kCounterDecrement = "CounterDecrement"; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 101 |
111 // Create a few threads and have them poke on their counters. | 102 // Create a few threads and have them poke on their counters. |
112 // See http://crbug.com/10611 for more information. | 103 // See http://crbug.com/10611 for more information. |
113 #if defined(OS_MACOSX) || defined(THREAD_SANITIZER) | 104 #if defined(OS_MACOSX) || defined(THREAD_SANITIZER) |
114 #define MAYBE_MultipleThreads DISABLED_MultipleThreads | 105 #define MAYBE_MultipleThreads DISABLED_MultipleThreads |
115 #else | 106 #else |
116 #define MAYBE_MultipleThreads MultipleThreads | 107 #define MAYBE_MultipleThreads MultipleThreads |
117 #endif | 108 #endif |
118 TEST_F(StatsTableTest, MAYBE_MultipleThreads) { | 109 TEST_F(StatsTableTest, MAYBE_MultipleThreads) { |
119 // Create a stats table. | 110 // Create a stats table. |
120 const std::string kTableName = "MultipleThreadStatTable"; | |
121 const int kMaxThreads = 20; | 111 const int kMaxThreads = 20; |
122 const int kMaxCounter = 5; | 112 const int kMaxCounter = 5; |
123 DeleteShmem(kTableName); | 113 StatsTable table(StatsTable::TableIdentifier(), kMaxThreads, kMaxCounter); |
124 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | |
125 StatsTable::set_current(&table); | 114 StatsTable::set_current(&table); |
126 | 115 |
127 EXPECT_EQ(0, table.CountThreadsRegistered()); | 116 EXPECT_EQ(0, table.CountThreadsRegistered()); |
128 | 117 |
129 // Spin up a set of threads to go bang on the various counters. | 118 // Spin up a set of threads to go bang on the various counters. |
130 // After we join the threads, we'll make sure the counters | 119 // After we join the threads, we'll make sure the counters |
131 // contain the values we expected. | 120 // contain the values we expected. |
132 StatsTableThread* threads[kMaxThreads]; | 121 StatsTableThread* threads[kMaxThreads]; |
133 | 122 |
134 // Spawn the threads. | 123 // Spawn the threads. |
(...skipping 24 matching lines...) Expand all Loading... |
159 name = "c:" + kCounterIncrement; | 148 name = "c:" + kCounterIncrement; |
160 EXPECT_EQ(kMaxThreads * kThreadLoops, | 149 EXPECT_EQ(kMaxThreads * kThreadLoops, |
161 table.GetCounterValue(name)); | 150 table.GetCounterValue(name)); |
162 name = "c:" + kCounterDecrement; | 151 name = "c:" + kCounterDecrement; |
163 EXPECT_EQ(-kMaxThreads * kThreadLoops, | 152 EXPECT_EQ(-kMaxThreads * kThreadLoops, |
164 table.GetCounterValue(name)); | 153 table.GetCounterValue(name)); |
165 name = "c:" + kCounterMixed; | 154 name = "c:" + kCounterMixed; |
166 EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, | 155 EXPECT_EQ((kMaxThreads % 2) * kThreadLoops, |
167 table.GetCounterValue(name)); | 156 table.GetCounterValue(name)); |
168 EXPECT_EQ(0, table.CountThreadsRegistered()); | 157 EXPECT_EQ(0, table.CountThreadsRegistered()); |
169 | |
170 DeleteShmem(kTableName); | |
171 } | 158 } |
172 | 159 |
| 160 // This multiprocess test only runs on Windows. On Posix, the shared memory |
| 161 // handle is not sent between the processes properly. |
| 162 #if defined(OS_WIN) |
173 const std::string kMPTableName = "MultipleProcessStatTable"; | 163 const std::string kMPTableName = "MultipleProcessStatTable"; |
174 | 164 |
175 MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { | 165 MULTIPROCESS_TEST_MAIN(StatsTableMultipleProcessMain) { |
176 // Each process will open the shared memory and set counters | 166 // Each process will open the shared memory and set counters |
177 // concurrently in a loop. We'll use some pauses to | 167 // concurrently in a loop. We'll use some pauses to |
178 // mixup the scheduling. | 168 // mixup the scheduling. |
179 | 169 |
180 StatsTable table(kMPTableName, 0, 0); | 170 StatsTable table(kMPTableName, 0, 0); |
181 StatsTable::set_current(&table); | 171 StatsTable::set_current(&table); |
182 StatsCounter zero_counter(kCounterZero); | 172 StatsCounter zero_counter(kCounterZero); |
183 StatsCounter lucky13_counter(kCounter1313); | 173 StatsCounter lucky13_counter(kCounter1313); |
184 StatsCounter increment_counter(kCounterIncrement); | 174 StatsCounter increment_counter(kCounterIncrement); |
185 StatsCounter decrement_counter(kCounterDecrement); | 175 StatsCounter decrement_counter(kCounterDecrement); |
186 for (int index = 0; index < kThreadLoops; index++) { | 176 for (int index = 0; index < kThreadLoops; index++) { |
187 zero_counter.Set(0); | 177 zero_counter.Set(0); |
188 lucky13_counter.Set(1313); | 178 lucky13_counter.Set(1313); |
189 increment_counter.Increment(); | 179 increment_counter.Increment(); |
190 decrement_counter.Decrement(); | 180 decrement_counter.Decrement(); |
191 PlatformThread::Sleep(TimeDelta::FromMilliseconds(index % 10)); | 181 PlatformThread::Sleep(TimeDelta::FromMilliseconds(index % 10)); |
192 } | 182 } |
193 return 0; | 183 return 0; |
194 } | 184 } |
195 | 185 |
196 // Create a few processes and have them poke on their counters. | 186 // Create a few processes and have them poke on their counters. |
197 // This test is slow and flaky http://crbug.com/10611 | 187 // This test is slow and flaky http://crbug.com/10611 |
198 TEST_F(StatsTableTest, DISABLED_MultipleProcesses) { | 188 TEST_F(StatsTableTest, DISABLED_MultipleProcesses) { |
199 // Create a stats table. | 189 // Create a stats table. |
200 const int kMaxProcs = 20; | 190 const int kMaxProcs = 20; |
201 const int kMaxCounter = 5; | 191 const int kMaxCounter = 5; |
202 DeleteShmem(kMPTableName); | |
203 StatsTable table(kMPTableName, kMaxProcs, kMaxCounter); | 192 StatsTable table(kMPTableName, kMaxProcs, kMaxCounter); |
204 StatsTable::set_current(&table); | 193 StatsTable::set_current(&table); |
205 EXPECT_EQ(0, table.CountThreadsRegistered()); | 194 EXPECT_EQ(0, table.CountThreadsRegistered()); |
206 | 195 |
207 // Spin up a set of processes to go bang on the various counters. | 196 // Spin up a set of processes to go bang on the various counters. |
208 // After we join the processes, we'll make sure the counters | 197 // After we join the processes, we'll make sure the counters |
209 // contain the values we expected. | 198 // contain the values we expected. |
210 ProcessHandle procs[kMaxProcs]; | 199 ProcessHandle procs[kMaxProcs]; |
211 | 200 |
212 // Spawn the processes. | 201 // Spawn the processes. |
(...skipping 21 matching lines...) Expand all Loading... |
234 name = "c:" + kCounter1313; | 223 name = "c:" + kCounter1313; |
235 EXPECT_EQ(1313 * kMaxProcs, | 224 EXPECT_EQ(1313 * kMaxProcs, |
236 table.GetCounterValue(name)); | 225 table.GetCounterValue(name)); |
237 name = "c:" + kCounterIncrement; | 226 name = "c:" + kCounterIncrement; |
238 EXPECT_EQ(kMaxProcs * kThreadLoops, | 227 EXPECT_EQ(kMaxProcs * kThreadLoops, |
239 table.GetCounterValue(name)); | 228 table.GetCounterValue(name)); |
240 name = "c:" + kCounterDecrement; | 229 name = "c:" + kCounterDecrement; |
241 EXPECT_EQ(-kMaxProcs * kThreadLoops, | 230 EXPECT_EQ(-kMaxProcs * kThreadLoops, |
242 table.GetCounterValue(name)); | 231 table.GetCounterValue(name)); |
243 EXPECT_EQ(0, table.CountThreadsRegistered()); | 232 EXPECT_EQ(0, table.CountThreadsRegistered()); |
244 | |
245 DeleteShmem(kMPTableName); | |
246 } | 233 } |
| 234 #endif |
247 | 235 |
248 class MockStatsCounter : public StatsCounter { | 236 class MockStatsCounter : public StatsCounter { |
249 public: | 237 public: |
250 explicit MockStatsCounter(const std::string& name) | 238 explicit MockStatsCounter(const std::string& name) |
251 : StatsCounter(name) {} | 239 : StatsCounter(name) {} |
252 int* Pointer() { return GetPtr(); } | 240 int* Pointer() { return GetPtr(); } |
253 }; | 241 }; |
254 | 242 |
255 // Test some basic StatsCounter operations | 243 // Test some basic StatsCounter operations |
256 TEST_F(StatsTableTest, StatsCounter) { | 244 TEST_F(StatsTableTest, StatsCounter) { |
257 // Create a stats table. | 245 // Create a stats table. |
258 const std::string kTableName = "StatTable"; | |
259 const int kMaxThreads = 20; | 246 const int kMaxThreads = 20; |
260 const int kMaxCounter = 5; | 247 const int kMaxCounter = 5; |
261 DeleteShmem(kTableName); | 248 StatsTable table(StatsTable::TableIdentifier(), kMaxThreads, kMaxCounter); |
262 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | |
263 StatsTable::set_current(&table); | 249 StatsTable::set_current(&table); |
264 | 250 |
265 MockStatsCounter foo("foo"); | 251 MockStatsCounter foo("foo"); |
266 | 252 |
267 // Test initial state. | 253 // Test initial state. |
268 EXPECT_TRUE(foo.Enabled()); | 254 EXPECT_TRUE(foo.Enabled()); |
269 ASSERT_NE(foo.Pointer(), static_cast<int*>(0)); | 255 ASSERT_NE(foo.Pointer(), static_cast<int*>(0)); |
270 EXPECT_EQ(0, *(foo.Pointer())); | 256 EXPECT_EQ(0, *(foo.Pointer())); |
271 EXPECT_EQ(0, table.GetCounterValue("c:foo")); | 257 EXPECT_EQ(0, table.GetCounterValue("c:foo")); |
272 | 258 |
(...skipping 15 matching lines...) Expand all Loading... |
288 foo.Set(0); | 274 foo.Set(0); |
289 EXPECT_EQ(0, table.GetCounterValue("c:foo")); | 275 EXPECT_EQ(0, table.GetCounterValue("c:foo")); |
290 | 276 |
291 // Test Decrement. | 277 // Test Decrement. |
292 foo.Subtract(1); | 278 foo.Subtract(1); |
293 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); | 279 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); |
294 foo.Subtract(0); | 280 foo.Subtract(0); |
295 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); | 281 EXPECT_EQ(-1, table.GetCounterValue("c:foo")); |
296 foo.Subtract(-1); | 282 foo.Subtract(-1); |
297 EXPECT_EQ(0, table.GetCounterValue("c:foo")); | 283 EXPECT_EQ(0, table.GetCounterValue("c:foo")); |
298 | |
299 DeleteShmem(kTableName); | |
300 } | 284 } |
301 | 285 |
302 class MockStatsCounterTimer : public StatsCounterTimer { | 286 class MockStatsCounterTimer : public StatsCounterTimer { |
303 public: | 287 public: |
304 explicit MockStatsCounterTimer(const std::string& name) | 288 explicit MockStatsCounterTimer(const std::string& name) |
305 : StatsCounterTimer(name) {} | 289 : StatsCounterTimer(name) {} |
306 | 290 |
307 TimeTicks start_time() { return start_time_; } | 291 TimeTicks start_time() { return start_time_; } |
308 TimeTicks stop_time() { return stop_time_; } | 292 TimeTicks stop_time() { return stop_time_; } |
309 }; | 293 }; |
310 | 294 |
311 // Test some basic StatsCounterTimer operations | 295 // Test some basic StatsCounterTimer operations |
312 TEST_F(StatsTableTest, StatsCounterTimer) { | 296 TEST_F(StatsTableTest, StatsCounterTimer) { |
313 // Create a stats table. | 297 // Create a stats table. |
314 const std::string kTableName = "StatTable"; | |
315 const int kMaxThreads = 20; | 298 const int kMaxThreads = 20; |
316 const int kMaxCounter = 5; | 299 const int kMaxCounter = 5; |
317 DeleteShmem(kTableName); | 300 StatsTable table(StatsTable::TableIdentifier(), kMaxThreads, kMaxCounter); |
318 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | |
319 StatsTable::set_current(&table); | 301 StatsTable::set_current(&table); |
320 | 302 |
321 MockStatsCounterTimer bar("bar"); | 303 MockStatsCounterTimer bar("bar"); |
322 | 304 |
323 // Test initial state. | 305 // Test initial state. |
324 EXPECT_FALSE(bar.Running()); | 306 EXPECT_FALSE(bar.Running()); |
325 EXPECT_TRUE(bar.start_time().is_null()); | 307 EXPECT_TRUE(bar.start_time().is_null()); |
326 EXPECT_TRUE(bar.stop_time().is_null()); | 308 EXPECT_TRUE(bar.stop_time().is_null()); |
327 | 309 |
328 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100); | 310 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100); |
329 | 311 |
330 // Do some timing. | 312 // Do some timing. |
331 bar.Start(); | 313 bar.Start(); |
332 PlatformThread::Sleep(kDuration); | 314 PlatformThread::Sleep(kDuration); |
333 bar.Stop(); | 315 bar.Stop(); |
334 EXPECT_GT(table.GetCounterValue("t:bar"), 0); | 316 EXPECT_GT(table.GetCounterValue("t:bar"), 0); |
335 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:bar")); | 317 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:bar")); |
336 | 318 |
337 // Verify that timing again is additive. | 319 // Verify that timing again is additive. |
338 bar.Start(); | 320 bar.Start(); |
339 PlatformThread::Sleep(kDuration); | 321 PlatformThread::Sleep(kDuration); |
340 bar.Stop(); | 322 bar.Stop(); |
341 EXPECT_GT(table.GetCounterValue("t:bar"), 0); | 323 EXPECT_GT(table.GetCounterValue("t:bar"), 0); |
342 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); | 324 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); |
343 DeleteShmem(kTableName); | |
344 } | 325 } |
345 | 326 |
346 // Test some basic StatsRate operations | 327 // Test some basic StatsRate operations |
347 TEST_F(StatsTableTest, StatsRate) { | 328 TEST_F(StatsTableTest, StatsRate) { |
348 // Create a stats table. | 329 // Create a stats table. |
349 const std::string kTableName = "StatTable"; | |
350 const int kMaxThreads = 20; | 330 const int kMaxThreads = 20; |
351 const int kMaxCounter = 5; | 331 const int kMaxCounter = 5; |
352 DeleteShmem(kTableName); | 332 StatsTable table(StatsTable::TableIdentifier(), kMaxThreads, kMaxCounter); |
353 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | |
354 StatsTable::set_current(&table); | 333 StatsTable::set_current(&table); |
355 | 334 |
356 StatsRate baz("baz"); | 335 StatsRate baz("baz"); |
357 | 336 |
358 // Test initial state. | 337 // Test initial state. |
359 EXPECT_FALSE(baz.Running()); | 338 EXPECT_FALSE(baz.Running()); |
360 EXPECT_EQ(0, table.GetCounterValue("c:baz")); | 339 EXPECT_EQ(0, table.GetCounterValue("c:baz")); |
361 EXPECT_EQ(0, table.GetCounterValue("t:baz")); | 340 EXPECT_EQ(0, table.GetCounterValue("t:baz")); |
362 | 341 |
363 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100); | 342 const TimeDelta kDuration = TimeDelta::FromMilliseconds(100); |
364 | 343 |
365 // Do some timing. | 344 // Do some timing. |
366 baz.Start(); | 345 baz.Start(); |
367 PlatformThread::Sleep(kDuration); | 346 PlatformThread::Sleep(kDuration); |
368 baz.Stop(); | 347 baz.Stop(); |
369 EXPECT_EQ(1, table.GetCounterValue("c:baz")); | 348 EXPECT_EQ(1, table.GetCounterValue("c:baz")); |
370 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:baz")); | 349 EXPECT_LE(kDuration.InMilliseconds(), table.GetCounterValue("t:baz")); |
371 | 350 |
372 // Verify that timing again is additive. | 351 // Verify that timing again is additive. |
373 baz.Start(); | 352 baz.Start(); |
374 PlatformThread::Sleep(kDuration); | 353 PlatformThread::Sleep(kDuration); |
375 baz.Stop(); | 354 baz.Stop(); |
376 EXPECT_EQ(2, table.GetCounterValue("c:baz")); | 355 EXPECT_EQ(2, table.GetCounterValue("c:baz")); |
377 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:baz")); | 356 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:baz")); |
378 DeleteShmem(kTableName); | |
379 } | 357 } |
380 | 358 |
381 // Test some basic StatsScope operations | 359 // Test some basic StatsScope operations |
382 TEST_F(StatsTableTest, StatsScope) { | 360 TEST_F(StatsTableTest, StatsScope) { |
383 // Create a stats table. | 361 // Create a stats table. |
384 const std::string kTableName = "StatTable"; | |
385 const int kMaxThreads = 20; | 362 const int kMaxThreads = 20; |
386 const int kMaxCounter = 5; | 363 const int kMaxCounter = 5; |
387 DeleteShmem(kTableName); | 364 StatsTable table(StatsTable::TableIdentifier(), kMaxThreads, kMaxCounter); |
388 StatsTable table(kTableName, kMaxThreads, kMaxCounter); | |
389 StatsTable::set_current(&table); | 365 StatsTable::set_current(&table); |
390 | 366 |
391 StatsCounterTimer foo("foo"); | 367 StatsCounterTimer foo("foo"); |
392 StatsRate bar("bar"); | 368 StatsRate bar("bar"); |
393 | 369 |
394 // Test initial state. | 370 // Test initial state. |
395 EXPECT_EQ(0, table.GetCounterValue("t:foo")); | 371 EXPECT_EQ(0, table.GetCounterValue("t:foo")); |
396 EXPECT_EQ(0, table.GetCounterValue("t:bar")); | 372 EXPECT_EQ(0, table.GetCounterValue("t:bar")); |
397 EXPECT_EQ(0, table.GetCounterValue("c:bar")); | 373 EXPECT_EQ(0, table.GetCounterValue("c:bar")); |
398 | 374 |
(...skipping 11 matching lines...) Expand all Loading... |
410 | 386 |
411 // Try a second scope. | 387 // Try a second scope. |
412 { | 388 { |
413 StatsScope<StatsCounterTimer> timer(foo); | 389 StatsScope<StatsCounterTimer> timer(foo); |
414 StatsScope<StatsRate> timer2(bar); | 390 StatsScope<StatsRate> timer2(bar); |
415 PlatformThread::Sleep(kDuration); | 391 PlatformThread::Sleep(kDuration); |
416 } | 392 } |
417 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); | 393 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); |
418 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); | 394 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); |
419 EXPECT_EQ(2, table.GetCounterValue("c:bar")); | 395 EXPECT_EQ(2, table.GetCounterValue("c:bar")); |
420 | |
421 DeleteShmem(kTableName); | |
422 } | 396 } |
423 | 397 |
424 } // namespace base | 398 } // namespace base |
OLD | NEW |