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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Create a stats table. | 193 // Create a stats table. |
194 const int kMaxProcs = 20; | 194 const int kMaxProcs = 20; |
195 const int kMaxCounter = 5; | 195 const int kMaxCounter = 5; |
196 StatsTable table(kMPTableName, kMaxProcs, kMaxCounter); | 196 StatsTable table(kMPTableName, kMaxProcs, kMaxCounter); |
197 StatsTable::set_current(&table); | 197 StatsTable::set_current(&table); |
198 EXPECT_EQ(0, table.CountThreadsRegistered()); | 198 EXPECT_EQ(0, table.CountThreadsRegistered()); |
199 | 199 |
200 // Spin up a set of processes to go bang on the various counters. | 200 // Spin up a set of processes to go bang on the various counters. |
201 // After we join the processes, we'll make sure the counters | 201 // After we join the processes, we'll make sure the counters |
202 // contain the values we expected. | 202 // contain the values we expected. |
203 ProcessHandle procs[kMaxProcs]; | 203 Process procs[kMaxProcs]; |
204 | 204 |
205 // Spawn the processes. | 205 // Spawn the processes. |
206 for (int16 index = 0; index < kMaxProcs; index++) { | 206 for (int16 index = 0; index < kMaxProcs; index++) { |
207 procs[index] = SpawnChild("StatsTableMultipleProcessMain"); | 207 procs[index] = SpawnChild("StatsTableMultipleProcessMain"); |
208 EXPECT_NE(kNullProcessHandle, procs[index]); | 208 EXPECT_TRUE(procs[index].IsValid()); |
209 } | 209 } |
210 | 210 |
211 // Wait for the processes to finish. | 211 // Wait for the processes to finish. |
212 for (int index = 0; index < kMaxProcs; index++) { | 212 for (int index = 0; index < kMaxProcs; index++) { |
213 EXPECT_TRUE(WaitForSingleProcess( | 213 EXPECT_TRUE(WaitForSingleProcess(procs[index].Handle(), |
214 procs[index], base::TimeDelta::FromMinutes(1))); | 214 base::TimeDelta::FromMinutes(1))); |
215 CloseProcessHandle(procs[index]); | 215 procs[index].Close(); |
216 } | 216 } |
217 | 217 |
218 StatsCounter zero_counter(kCounterZero); | 218 StatsCounter zero_counter(kCounterZero); |
219 StatsCounter lucky13_counter(kCounter1313); | 219 StatsCounter lucky13_counter(kCounter1313); |
220 StatsCounter increment_counter(kCounterIncrement); | 220 StatsCounter increment_counter(kCounterIncrement); |
221 StatsCounter decrement_counter(kCounterDecrement); | 221 StatsCounter decrement_counter(kCounterDecrement); |
222 | 222 |
223 // Verify the various counters are correct. | 223 // Verify the various counters are correct. |
224 std::string name; | 224 std::string name; |
225 name = "c:" + kCounterZero; | 225 name = "c:" + kCounterZero; |
(...skipping 167 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 |