| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_COUNTERS_H_ | 28 #ifndef V8_COUNTERS_H_ |
| 29 #define V8_COUNTERS_H_ | 29 #define V8_COUNTERS_H_ |
| 30 | 30 |
| 31 #include <wchar.h> | |
| 32 | |
| 33 namespace v8 { namespace internal { | 31 namespace v8 { namespace internal { |
| 34 | 32 |
| 35 // StatsCounters is an interface for plugging into external | 33 // StatsCounters is an interface for plugging into external |
| 36 // counters for monitoring. Counters can be looked up and | 34 // counters for monitoring. Counters can be looked up and |
| 37 // manipulated by name. | 35 // manipulated by name. |
| 38 | 36 |
| 39 class StatsTable : public AllStatic { | 37 class StatsTable : public AllStatic { |
| 40 public: | 38 public: |
| 41 // Register an application-defined function where | 39 // Register an application-defined function where |
| 42 // counters can be looked up. | 40 // counters can be looked up. |
| 43 static void SetCounterFunction(CounterLookupCallback f) { | 41 static void SetCounterFunction(CounterLookupCallback f) { |
| 44 lookup_function_ = f; | 42 lookup_function_ = f; |
| 45 } | 43 } |
| 46 | 44 |
| 47 static bool HasCounterFunction() { | 45 static bool HasCounterFunction() { |
| 48 return lookup_function_ != NULL; | 46 return lookup_function_ != NULL; |
| 49 } | 47 } |
| 50 | 48 |
| 51 // Lookup the location of a counter by name. If the lookup | 49 // Lookup the location of a counter by name. If the lookup |
| 52 // is successful, returns a non-NULL pointer for writing the | 50 // is successful, returns a non-NULL pointer for writing the |
| 53 // value of the counter. Each thread calling this function | 51 // value of the counter. Each thread calling this function |
| 54 // may receive a different location to store it's counter. | 52 // may receive a different location to store it's counter. |
| 55 // The return value must not be cached and re-used across | 53 // The return value must not be cached and re-used across |
| 56 // threads, although a single thread is free to cache it. | 54 // threads, although a single thread is free to cache it. |
| 57 static int *FindLocation(const wchar_t* name) { | 55 static int *FindLocation(const char* name) { |
| 58 if (!lookup_function_) return NULL; | 56 if (!lookup_function_) return NULL; |
| 59 return lookup_function_(name); | 57 return lookup_function_(name); |
| 60 } | 58 } |
| 61 | 59 |
| 62 private: | 60 private: |
| 63 static CounterLookupCallback lookup_function_; | 61 static CounterLookupCallback lookup_function_; |
| 64 }; | 62 }; |
| 65 | 63 |
| 66 // StatsCounters are dynamically created values which can be tracked in | 64 // StatsCounters are dynamically created values which can be tracked in |
| 67 // the StatsTable. They are designed to be lightweight to create and | 65 // the StatsTable. They are designed to be lightweight to create and |
| 68 // easy to use. | 66 // easy to use. |
| 69 // | 67 // |
| 70 // Internally, a counter represents a value in a row of a StatsTable. | 68 // Internally, a counter represents a value in a row of a StatsTable. |
| 71 // The row has a 32bit value for each process/thread in the table and also | 69 // The row has a 32bit value for each process/thread in the table and also |
| 72 // a name (stored in the table metadata). Since the storage location can be | 70 // a name (stored in the table metadata). Since the storage location can be |
| 73 // thread-specific, this class cannot be shared across threads. | 71 // thread-specific, this class cannot be shared across threads. |
| 74 // | 72 // |
| 75 // This class is designed to be POD initialized. It will be registered with | 73 // This class is designed to be POD initialized. It will be registered with |
| 76 // the counter system on first use. For example: | 74 // the counter system on first use. For example: |
| 77 // StatsCounter c = { L"c:myctr", NULL, false }; | 75 // StatsCounter c = { "c:myctr", NULL, false }; |
| 78 struct StatsCounter { | 76 struct StatsCounter { |
| 79 const wchar_t* name_; | 77 const char* name_; |
| 80 int* ptr_; | 78 int* ptr_; |
| 81 bool lookup_done_; | 79 bool lookup_done_; |
| 82 | 80 |
| 83 // Sets the counter to a specific value. | 81 // Sets the counter to a specific value. |
| 84 void Set(int value) { | 82 void Set(int value) { |
| 85 int* loc = GetPtr(); | 83 int* loc = GetPtr(); |
| 86 if (loc) *loc = value; | 84 if (loc) *loc = value; |
| 87 } | 85 } |
| 88 | 86 |
| 89 // Increments the counter. | 87 // Increments the counter. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 rate_->Stop(); | 189 rate_->Stop(); |
| 192 } | 190 } |
| 193 private: | 191 private: |
| 194 StatsRate* rate_; | 192 StatsRate* rate_; |
| 195 }; | 193 }; |
| 196 | 194 |
| 197 | 195 |
| 198 } } // namespace v8::internal | 196 } } // namespace v8::internal |
| 199 | 197 |
| 200 #endif // V8_COUNTERS_H_ | 198 #endif // V8_COUNTERS_H_ |
| OLD | NEW |