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/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
11 #include "src/base/platform/time.h" | 11 #include "src/base/platform/time.h" |
12 #include "src/builtins/builtins.h" | 12 #include "src/builtins/builtins.h" |
13 #include "src/globals.h" | 13 #include "src/globals.h" |
14 #include "src/isolate.h" | 14 #include "src/isolate.h" |
15 #include "src/objects.h" | 15 #include "src/objects.h" |
16 #include "src/runtime/runtime.h" | 16 #include "src/runtime/runtime.h" |
17 #include "src/tracing/trace-event.h" | 17 #include "src/tracing/trace-event.h" |
| 18 #include "src/tracing/traced-value.h" |
18 | 19 |
19 namespace v8 { | 20 namespace v8 { |
20 namespace internal { | 21 namespace internal { |
21 | 22 |
22 // StatsCounters is an interface for plugging into external | 23 // StatsCounters is an interface for plugging into external |
23 // counters for monitoring. Counters can be looked up and | 24 // counters for monitoring. Counters can be looked up and |
24 // manipulated by name. | 25 // manipulated by name. |
25 | 26 |
26 class StatsTable { | 27 class StatsTable { |
27 public: | 28 public: |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 // The aggregate_value_ is the average for [start_ms_; last_ms_]. | 478 // The aggregate_value_ is the average for [start_ms_; last_ms_]. |
478 // The value is the average for [last_ms_; current_ms]. | 479 // The value is the average for [last_ms_; current_ms]. |
479 // Return the weighted average of the aggregate_value_ and the value. | 480 // Return the weighted average of the aggregate_value_ and the value. |
480 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + | 481 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + |
481 value * ((current_ms - last_ms_) / interval_ms); | 482 value * ((current_ms - last_ms_) / interval_ms); |
482 } | 483 } |
483 | 484 |
484 struct RuntimeCallCounter { | 485 struct RuntimeCallCounter { |
485 explicit RuntimeCallCounter(const char* name) : name(name) {} | 486 explicit RuntimeCallCounter(const char* name) : name(name) {} |
486 V8_NOINLINE void Reset(); | 487 V8_NOINLINE void Reset(); |
487 V8_NOINLINE void Dump(std::stringstream& out); | 488 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
488 | 489 |
489 const char* name; | 490 const char* name; |
490 int64_t count = 0; | 491 int64_t count = 0; |
491 base::TimeDelta time; | 492 base::TimeDelta time; |
492 }; | 493 }; |
493 | 494 |
494 // RuntimeCallTimer is used to keep track of the stack of currently active | 495 // RuntimeCallTimer is used to keep track of the stack of currently active |
495 // timers used for properly measuring the own time of a RuntimeCallCounter. | 496 // timers used for properly measuring the own time of a RuntimeCallCounter. |
496 class RuntimeCallTimer { | 497 class RuntimeCallTimer { |
497 public: | 498 public: |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 // parent. | 793 // parent. |
793 static void Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer); | 794 static void Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer); |
794 | 795 |
795 // Set counter id for the innermost measurement. It can be used to refine | 796 // Set counter id for the innermost measurement. It can be used to refine |
796 // event kind when a runtime entry counter is too generic. | 797 // event kind when a runtime entry counter is too generic. |
797 static void CorrectCurrentCounterId(RuntimeCallStats* stats, | 798 static void CorrectCurrentCounterId(RuntimeCallStats* stats, |
798 CounterId counter_id); | 799 CounterId counter_id); |
799 | 800 |
800 void Reset(); | 801 void Reset(); |
801 void Print(std::ostream& os); | 802 void Print(std::ostream& os); |
802 std::string Dump(); | 803 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
803 | 804 |
804 RuntimeCallStats() { | 805 RuntimeCallStats() { |
805 Reset(); | 806 Reset(); |
806 in_use_ = false; | 807 in_use_ = false; |
807 } | 808 } |
808 | 809 |
809 RuntimeCallTimer* current_timer() { return current_timer_; } | 810 RuntimeCallTimer* current_timer() { return current_timer_; } |
810 bool InUse() { return in_use_; } | 811 bool InUse() { return in_use_; } |
811 | 812 |
812 private: | 813 private: |
813 std::stringstream buffer_; | |
814 // Counter to track recursive time events. | 814 // Counter to track recursive time events. |
815 RuntimeCallTimer* current_timer_ = NULL; | 815 RuntimeCallTimer* current_timer_ = NULL; |
816 // Used to track nested tracing scopes. | 816 // Used to track nested tracing scopes. |
817 bool in_use_; | 817 bool in_use_; |
818 }; | 818 }; |
819 | 819 |
820 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ | 820 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ |
821 do { \ | 821 do { \ |
822 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() || \ | 822 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() || \ |
823 FLAG_runtime_call_stats)) { \ | 823 FLAG_runtime_call_stats)) { \ |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 } | 1272 } |
1273 | 1273 |
1274 Isolate* isolate_ = nullptr; | 1274 Isolate* isolate_ = nullptr; |
1275 RuntimeCallTimer timer_; | 1275 RuntimeCallTimer timer_; |
1276 }; | 1276 }; |
1277 | 1277 |
1278 } // namespace internal | 1278 } // namespace internal |
1279 } // namespace v8 | 1279 } // namespace v8 |
1280 | 1280 |
1281 #endif // V8_COUNTERS_H_ | 1281 #endif // V8_COUNTERS_H_ |
OLD | NEW |