Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
|
Michael Starzinger
2012/07/02 21:09:56
2012
jochen (gone - plz use gerrit)
2012/07/13 09:48:08
Done.
| |
| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 int* GetInternalPointer() { | 163 int* GetInternalPointer() { |
| 164 int* loc = GetPtr(); | 164 int* loc = GetPtr(); |
| 165 ASSERT(loc != NULL); | 165 ASSERT(loc != NULL); |
| 166 return loc; | 166 return loc; |
| 167 } | 167 } |
| 168 | 168 |
| 169 protected: | 169 protected: |
| 170 // Returns the cached address of this counter location. | 170 // Returns the cached address of this counter location. |
| 171 int* GetPtr() { | 171 int* GetPtr() { |
| 172 if (lookup_done_) | 172 if (lookup_done_) |
| 173 return ptr_; | 173 return ptr_; |
|
Michael Starzinger
2012/07/02 21:09:56
Aww, that should be on one line.
jochen (gone - plz use gerrit)
2012/07/13 09:48:08
Done.
| |
| 174 lookup_done_ = true; | 174 lookup_done_ = true; |
| 175 ptr_ = FindLocationInStatsTable(); | 175 ptr_ = FindLocationInStatsTable(); |
| 176 return ptr_; | 176 return ptr_; |
| 177 } | 177 } |
| 178 | 178 |
| 179 private: | 179 private: |
| 180 int* FindLocationInStatsTable() const; | 180 int* FindLocationInStatsTable() const; |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 // StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 }; | 183 // StatsCounterTimer t = { { L"t:foo", NULL, false }, 0, 0 }; |
| 184 struct StatsCounterTimer { | 184 struct StatsCounterTimer { |
| 185 StatsCounter counter_; | 185 StatsCounter counter_; |
| 186 | 186 |
| 187 int64_t start_time_; | 187 int64_t start_time_; |
| 188 int64_t stop_time_; | 188 int64_t stop_time_; |
| 189 | 189 |
| 190 // Start the timer. | 190 // Start the timer. |
| 191 void Start(); | 191 void Start(); |
| 192 | 192 |
| 193 // Stop the timer and record the results. | 193 // Stop the timer and record the results. |
| 194 void Stop(); | 194 void Stop(); |
| 195 | 195 |
| 196 // Returns true if the timer is running. | 196 // Returns true if the timer is running. |
| 197 bool Running() { | 197 bool Running() { |
| 198 return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0; | 198 return counter_.Enabled() && start_time_ != 0 && stop_time_ == 0; |
| 199 } | 199 } |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 // A HistogramTimer allows distributions of results to be created | 202 // Similar to StatsCounter, the class Histogram represents a dynamically |
|
Michael Starzinger
2012/07/02 21:09:56
Can we remove the reference to StatsCounter here?
jochen (gone - plz use gerrit)
2012/07/13 09:48:08
Done.
| |
| 203 // HistogramTimer t = { L"foo", NULL, false, 0, 0 }; | 203 // created histogram in the StatsTable. |
| 204 struct HistogramTimer { | 204 // |
| 205 // This class is designed to be POD initialized. It will be registered with | |
| 206 // the histogram system on first use. For example: | |
| 207 // Histogram h = { "myhist", 0, 10000, 50, NULL, false }; | |
| 208 struct Histogram { | |
| 205 const char* name_; | 209 const char* name_; |
| 210 int min_; | |
| 211 int max_; | |
| 212 int num_buckets_; | |
| 206 void* histogram_; | 213 void* histogram_; |
| 207 bool lookup_done_; | 214 bool lookup_done_; |
| 208 | 215 |
| 209 int64_t start_time_; | 216 // Add a single sample to this histogram. |
| 210 int64_t stop_time_; | 217 void AddSample(int sample); |
| 211 | 218 |
| 212 // Start the timer. | 219 // Is this histogram enabled? |
| 213 void Start(); | 220 // Returns false if table is full. |
|
Michael Starzinger
2012/07/02 21:09:56
Let's turn that into just one line: "Returns true
jochen (gone - plz use gerrit)
2012/07/13 09:48:08
Done.
| |
| 214 | 221 bool Enabled() { |
| 215 // Stop the timer and record the results. | 222 return GetHistogram() != NULL; |
| 216 void Stop(); | |
| 217 | |
| 218 // Returns true if the timer is running. | |
| 219 bool Running() { | |
| 220 return (histogram_ != NULL) && (start_time_ != 0) && (stop_time_ == 0); | |
| 221 } | 223 } |
| 222 | 224 |
| 223 protected: | 225 protected: |
| 224 // Returns the handle to the histogram. | 226 // Returns the handle to the histogram. |
| 225 void* GetHistogram() { | 227 void* GetHistogram() { |
| 226 if (!lookup_done_) { | 228 if (!lookup_done_) { |
| 227 lookup_done_ = true; | 229 lookup_done_ = true; |
| 228 histogram_ = CreateHistogram(); | 230 histogram_ = CreateHistogram(); |
| 229 } | 231 } |
| 230 return histogram_; | 232 return histogram_; |
| 231 } | 233 } |
| 232 | 234 |
| 233 private: | 235 private: |
| 234 void* CreateHistogram() const; | 236 void* CreateHistogram() const; |
| 235 }; | 237 }; |
| 236 | 238 |
| 239 // A HistogramTimer allows distributions of results to be created | |
| 240 // HistogramTimer t = { {L"foo", 0, 10000, 50, NULL, false}, 0, 0 }; | |
| 241 struct HistogramTimer { | |
| 242 Histogram histogram_; | |
| 243 | |
| 244 int64_t start_time_; | |
| 245 int64_t stop_time_; | |
| 246 | |
| 247 // Start the timer. | |
| 248 void Start(); | |
| 249 | |
| 250 // Stop the timer and record the results. | |
| 251 void Stop(); | |
| 252 | |
| 253 // Returns true if the timer is running. | |
| 254 bool Running() { | |
| 255 return histogram_.Enabled() && (start_time_ != 0) && (stop_time_ == 0); | |
| 256 } | |
| 257 }; | |
| 258 | |
| 237 // Helper class for scoping a HistogramTimer. | 259 // Helper class for scoping a HistogramTimer. |
| 238 class HistogramTimerScope BASE_EMBEDDED { | 260 class HistogramTimerScope BASE_EMBEDDED { |
| 239 public: | 261 public: |
| 240 explicit HistogramTimerScope(HistogramTimer* timer) : | 262 explicit HistogramTimerScope(HistogramTimer* timer) : |
| 241 timer_(timer) { | 263 timer_(timer) { |
| 242 timer_->Start(); | 264 timer_->Start(); |
| 243 } | 265 } |
| 244 ~HistogramTimerScope() { | 266 ~HistogramTimerScope() { |
| 245 timer_->Stop(); | 267 timer_->Stop(); |
| 246 } | 268 } |
| 247 private: | 269 private: |
| 248 HistogramTimer* timer_; | 270 HistogramTimer* timer_; |
| 249 }; | 271 }; |
| 250 | 272 |
| 251 | 273 |
| 252 } } // namespace v8::internal | 274 } } // namespace v8::internal |
| 253 | 275 |
| 254 #endif // V8_COUNTERS_H_ | 276 #endif // V8_COUNTERS_H_ |
| OLD | NEW |