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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // StatsCounter represents a counter in the StatsTable class. | 84 // StatsCounter represents a counter in the StatsTable class. |
85 class StatsCounter BASE_EMBEDDED { | 85 class StatsCounter BASE_EMBEDDED { |
86 public: | 86 public: |
87 // Create a StatsCounter object. | 87 // Create a StatsCounter object. |
88 explicit StatsCounter(const wchar_t* name, int id) : | 88 explicit StatsCounter(const wchar_t* name, int id) : |
89 lookup_done_(false), | 89 lookup_done_(false), |
90 ptr_(NULL), | 90 ptr_(NULL), |
91 id_(id) { | 91 id_(id) { |
92 int len = wcslen(name); | 92 int len = wcslen(name); |
93 // we prepend the name with 'c:' to indicate that it is a counter. | 93 // we prepend the name with 'c:' to indicate that it is a counter. |
94 name_ = NewArray<wchar_t>(len+3); | 94 name_ = Vector<wchar_t>::New(len+3); |
95 wcscpy(name_, L"c:"); | 95 OS::WcsCpy(name_, L"c:"); |
96 wcscpy(&name_[2], name); | 96 OS::WcsCpy(name_ + 2, name); |
97 }; | 97 }; |
98 | 98 |
99 ~StatsCounter() { | 99 ~StatsCounter() { |
100 DeleteArray(name_); | 100 name_.Dispose(); |
101 } | 101 } |
102 | 102 |
103 // Sets the counter to a specific value. | 103 // Sets the counter to a specific value. |
104 void Set(int value) { | 104 void Set(int value) { |
105 int* loc = GetPtr(); | 105 int* loc = GetPtr(); |
106 if (loc) *loc = value; | 106 if (loc) *loc = value; |
107 } | 107 } |
108 | 108 |
109 // Increments the counter. | 109 // Increments the counter. |
110 void Increment() { | 110 void Increment() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 StatsCounter() : | 152 StatsCounter() : |
153 lookup_done_(false), | 153 lookup_done_(false), |
154 ptr_(NULL) { | 154 ptr_(NULL) { |
155 } | 155 } |
156 | 156 |
157 // Returns the cached address of this counter location. | 157 // Returns the cached address of this counter location. |
158 int* GetPtr() { | 158 int* GetPtr() { |
159 if (lookup_done_) | 159 if (lookup_done_) |
160 return ptr_; | 160 return ptr_; |
161 lookup_done_ = true; | 161 lookup_done_ = true; |
162 ptr_ = StatsTable::FindLocation(name_); | 162 ptr_ = StatsTable::FindLocation(name_.start()); |
163 return ptr_; | 163 return ptr_; |
164 } | 164 } |
165 | 165 |
166 wchar_t* name_; | 166 Vector<wchar_t> name_; |
167 bool lookup_done_; | 167 bool lookup_done_; |
168 int* ptr_; | 168 int* ptr_; |
169 int id_; | 169 int id_; |
170 }; | 170 }; |
171 | 171 |
172 // A StatsCounterTimer is a StatsCounter which keeps a timer during | 172 // A StatsCounterTimer is a StatsCounter which keeps a timer during |
173 // the scope of the StatsCounterTimer. On destruction, it will record | 173 // the scope of the StatsCounterTimer. On destruction, it will record |
174 // its time measurement. | 174 // its time measurement. |
175 class StatsCounterTimer : StatsCounter { | 175 class StatsCounterTimer : StatsCounter { |
176 public: | 176 public: |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 rate_->Stop(); | 258 rate_->Stop(); |
259 } | 259 } |
260 private: | 260 private: |
261 StatsRate* rate_; | 261 StatsRate* rate_; |
262 }; | 262 }; |
263 | 263 |
264 | 264 |
265 } } // namespace v8::internal | 265 } } // namespace v8::internal |
266 | 266 |
267 #endif // V8_COUNTERS_H_ | 267 #endif // V8_COUNTERS_H_ |
OLD | NEW |