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 #ifndef V8_COUNTERS_H_ | 5 #ifndef V8_COUNTERS_H_ |
6 #define V8_COUNTERS_H_ | 6 #define V8_COUNTERS_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
| 10 #include "src/base/atomic-utils.h" |
10 #include "src/base/platform/elapsed-timer.h" | 11 #include "src/base/platform/elapsed-timer.h" |
11 #include "src/base/platform/time.h" | 12 #include "src/base/platform/time.h" |
12 #include "src/builtins/builtins.h" | 13 #include "src/builtins/builtins.h" |
13 #include "src/globals.h" | 14 #include "src/globals.h" |
14 #include "src/isolate.h" | 15 #include "src/isolate.h" |
15 #include "src/objects.h" | 16 #include "src/objects.h" |
16 #include "src/runtime/runtime.h" | 17 #include "src/runtime/runtime.h" |
17 #include "src/tracing/trace-event.h" | 18 #include "src/tracing/trace-event.h" |
18 #include "src/tracing/traced-value.h" | 19 #include "src/tracing/traced-value.h" |
19 | 20 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 490 |
490 const char* name; | 491 const char* name; |
491 int64_t count = 0; | 492 int64_t count = 0; |
492 base::TimeDelta time; | 493 base::TimeDelta time; |
493 }; | 494 }; |
494 | 495 |
495 // RuntimeCallTimer is used to keep track of the stack of currently active | 496 // RuntimeCallTimer is used to keep track of the stack of currently active |
496 // timers used for properly measuring the own time of a RuntimeCallCounter. | 497 // timers used for properly measuring the own time of a RuntimeCallCounter. |
497 class RuntimeCallTimer { | 498 class RuntimeCallTimer { |
498 public: | 499 public: |
499 RuntimeCallTimer() {} | |
500 RuntimeCallCounter* counter() { return counter_; } | 500 RuntimeCallCounter* counter() { return counter_; } |
501 base::ElapsedTimer timer() { return timer_; } | 501 base::ElapsedTimer timer() { return timer_; } |
502 RuntimeCallTimer* parent() const { return parent_; } | 502 RuntimeCallTimer* parent() const { return parent_.Value(); } |
503 | 503 |
504 private: | 504 private: |
505 friend class RuntimeCallStats; | 505 friend class RuntimeCallStats; |
506 | 506 |
507 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) { | 507 inline void Start(RuntimeCallCounter* counter, RuntimeCallTimer* parent) { |
508 counter_ = counter; | 508 counter_ = counter; |
509 parent_ = parent; | 509 parent_.SetValue(parent); |
510 timer_.Start(); | 510 timer_.Start(); |
511 } | 511 } |
512 | 512 |
513 inline RuntimeCallTimer* Stop() { | 513 inline RuntimeCallTimer* Stop() { |
514 base::TimeDelta delta = timer_.Elapsed(); | 514 base::TimeDelta delta = timer_.Elapsed(); |
515 timer_.Stop(); | 515 timer_.Stop(); |
516 counter_->count++; | 516 counter_->count++; |
517 counter_->time += delta; | 517 counter_->time += delta; |
518 if (parent_ != NULL) { | 518 if (parent()) { |
519 // Adjust parent timer so that it does not include sub timer's time. | 519 // Adjust parent timer so that it does not include sub timer's time. |
520 parent_->counter_->time -= delta; | 520 parent()->counter_->time -= delta; |
521 } | 521 } |
522 return parent_; | 522 return parent(); |
523 } | 523 } |
524 | 524 |
525 inline void Elapsed() { | 525 inline void Elapsed() { |
526 base::TimeDelta delta = timer_.Elapsed(); | 526 base::TimeDelta delta = timer_.Elapsed(); |
527 counter_->time += delta; | 527 counter_->time += delta; |
528 if (parent_ != nullptr) { | 528 if (parent()) { |
529 parent_->counter_->time -= delta; | 529 parent()->counter_->time -= delta; |
530 parent_->Elapsed(); | 530 parent()->Elapsed(); |
531 } | 531 } |
532 timer_.Restart(); | 532 timer_.Restart(); |
533 } | 533 } |
534 | 534 |
535 RuntimeCallCounter* counter_ = nullptr; | 535 RuntimeCallCounter* counter_ = nullptr; |
536 RuntimeCallTimer* parent_ = nullptr; | 536 base::AtomicValue<RuntimeCallTimer*> parent_; |
537 base::ElapsedTimer timer_; | 537 base::ElapsedTimer timer_; |
538 }; | 538 }; |
539 | 539 |
540 #define FOR_EACH_API_COUNTER(V) \ | 540 #define FOR_EACH_API_COUNTER(V) \ |
541 V(ArrayBuffer_Cast) \ | 541 V(ArrayBuffer_Cast) \ |
542 V(ArrayBuffer_Neuter) \ | 542 V(ArrayBuffer_Neuter) \ |
543 V(ArrayBuffer_New) \ | 543 V(ArrayBuffer_New) \ |
544 V(Array_CloneElementAt) \ | 544 V(Array_CloneElementAt) \ |
545 V(Array_New) \ | 545 V(Array_New) \ |
546 V(BooleanObject_BooleanValue) \ | 546 V(BooleanObject_BooleanValue) \ |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 824 |
825 void Reset(); | 825 void Reset(); |
826 void Print(std::ostream& os); | 826 void Print(std::ostream& os); |
827 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); | 827 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
828 | 828 |
829 RuntimeCallStats() { | 829 RuntimeCallStats() { |
830 Reset(); | 830 Reset(); |
831 in_use_ = false; | 831 in_use_ = false; |
832 } | 832 } |
833 | 833 |
834 RuntimeCallTimer* current_timer() { return current_timer_; } | 834 RuntimeCallTimer* current_timer() { return current_timer_.Value(); } |
835 bool InUse() { return in_use_; } | 835 bool InUse() { return in_use_; } |
836 | 836 |
837 private: | 837 private: |
838 // Counter to track recursive time events. | 838 // Counter to track recursive time events. |
839 RuntimeCallTimer* current_timer_ = NULL; | 839 base::AtomicValue<RuntimeCallTimer*> current_timer_; |
840 // Used to track nested tracing scopes. | 840 // Used to track nested tracing scopes. |
841 bool in_use_; | 841 bool in_use_; |
842 }; | 842 }; |
843 | 843 |
844 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ | 844 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ |
845 do { \ | 845 do { \ |
846 if (RuntimeCallStats::IsEnabled()) { \ | 846 if (RuntimeCallStats::IsEnabled()) { \ |
847 RuntimeCallStats::CorrectCurrentCounterId( \ | 847 RuntimeCallStats::CorrectCurrentCounterId( \ |
848 isolate->counters()->runtime_call_stats(), \ | 848 isolate->counters()->runtime_call_stats(), \ |
849 &RuntimeCallStats::counter_name); \ | 849 &RuntimeCallStats::counter_name); \ |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 } | 1291 } |
1292 | 1292 |
1293 Isolate* isolate_ = nullptr; | 1293 Isolate* isolate_ = nullptr; |
1294 RuntimeCallTimer timer_; | 1294 RuntimeCallTimer timer_; |
1295 }; | 1295 }; |
1296 | 1296 |
1297 } // namespace internal | 1297 } // namespace internal |
1298 } // namespace v8 | 1298 } // namespace v8 |
1299 | 1299 |
1300 #endif // V8_COUNTERS_H_ | 1300 #endif // V8_COUNTERS_H_ |
OLD | NEW |