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(Isolate* isolate, RuntimeCallTimer* timer, | 285 void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
286 CounterId counter_id) { | 286 CounterId counter_id) { |
287 RuntimeCallStats* stats = isolate->counters()->runtime_call_stats(); | |
288 RuntimeCallCounter* counter = &(stats->*counter_id); | 287 RuntimeCallCounter* counter = &(stats->*counter_id); |
289 timer->Start(counter, stats->current_timer_); | 288 timer->Start(counter, stats->current_timer_); |
290 stats->current_timer_ = timer; | 289 stats->current_timer_ = timer; |
291 } | 290 } |
292 | 291 |
293 // static | 292 // static |
294 void RuntimeCallStats::Leave(Isolate* isolate, RuntimeCallTimer* timer) { | 293 void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { |
295 RuntimeCallStats* stats = isolate->counters()->runtime_call_stats(); | |
296 | |
297 if (stats->current_timer_ == timer) { | 294 if (stats->current_timer_ == timer) { |
298 stats->current_timer_ = timer->Stop(); | 295 stats->current_timer_ = timer->Stop(); |
299 } else { | 296 } else { |
300 // Must be a Threading cctest. Walk the chain of Timers to find the | 297 // Must be a Threading cctest. Walk the chain of Timers to find the |
301 // buried one that's leaving. We don't care about keeping nested timings | 298 // buried one that's leaving. We don't care about keeping nested timings |
302 // accurate, just avoid crashing by keeping the chain intact. | 299 // accurate, just avoid crashing by keeping the chain intact. |
303 RuntimeCallTimer* next = stats->current_timer_; | 300 RuntimeCallTimer* next = stats->current_timer_; |
304 while (next->parent_ != timer) next = next->parent_; | 301 while (next->parent_ != timer) next = next->parent_; |
305 next->parent_ = timer->Stop(); | 302 next->parent_ = timer->Stop(); |
306 } | 303 } |
307 } | 304 } |
308 | 305 |
309 // static | 306 // static |
310 void RuntimeCallStats::CorrectCurrentCounterId(Isolate* isolate, | 307 void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, |
311 CounterId counter_id) { | 308 CounterId counter_id) { |
312 RuntimeCallStats* stats = isolate->counters()->runtime_call_stats(); | |
313 DCHECK_NOT_NULL(stats->current_timer_); | 309 DCHECK_NOT_NULL(stats->current_timer_); |
314 RuntimeCallCounter* counter = &(stats->*counter_id); | 310 RuntimeCallCounter* counter = &(stats->*counter_id); |
315 stats->current_timer_->counter_ = counter; | 311 stats->current_timer_->counter_ = counter; |
316 } | 312 } |
317 | 313 |
318 void RuntimeCallStats::Print(std::ostream& os) { | 314 void RuntimeCallStats::Print(std::ostream& os) { |
319 RuntimeCallStatEntries entries; | 315 RuntimeCallStatEntries entries; |
320 | 316 |
321 #define PRINT_COUNTER(name) entries.Add(&this->name); | 317 #define PRINT_COUNTER(name) entries.Add(&this->name); |
322 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) | 318 FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 353 |
358 #define RESET_COUNTER(name) this->API_##name.Reset(); | 354 #define RESET_COUNTER(name) this->API_##name.Reset(); |
359 FOR_EACH_API_COUNTER(RESET_COUNTER) | 355 FOR_EACH_API_COUNTER(RESET_COUNTER) |
360 #undef RESET_COUNTER | 356 #undef RESET_COUNTER |
361 | 357 |
362 #define RESET_COUNTER(name) this->Handler_##name.Reset(); | 358 #define RESET_COUNTER(name) this->Handler_##name.Reset(); |
363 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) | 359 FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) |
364 #undef RESET_COUNTER | 360 #undef RESET_COUNTER |
365 } | 361 } |
366 | 362 |
| 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 |
367 } // namespace internal | 403 } // namespace internal |
368 } // namespace v8 | 404 } // namespace v8 |
OLD | NEW |