| 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 void Reset(); | 487 void Reset(); |
| 487 V8_NOINLINE void Dump(std::stringstream& out); | |
| 488 | 488 |
| 489 const char* name; | 489 const char* name; |
| 490 int64_t count = 0; | 490 int64_t count = 0; |
| 491 base::TimeDelta time; | 491 base::TimeDelta time; |
| 492 }; | 492 }; |
| 493 | 493 |
| 494 // RuntimeCallTimer is used to keep track of the stack of currently active | 494 // RuntimeCallTimer is used to keep track of the stack of currently active |
| 495 // timers used for properly measuring the own time of a RuntimeCallCounter. | 495 // timers used for properly measuring the own time of a RuntimeCallCounter. |
| 496 class RuntimeCallTimer { | 496 class RuntimeCallTimer { |
| 497 public: | 497 public: |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 // parent. | 792 // parent. |
| 793 static void Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer); | 793 static void Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer); |
| 794 | 794 |
| 795 // Set counter id for the innermost measurement. It can be used to refine | 795 // Set counter id for the innermost measurement. It can be used to refine |
| 796 // event kind when a runtime entry counter is too generic. | 796 // event kind when a runtime entry counter is too generic. |
| 797 static void CorrectCurrentCounterId(RuntimeCallStats* stats, | 797 static void CorrectCurrentCounterId(RuntimeCallStats* stats, |
| 798 CounterId counter_id); | 798 CounterId counter_id); |
| 799 | 799 |
| 800 void Reset(); | 800 void Reset(); |
| 801 V8_NOINLINE void Print(std::ostream& os); | 801 V8_NOINLINE void Print(std::ostream& os); |
| 802 V8_NOINLINE std::string Dump(); | 802 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
| 803 | 803 |
| 804 RuntimeCallStats() { | 804 RuntimeCallStats() { |
| 805 Reset(); | 805 Reset(); |
| 806 in_use_ = false; | 806 in_use_ = false; |
| 807 } | 807 } |
| 808 | 808 |
| 809 RuntimeCallTimer* current_timer() { return current_timer_; } | 809 RuntimeCallTimer* current_timer() { return current_timer_; } |
| 810 bool InUse() { return in_use_; } | 810 bool InUse() { return in_use_; } |
| 811 | 811 |
| 812 private: | 812 private: |
| 813 std::stringstream buffer_; | |
| 814 // Counter to track recursive time events. | 813 // Counter to track recursive time events. |
| 815 RuntimeCallTimer* current_timer_ = NULL; | 814 RuntimeCallTimer* current_timer_ = NULL; |
| 816 // Used to track nested tracing scopes. | 815 // Used to track nested tracing scopes. |
| 817 bool in_use_; | 816 bool in_use_; |
| 818 }; | 817 }; |
| 819 | 818 |
| 820 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ | 819 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ |
| 821 do { \ | 820 do { \ |
| 822 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() || \ | 821 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() || \ |
| 823 FLAG_runtime_call_stats)) { \ | 822 FLAG_runtime_call_stats)) { \ |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 } | 1271 } |
| 1273 | 1272 |
| 1274 Isolate* isolate_ = nullptr; | 1273 Isolate* isolate_ = nullptr; |
| 1275 RuntimeCallTimer timer_; | 1274 RuntimeCallTimer timer_; |
| 1276 }; | 1275 }; |
| 1277 | 1276 |
| 1278 } // namespace internal | 1277 } // namespace internal |
| 1279 } // namespace v8 | 1278 } // namespace v8 |
| 1280 | 1279 |
| 1281 #endif // V8_COUNTERS_H_ | 1280 #endif // V8_COUNTERS_H_ |
| OLD | NEW |