| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_piece.h" | 9 #include "base/string_piece.h" |
| 9 #include "base/string_util.h" | |
| 10 #include "base/test/multiprocess_test.h" | 10 #include "base/test/multiprocess_test.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/multiprocess_func_list.h" | 15 #include "testing/multiprocess_func_list.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 | 18 |
| 19 class StatsTableTest : public MultiProcessTest { | 19 class StatsTableTest : public MultiProcessTest { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // Register a single thread. | 36 // Register a single thread. |
| 37 std::string thread_name = "mainThread"; | 37 std::string thread_name = "mainThread"; |
| 38 int slot_id = table.RegisterThread(thread_name); | 38 int slot_id = table.RegisterThread(thread_name); |
| 39 EXPECT_NE(slot_id, 0); | 39 EXPECT_NE(slot_id, 0); |
| 40 | 40 |
| 41 // Fill up the table with counters. | 41 // Fill up the table with counters. |
| 42 std::string counter_base_name = "counter"; | 42 std::string counter_base_name = "counter"; |
| 43 for (int index = 0; index < kMaxCounter; index++) { | 43 for (int index = 0; index < kMaxCounter; index++) { |
| 44 std::string counter_name = counter_base_name; | 44 std::string counter_name = counter_base_name; |
| 45 StringAppendF(&counter_name, "counter.ctr%d", index); | 45 base::StringAppendF(&counter_name, "counter.ctr%d", index); |
| 46 int counter_id = table.FindCounter(counter_name); | 46 int counter_id = table.FindCounter(counter_name); |
| 47 EXPECT_GT(counter_id, 0); | 47 EXPECT_GT(counter_id, 0); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Try to allocate an additional thread. Verify it fails. | 50 // Try to allocate an additional thread. Verify it fails. |
| 51 slot_id = table.RegisterThread("too many threads"); | 51 slot_id = table.RegisterThread("too many threads"); |
| 52 EXPECT_EQ(slot_id, 0); | 52 EXPECT_EQ(slot_id, 0); |
| 53 | 53 |
| 54 // Try to allocate an additional counter. Verify it fails. | 54 // Try to allocate an additional counter. Verify it fails. |
| 55 int counter_id = table.FindCounter(counter_base_name); | 55 int counter_id = table.FindCounter(counter_base_name); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 PlatformThread::Sleep(kRunMs); | 402 PlatformThread::Sleep(kRunMs); |
| 403 } | 403 } |
| 404 EXPECT_LE(kRunMs * 2, table.GetCounterValue("t:foo")); | 404 EXPECT_LE(kRunMs * 2, table.GetCounterValue("t:foo")); |
| 405 EXPECT_LE(kRunMs * 2, table.GetCounterValue("t:bar")); | 405 EXPECT_LE(kRunMs * 2, table.GetCounterValue("t:bar")); |
| 406 EXPECT_EQ(2, table.GetCounterValue("c:bar")); | 406 EXPECT_EQ(2, table.GetCounterValue("c:bar")); |
| 407 | 407 |
| 408 DeleteShmem(kTableName); | 408 DeleteShmem(kTableName); |
| 409 } | 409 } |
| 410 | 410 |
| 411 } // namespace base | 411 } // namespace base |
| OLD | NEW |