| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 |
| 11 // to track the counters, and also to allow a single "view" to display | 11 // to track the counters, and also to allow a single "view" to display |
| 12 // the contents of all counters. | 12 // the contents of all counters. |
| 13 // | 13 // |
| 14 // To achieve this, StatsTable creates a shared memory segment to store | 14 // To achieve this, StatsTable creates a shared memory segment to store |
| 15 // the data for the counters. Upon creation, it has a specific size | 15 // the data for the counters. Upon creation, it has a specific size |
| 16 // which governs the maximum number of counters and concurrent | 16 // which governs the maximum number of counters and concurrent |
| 17 // threads/processes which can use it. | 17 // threads/processes which can use it. |
| 18 // | 18 // |
| 19 | 19 |
| 20 #ifndef BASE_STATS_TABLE_H__ | 20 #ifndef BASE_STATS_TABLE_H__ |
| 21 #define BASE_STATS_TABLE_H__ | 21 #define BASE_STATS_TABLE_H__ |
| 22 | 22 |
| 23 #include <string> | 23 #include <string> |
| 24 #include "base/basictypes.h" | 24 #include "base/basictypes.h" |
| 25 #include "base/hash_tables.h" | 25 #include "base/hash_tables.h" |
| 26 #include "base/lock.h" | 26 #include "base/lock.h" |
| 27 #include "base/shared_memory.h" | |
| 28 #include "base/thread_local_storage.h" | 27 #include "base/thread_local_storage.h" |
| 29 | 28 |
| 30 class StatsTablePrivate; | 29 class StatsTablePrivate; |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 struct StatsTableTLSData; | 32 struct StatsTableTLSData; |
| 34 } | 33 } |
| 35 | 34 |
| 36 class StatsTable { | 35 class StatsTable { |
| 37 public: | 36 public: |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // On failure, returns 0. | 157 // On failure, returns 0. |
| 159 int AddCounter(const std::wstring& name); | 158 int AddCounter(const std::wstring& name); |
| 160 | 159 |
| 161 // Get the TLS data for the calling thread. Returns NULL if none is | 160 // Get the TLS data for the calling thread. Returns NULL if none is |
| 162 // initialized. | 161 // initialized. |
| 163 StatsTableTLSData* GetTLSData() const; | 162 StatsTableTLSData* GetTLSData() const; |
| 164 | 163 |
| 165 typedef base::hash_map<std::wstring, int> CountersMap; | 164 typedef base::hash_map<std::wstring, int> CountersMap; |
| 166 | 165 |
| 167 bool opened_; | 166 bool opened_; |
| 168 SharedMemory shared_memory_; | |
| 169 StatsTablePrivate* impl_; | 167 StatsTablePrivate* impl_; |
| 170 // The counters_lock_ protects the counters_ hash table. | 168 // The counters_lock_ protects the counters_ hash table. |
| 171 Lock counters_lock_; | 169 Lock counters_lock_; |
| 172 // The counters_ hash map is an in-memory hash of the counters. | 170 // The counters_ hash map is an in-memory hash of the counters. |
| 173 // It is used for quick lookup of counters, but is cannot be used | 171 // It is used for quick lookup of counters, but is cannot be used |
| 174 // as a substitute for what is in the shared memory. Even though | 172 // as a substitute for what is in the shared memory. Even though |
| 175 // we don't have a counter in our hash table, another process may | 173 // we don't have a counter in our hash table, another process may |
| 176 // have created it. | 174 // have created it. |
| 177 CountersMap counters_; | 175 CountersMap counters_; |
| 178 TLSSlot tls_index_; | 176 TLSSlot tls_index_; |
| 179 | 177 |
| 180 static StatsTable* global_table_; | 178 static StatsTable* global_table_; |
| 181 DISALLOW_EVIL_CONSTRUCTORS(StatsTable); | 179 DISALLOW_EVIL_CONSTRUCTORS(StatsTable); |
| 182 }; | 180 }; |
| 183 | 181 |
| 184 #endif // BASE_STATS_TABLE_H__ | 182 #endif // BASE_STATS_TABLE_H__ |
| 185 | |
| OLD | NEW |