| 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/atomic-utils.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 double value = (current_value + last_value_) / 2; | 479 double value = (current_value + last_value_) / 2; |
| 480 // The aggregate_value_ is the average for [start_ms_; last_ms_]. | 480 // The aggregate_value_ is the average for [start_ms_; last_ms_]. |
| 481 // The value is the average for [last_ms_; current_ms]. | 481 // The value is the average for [last_ms_; current_ms]. |
| 482 // Return the weighted average of the aggregate_value_ and the value. | 482 // Return the weighted average of the aggregate_value_ and the value. |
| 483 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + | 483 return aggregate_value_ * ((last_ms_ - start_ms_) / interval_ms) + |
| 484 value * ((current_ms - last_ms_) / interval_ms); | 484 value * ((current_ms - last_ms_) / interval_ms); |
| 485 } | 485 } |
| 486 | 486 |
| 487 class RuntimeCallCounter final { | 487 class RuntimeCallCounter final { |
| 488 public: | 488 public: |
| 489 explicit RuntimeCallCounter(const char* name) : name_(name) {} | 489 explicit RuntimeCallCounter(const char* name) |
| 490 : name_(name), count_(0), time_(0) {} |
| 490 V8_NOINLINE void Reset(); | 491 V8_NOINLINE void Reset(); |
| 491 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); | 492 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
| 492 void Add(RuntimeCallCounter* other); | 493 void Add(RuntimeCallCounter* other); |
| 493 | 494 |
| 494 const char* name() const { return name_; } | 495 const char* name() const { return name_; } |
| 495 int64_t count() const { return count_; } | 496 int64_t count() const { return count_; } |
| 496 base::TimeDelta time() const { return time_; } | 497 base::TimeDelta time() const { |
| 498 return base::TimeDelta::FromMicroseconds(time_); |
| 499 } |
| 497 void Increment() { count_++; } | 500 void Increment() { count_++; } |
| 498 void Add(base::TimeDelta delta) { time_ += delta; } | 501 void Add(base::TimeDelta delta) { time_ += delta.InMicroseconds(); } |
| 499 | 502 |
| 500 private: | 503 private: |
| 504 RuntimeCallCounter() {} |
| 505 |
| 501 const char* name_; | 506 const char* name_; |
| 502 int64_t count_ = 0; | 507 int64_t count_; |
| 503 base::TimeDelta time_; | 508 // Stored as int64_t so that its initialization can be deferred. |
| 509 int64_t time_; |
| 510 |
| 511 friend class RuntimeCallStats; |
| 504 }; | 512 }; |
| 505 | 513 |
| 506 // RuntimeCallTimer is used to keep track of the stack of currently active | 514 // RuntimeCallTimer is used to keep track of the stack of currently active |
| 507 // timers used for properly measuring the own time of a RuntimeCallCounter. | 515 // timers used for properly measuring the own time of a RuntimeCallCounter. |
| 508 class RuntimeCallTimer final { | 516 class RuntimeCallTimer final { |
| 509 public: | 517 public: |
| 510 RuntimeCallCounter* counter() { return counter_; } | 518 RuntimeCallCounter* counter() { return counter_; } |
| 511 void set_counter(RuntimeCallCounter* counter) { counter_ = counter; } | 519 void set_counter(RuntimeCallCounter* counter) { counter_ = counter; } |
| 512 RuntimeCallTimer* parent() const { return parent_.Value(); } | 520 RuntimeCallTimer* parent() const { return parent_.Value(); } |
| 513 void set_parent(RuntimeCallTimer* timer) { parent_.SetValue(timer); } | 521 void set_parent(RuntimeCallTimer* timer) { parent_.SetValue(timer); } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 V(StoreIC_StoreInterceptorStub) \ | 827 V(StoreIC_StoreInterceptorStub) \ |
| 820 V(StoreIC_StoreNormalDH) \ | 828 V(StoreIC_StoreNormalDH) \ |
| 821 V(StoreIC_StoreScriptContextFieldStub) \ | 829 V(StoreIC_StoreScriptContextFieldStub) \ |
| 822 V(StoreIC_StoreTransition) \ | 830 V(StoreIC_StoreTransition) \ |
| 823 V(StoreIC_StoreTransitionDH) \ | 831 V(StoreIC_StoreTransitionDH) \ |
| 824 V(StoreIC_StoreViaSetter) | 832 V(StoreIC_StoreViaSetter) |
| 825 | 833 |
| 826 class RuntimeCallStats final : public ZoneObject { | 834 class RuntimeCallStats final : public ZoneObject { |
| 827 public: | 835 public: |
| 828 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; | 836 typedef RuntimeCallCounter RuntimeCallStats::*CounterId; |
| 837 V8_EXPORT_PRIVATE RuntimeCallStats(); |
| 829 | 838 |
| 830 #define CALL_RUNTIME_COUNTER(name) \ | 839 #define CALL_RUNTIME_COUNTER(name) RuntimeCallCounter name; |
| 831 RuntimeCallCounter name = RuntimeCallCounter(#name); | |
| 832 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) | 840 FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) |
| 833 #undef CALL_RUNTIME_COUNTER | 841 #undef CALL_RUNTIME_COUNTER |
| 834 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ | 842 #define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
| 835 RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); | 843 RuntimeCallCounter Runtime_##name; |
| 836 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) | 844 FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) |
| 837 #undef CALL_RUNTIME_COUNTER | 845 #undef CALL_RUNTIME_COUNTER |
| 838 #define CALL_BUILTIN_COUNTER(name) \ | 846 #define CALL_BUILTIN_COUNTER(name) RuntimeCallCounter Builtin_##name; |
| 839 RuntimeCallCounter Builtin_##name = RuntimeCallCounter(#name); | |
| 840 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) | 847 BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) |
| 841 #undef CALL_BUILTIN_COUNTER | 848 #undef CALL_BUILTIN_COUNTER |
| 842 #define CALL_BUILTIN_COUNTER(name) \ | 849 #define CALL_BUILTIN_COUNTER(name) RuntimeCallCounter API_##name; |
| 843 RuntimeCallCounter API_##name = RuntimeCallCounter("API_" #name); | |
| 844 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) | 850 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) |
| 845 #undef CALL_BUILTIN_COUNTER | 851 #undef CALL_BUILTIN_COUNTER |
| 846 #define CALL_BUILTIN_COUNTER(name) \ | 852 #define CALL_BUILTIN_COUNTER(name) RuntimeCallCounter Handler_##name; |
| 847 RuntimeCallCounter Handler_##name = RuntimeCallCounter(#name); | |
| 848 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) | 853 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) |
| 849 #undef CALL_BUILTIN_COUNTER | 854 #undef CALL_BUILTIN_COUNTER |
| 850 | 855 |
| 851 static const CounterId counters[]; | 856 static const CounterId counters[]; |
| 852 static const int counters_count; | 857 static const int counters_count; |
| 853 | 858 |
| 854 // Starting measuring the time for a function. This will establish the | 859 // Starting measuring the time for a function. This will establish the |
| 855 // connection to the parent counter for properly calculating the own times. | 860 // connection to the parent counter for properly calculating the own times. |
| 856 V8_EXPORT_PRIVATE static void Enter(RuntimeCallStats* stats, | 861 V8_EXPORT_PRIVATE static void Enter(RuntimeCallStats* stats, |
| 857 RuntimeCallTimer* timer, | 862 RuntimeCallTimer* timer, |
| 858 CounterId counter_id); | 863 CounterId counter_id); |
| 859 | 864 |
| 860 // Leave a scope for a measured runtime function. This will properly add | 865 // Leave a scope for a measured runtime function. This will properly add |
| 861 // the time delta to the current_counter and subtract the delta from its | 866 // the time delta to the current_counter and subtract the delta from its |
| 862 // parent. | 867 // parent. |
| 863 V8_EXPORT_PRIVATE static void Leave(RuntimeCallStats* stats, | 868 V8_EXPORT_PRIVATE static void Leave(RuntimeCallStats* stats, |
| 864 RuntimeCallTimer* timer); | 869 RuntimeCallTimer* timer); |
| 865 | 870 |
| 866 // Set counter id for the innermost measurement. It can be used to refine | 871 // Set counter id for the innermost measurement. It can be used to refine |
| 867 // event kind when a runtime entry counter is too generic. | 872 // event kind when a runtime entry counter is too generic. |
| 868 V8_EXPORT_PRIVATE static void CorrectCurrentCounterId(RuntimeCallStats* stats, | 873 V8_EXPORT_PRIVATE static void CorrectCurrentCounterId(RuntimeCallStats* stats, |
| 869 CounterId counter_id); | 874 CounterId counter_id); |
| 870 | 875 |
| 871 V8_EXPORT_PRIVATE void Reset(); | 876 V8_EXPORT_PRIVATE void Reset(); |
| 872 // Add all entries from another stats object. | 877 // Add all entries from another stats object. |
| 873 void Add(RuntimeCallStats* other); | 878 void Add(RuntimeCallStats* other); |
| 874 V8_EXPORT_PRIVATE void Print(std::ostream& os); | 879 V8_EXPORT_PRIVATE void Print(std::ostream& os); |
| 875 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); | 880 V8_NOINLINE void Dump(v8::tracing::TracedValue* value); |
| 876 | 881 |
| 877 RuntimeCallStats() { | |
| 878 Reset(); | |
| 879 in_use_ = false; | |
| 880 } | |
| 881 | |
| 882 RuntimeCallTimer* current_timer() { return current_timer_.Value(); } | 882 RuntimeCallTimer* current_timer() { return current_timer_.Value(); } |
| 883 bool InUse() { return in_use_; } | 883 bool InUse() { return in_use_; } |
| 884 | 884 |
| 885 private: | 885 private: |
| 886 // Counter to track recursive time events. | 886 // Counter to track recursive time events. |
| 887 base::AtomicValue<RuntimeCallTimer*> current_timer_; | 887 base::AtomicValue<RuntimeCallTimer*> current_timer_; |
| 888 // Used to track nested tracing scopes. | 888 // Used to track nested tracing scopes. |
| 889 bool in_use_; | 889 bool in_use_; |
| 890 }; | 890 }; |
| 891 | 891 |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 | 1336 |
| 1337 explicit Counters(Isolate* isolate); | 1337 explicit Counters(Isolate* isolate); |
| 1338 | 1338 |
| 1339 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1339 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
| 1340 }; | 1340 }; |
| 1341 | 1341 |
| 1342 } // namespace internal | 1342 } // namespace internal |
| 1343 } // namespace v8 | 1343 } // namespace v8 |
| 1344 | 1344 |
| 1345 #endif // V8_COUNTERS_H_ | 1345 #endif // V8_COUNTERS_H_ |
| OLD | NEW |