OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A StatsTable is a table of statistics. It can be used across multiple | 5 // A StatsTable is a table of statistics. It can be used across multiple |
6 // processes and threads, maintaining cheap statistics counters without | 6 // processes and threads, maintaining cheap statistics counters without |
7 // locking. | 7 // locking. |
8 // | 8 // |
9 // The goal is to make it very cheap and easy for developers to add | 9 // The goal is to make it very cheap and easy for developers to add |
10 // counters to code, without having to build one-off utilities or mechanisms | 10 // counters to code, without having to build one-off utilities or mechanisms |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // max_counters is the maximum number of counters the table will support. | 45 // max_counters is the maximum number of counters the table will support. |
46 // If the StatsTable already exists, this number is ignored. | 46 // If the StatsTable already exists, this number is ignored. |
47 StatsTable(const std::string& name, int max_threads, int max_counters); | 47 StatsTable(const std::string& name, int max_threads, int max_counters); |
48 | 48 |
49 // Destroys the StatsTable. When the last StatsTable is destroyed | 49 // Destroys the StatsTable. When the last StatsTable is destroyed |
50 // (across all processes), the StatsTable is removed from disk. | 50 // (across all processes), the StatsTable is removed from disk. |
51 ~StatsTable(); | 51 ~StatsTable(); |
52 | 52 |
53 // For convenience, we create a static table. This is generally | 53 // For convenience, we create a static table. This is generally |
54 // used automatically by the counters. | 54 // used automatically by the counters. |
55 static StatsTable* current() { return global_table_; } | 55 static StatsTable* current(); |
56 | 56 |
57 // Set the global table for use in this process. | 57 // Set the global table for use in this process. |
58 static void set_current(StatsTable* value) { global_table_ = value; } | 58 static void set_current(StatsTable* value); |
59 | 59 |
60 // Get the slot id for the calling thread. Returns 0 if no | 60 // Get the slot id for the calling thread. Returns 0 if no |
61 // slot is assigned. | 61 // slot is assigned. |
62 int GetSlot() const; | 62 int GetSlot() const; |
63 | 63 |
64 // All threads that contribute data to the table must register with the | 64 // All threads that contribute data to the table must register with the |
65 // table first. This function will set thread local storage for the | 65 // table first. This function will set thread local storage for the |
66 // thread containing the location in the table where this thread will | 66 // thread containing the location in the table where this thread will |
67 // write its counter data. | 67 // write its counter data. |
68 // | 68 // |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 base::Lock counters_lock_; | 178 base::Lock counters_lock_; |
179 | 179 |
180 // The counters_ hash map is an in-memory hash of the counters. | 180 // The counters_ hash map is an in-memory hash of the counters. |
181 // It is used for quick lookup of counters, but is cannot be used | 181 // It is used for quick lookup of counters, but is cannot be used |
182 // as a substitute for what is in the shared memory. Even though | 182 // as a substitute for what is in the shared memory. Even though |
183 // we don't have a counter in our hash table, another process may | 183 // we don't have a counter in our hash table, another process may |
184 // have created it. | 184 // have created it. |
185 CountersMap counters_; | 185 CountersMap counters_; |
186 ThreadLocalStorage::Slot tls_index_; | 186 ThreadLocalStorage::Slot tls_index_; |
187 | 187 |
188 static StatsTable* global_table_; | |
189 | |
190 DISALLOW_COPY_AND_ASSIGN(StatsTable); | 188 DISALLOW_COPY_AND_ASSIGN(StatsTable); |
191 }; | 189 }; |
192 | 190 |
193 } // namespace base | 191 } // namespace base |
194 | 192 |
195 #endif // BASE_METRICS_STATS_TABLE_H_ | 193 #endif // BASE_METRICS_STATS_TABLE_H_ |
OLD | NEW |