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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 const std::string kCounterMixed = "CounterMixed"; | 63 const std::string kCounterMixed = "CounterMixed"; |
64 // The number of thread loops that we will do. | 64 // The number of thread loops that we will do. |
65 const int kThreadLoops = 100; | 65 const int kThreadLoops = 100; |
66 | 66 |
67 class StatsTableThread : public SimpleThread { | 67 class StatsTableThread : public SimpleThread { |
68 public: | 68 public: |
69 StatsTableThread(std::string name, int id) | 69 StatsTableThread(std::string name, int id) |
70 : SimpleThread(name), | 70 : SimpleThread(name), |
71 id_(id) {} | 71 id_(id) {} |
72 | 72 |
73 virtual void Run() OVERRIDE; | 73 void Run() override; |
74 | 74 |
75 private: | 75 private: |
76 int id_; | 76 int id_; |
77 }; | 77 }; |
78 | 78 |
79 void StatsTableThread::Run() { | 79 void StatsTableThread::Run() { |
80 // Each thread will open the shared memory and set counters | 80 // Each thread will open the shared memory and set counters |
81 // concurrently in a loop. We'll use some pauses to | 81 // concurrently in a loop. We'll use some pauses to |
82 // mixup the thread scheduling. | 82 // mixup the thread scheduling. |
83 | 83 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 StatsScope<StatsCounterTimer> timer(foo); | 393 StatsScope<StatsCounterTimer> timer(foo); |
394 StatsScope<StatsRate> timer2(bar); | 394 StatsScope<StatsRate> timer2(bar); |
395 PlatformThread::Sleep(kDuration); | 395 PlatformThread::Sleep(kDuration); |
396 } | 396 } |
397 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); | 397 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:foo")); |
398 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); | 398 EXPECT_LE(kDuration.InMilliseconds() * 2, table.GetCounterValue("t:bar")); |
399 EXPECT_EQ(2, table.GetCounterValue("c:bar")); | 399 EXPECT_EQ(2, table.GetCounterValue("c:bar")); |
400 } | 400 } |
401 | 401 |
402 } // namespace base | 402 } // namespace base |
OLD | NEW |