OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 #include "src/counters.h" | 5 #include "src/counters.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 count = 0; | 275 count = 0; |
276 time = base::TimeDelta(); | 276 time = base::TimeDelta(); |
277 } | 277 } |
278 | 278 |
279 void RuntimeCallCounter::Dump(std::stringstream& out) { | 279 void RuntimeCallCounter::Dump(std::stringstream& out) { |
280 out << "\"" << name << "\":[" << count << "," << time.InMicroseconds() | 280 out << "\"" << name << "\":[" << count << "," << time.InMicroseconds() |
281 << "],"; | 281 << "],"; |
282 } | 282 } |
283 | 283 |
284 // static | 284 // static |
285 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, | 285 void RuntimeCallStats::Enter(Isolate* isolate, RuntimeCallTimer* timer, |
286 CounterId counter_id) { | 286 CounterId counter_id) { |
| 287 RuntimeCallStats* stats = isolate->counters()->runtime_call_stats(); |
287 RuntimeCallCounter* counter = &(stats->*counter_id); | 288 RuntimeCallCounter* counter = &(stats->*counter_id); |
288 timer->Start(counter, stats->current_timer_); | 289 timer->Start(counter, stats->current_timer_); |
289 stats->current_timer_ = timer; | 290 stats->current_timer_ = timer; |
290 } | 291 } |
291 | 292 |
292 // static | 293 // static |
293 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { | 294 void RuntimeCallStats::Leave(Isolate* isolate, RuntimeCallTimer* timer) { |
| 295 RuntimeCallStats* stats = isolate->counters()->runtime_call_stats(); |
| 296 |
294 if (stats->current_timer_ == timer) { | 297 if (stats->current_timer_ == timer) { |
295 stats->current_timer_ = timer->Stop(); | 298 stats->current_timer_ = timer->Stop(); |
296 } else { | 299 } else { |
297 // Must be a Threading cctest. Walk the chain of Timers to find the | 300 // Must be a Threading cctest. Walk the chain of Timers to find the |
298 // buried one that's leaving. We don't care about keeping nested timings | 301 // buried one that's leaving. We don't care about keeping nested timings |
299 // accurate, just avoid crashing by keeping the chain intact. | 302 // accurate, just avoid crashing by keeping the chain intact. |
300 RuntimeCallTimer* next = stats->current_timer_; | 303 RuntimeCallTimer* next = stats->current_timer_; |
301 while (next->parent_ != timer) next = next->parent_; | 304 while (next->parent_ != timer) next = next->parent_; |
302 next->parent_ = timer->Stop(); | 305 next->parent_ = timer->Stop(); |
303 } | 306 } |
304 } | 307 } |
305 | 308 |
306 // static | 309 // static |
307 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, | 310 void RuntimeCallStats::CorrectCurrentCounterId(Isolate* isolate, |
308 CounterId counter_id) { | 311 CounterId counter_id) { |
| 312 RuntimeCallStats* stats = isolate->counters()->runtime_call_stats(); |
309 DCHECK_NOT_NULL(stats->current_timer_); | 313 DCHECK_NOT_NULL(stats->current_timer_); |
310 RuntimeCallCounter* counter = &(stats->*counter_id); | 314 RuntimeCallCounter* counter = &(stats->*counter_id); |
311 stats->current_timer_->counter_ = counter; | 315 stats->current_timer_->counter_ = counter; |
312 } | 316 } |
313 | 317 |
314 void RuntimeCallStats::Print(std::ostream& os) { | 318 void RuntimeCallStats::Print(std::ostream& os) { |
315 RuntimeCallStatEntries entries; | 319 RuntimeCallStatEntries entries; |
316 | 320 |
317 #define PRINT_COUNTER(name) entries.Add(&this->name); | 321 #define PRINT_COUNTER(name) entries.Add(&this->name); |
318 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) | 322 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 357 |
354 #define RESET_COUNTER(name) this->API_##name.Reset(); | 358 #define RESET_COUNTER(name) this->API_##name.Reset(); |
355 FOR_EACH_API_COUNTER(RESET_COUNTER) | 359 FOR_EACH_API_COUNTER(RESET_COUNTER) |
356 #undef RESET_COUNTER | 360 #undef RESET_COUNTER |
357 | 361 |
358 #define RESET_COUNTER(name) this->Handler_##name.Reset(); | 362 #define RESET_COUNTER(name) this->Handler_##name.Reset(); |
359 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) | 363 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) |
360 #undef RESET_COUNTER | 364 #undef RESET_COUNTER |
361 } | 365 } |
362 | 366 |
363 const char* RuntimeCallStats::Dump() { | |
364 buffer_.str(std::string()); | |
365 buffer_.clear(); | |
366 buffer_ << "{"; | |
367 #define DUMP_COUNTER(name) \ | |
368 if (this->name.count > 0) this->name.Dump(buffer_); | |
369 FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) | |
370 #undef DUMP_COUNTER | |
371 | |
372 #define DUMP_COUNTER(name, nargs, result_size) \ | |
373 if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(buffer_); | |
374 FOR_EACH_INTRINSIC(DUMP_COUNTER) | |
375 #undef DUMP_COUNTER | |
376 | |
377 #define DUMP_COUNTER(name) \ | |
378 if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(buffer_); | |
379 BUILTIN_LIST_C(DUMP_COUNTER) | |
380 #undef DUMP_COUNTER | |
381 | |
382 #define DUMP_COUNTER(name) \ | |
383 if (this->API_##name.count > 0) this->API_##name.Dump(buffer_); | |
384 FOR_EACH_API_COUNTER(DUMP_COUNTER) | |
385 #undef DUMP_COUNTER | |
386 | |
387 #define DUMP_COUNTER(name) \ | |
388 if (this->Handler_##name.count > 0) this->Handler_##name.Dump(buffer_); | |
389 FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER) | |
390 #undef DUMP_COUNTER | |
391 buffer_ << "\"END\":[]}"; | |
392 const std::string& buffer_str = buffer_.str(); | |
393 size_t length = buffer_str.size(); | |
394 if (length > len_) { | |
395 buffer_c_str_.reset(new char[length + 1]); | |
396 len_ = length; | |
397 } | |
398 strncpy(buffer_c_str_.get(), buffer_str.c_str(), length + 1); | |
399 in_use_ = false; | |
400 return buffer_c_str_.get(); | |
401 } | |
402 | |
403 } // namespace internal | 367 } // namespace internal |
404 } // namespace v8 | 368 } // namespace v8 |
OLD | NEW |