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/objects.h" | 15 #include "src/objects.h" |
15 #include "src/runtime/runtime.h" | 16 #include "src/runtime/runtime.h" |
| 17 #include "src/tracing/trace-event.h" |
16 | 18 |
17 namespace v8 { | 19 namespace v8 { |
18 namespace internal { | 20 namespace internal { |
19 | 21 |
20 // StatsCounters is an interface for plugging into external | 22 // StatsCounters is an interface for plugging into external |
21 // counters for monitoring. Counters can be looked up and | 23 // counters for monitoring. Counters can be looked up and |
22 // manipulated by name. | 24 // manipulated by name. |
23 | 25 |
24 class StatsTable { | 26 class StatsTable { |
25 public: | 27 public: |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 RuntimeCallCounter API_##name = RuntimeCallCounter("API_" #name); | 765 RuntimeCallCounter API_##name = RuntimeCallCounter("API_" #name); |
764 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) | 766 FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) |
765 #undef CALL_BUILTIN_COUNTER | 767 #undef CALL_BUILTIN_COUNTER |
766 #define CALL_BUILTIN_COUNTER(name) \ | 768 #define CALL_BUILTIN_COUNTER(name) \ |
767 RuntimeCallCounter Handler_##name = RuntimeCallCounter(#name); | 769 RuntimeCallCounter Handler_##name = RuntimeCallCounter(#name); |
768 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) | 770 FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) |
769 #undef CALL_BUILTIN_COUNTER | 771 #undef CALL_BUILTIN_COUNTER |
770 | 772 |
771 // Starting measuring the time for a function. This will establish the | 773 // Starting measuring the time for a function. This will establish the |
772 // connection to the parent counter for properly calculating the own times. | 774 // connection to the parent counter for properly calculating the own times. |
773 static void Enter(Isolate* isolate, RuntimeCallTimer* timer, | 775 static void Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
774 CounterId counter_id); | 776 CounterId counter_id); |
775 | 777 |
776 // Leave a scope for a measured runtime function. This will properly add | 778 // Leave a scope for a measured runtime function. This will properly add |
777 // the time delta to the current_counter and subtract the delta from its | 779 // the time delta to the current_counter and subtract the delta from its |
778 // parent. | 780 // parent. |
779 static void Leave(Isolate* isolate, RuntimeCallTimer* timer); | 781 static void Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer); |
780 | 782 |
781 // Set counter id for the innermost measurement. It can be used to refine | 783 // Set counter id for the innermost measurement. It can be used to refine |
782 // event kind when a runtime entry counter is too generic. | 784 // event kind when a runtime entry counter is too generic. |
783 static void CorrectCurrentCounterId(Isolate* isolate, CounterId counter_id); | 785 static void CorrectCurrentCounterId(RuntimeCallStats* stats, |
| 786 CounterId counter_id); |
784 | 787 |
785 void Reset(); | 788 void Reset(); |
786 void Print(std::ostream& os); | 789 V8_NOINLINE void Print(std::ostream& os); |
| 790 V8_NOINLINE const char* Dump(); |
787 | 791 |
788 RuntimeCallStats() { Reset(); } | 792 RuntimeCallStats() { |
| 793 Reset(); |
| 794 in_use_ = false; |
| 795 } |
| 796 |
789 RuntimeCallTimer* current_timer() { return current_timer_; } | 797 RuntimeCallTimer* current_timer() { return current_timer_; } |
| 798 bool InUse() { return in_use_; } |
790 | 799 |
791 private: | 800 private: |
| 801 std::stringstream buffer_; |
| 802 std::unique_ptr<char[]> buffer_c_str_; |
| 803 size_t len_ = 0; |
792 // Counter to track recursive time events. | 804 // Counter to track recursive time events. |
793 RuntimeCallTimer* current_timer_ = NULL; | 805 RuntimeCallTimer* current_timer_ = NULL; |
| 806 bool in_use_; |
794 }; | 807 }; |
795 | 808 |
796 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ | 809 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ |
797 do { \ | 810 do { \ |
798 if (FLAG_runtime_call_stats) { \ | 811 if (FLAG_runtime_call_stats) { \ |
799 RuntimeCallStats::CorrectCurrentCounterId( \ | 812 RuntimeCallStats::CorrectCurrentCounterId( \ |
800 isolate, &RuntimeCallStats::counter_name); \ | 813 isolate->counters()->runtime_call_stats(), \ |
801 } \ | 814 &RuntimeCallStats::counter_name); \ |
| 815 } \ |
| 816 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) { \ |
| 817 RuntimeCallStats::CorrectCurrentCounterId( \ |
| 818 isolate->counters()->tracing_runtime_call_stats(), \ |
| 819 &RuntimeCallStats::counter_name); \ |
| 820 } \ |
802 } while (false) | 821 } while (false) |
803 | 822 |
804 #define TRACE_HANDLER_STATS(isolate, counter_name) \ | 823 #define TRACE_HANDLER_STATS(isolate, counter_name) \ |
805 TRACE_RUNTIME_CALL_STATS(isolate, Handler_##counter_name) | 824 TRACE_RUNTIME_CALL_STATS(isolate, Handler_##counter_name) |
806 | 825 |
807 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the | |
808 // the time of C++ scope. | |
809 class RuntimeCallTimerScope { | |
810 public: | |
811 inline RuntimeCallTimerScope(Isolate* isolate, | |
812 RuntimeCallStats::CounterId counter_id) { | |
813 if (V8_UNLIKELY(FLAG_runtime_call_stats)) { | |
814 isolate_ = isolate; | |
815 RuntimeCallStats::Enter(isolate_, &timer_, counter_id); | |
816 } | |
817 } | |
818 // This constructor is here just to avoid calling GetIsolate() when the | |
819 // stats are disabled and the isolate is not directly available. | |
820 inline RuntimeCallTimerScope(HeapObject* heap_object, | |
821 RuntimeCallStats::CounterId counter_id); | |
822 | |
823 inline ~RuntimeCallTimerScope() { | |
824 if (V8_UNLIKELY(FLAG_runtime_call_stats)) { | |
825 RuntimeCallStats::Leave(isolate_, &timer_); | |
826 } | |
827 } | |
828 | |
829 private: | |
830 Isolate* isolate_; | |
831 RuntimeCallTimer timer_; | |
832 }; | |
833 | |
834 #define HISTOGRAM_RANGE_LIST(HR) \ | 826 #define HISTOGRAM_RANGE_LIST(HR) \ |
835 /* Generic range histograms */ \ | 827 /* Generic range histograms */ \ |
836 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ | 828 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ |
837 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ | 829 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ |
838 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ | 830 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ |
839 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ | 831 HR(gc_idle_time_limit_undershot, V8.GCIdleTimeLimit.Undershot, 0, 10000, \ |
840 101) \ | 832 101) \ |
841 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ | 833 HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \ |
842 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ | 834 HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \ |
843 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ | 835 HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \ |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 #define COUNTER_ID(name) kCountOfCODE_AGE__##name, \ | 1158 #define COUNTER_ID(name) kCountOfCODE_AGE__##name, \ |
1167 kSizeOfCODE_AGE__##name, | 1159 kSizeOfCODE_AGE__##name, |
1168 CODE_AGE_LIST_COMPLETE(COUNTER_ID) | 1160 CODE_AGE_LIST_COMPLETE(COUNTER_ID) |
1169 #undef COUNTER_ID | 1161 #undef COUNTER_ID |
1170 stats_counter_count | 1162 stats_counter_count |
1171 }; | 1163 }; |
1172 | 1164 |
1173 void ResetCounters(); | 1165 void ResetCounters(); |
1174 void ResetHistograms(); | 1166 void ResetHistograms(); |
1175 RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; } | 1167 RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; } |
| 1168 RuntimeCallStats* tracing_runtime_call_stats() { |
| 1169 return &tracing_runtime_call_stats_; |
| 1170 } |
1176 | 1171 |
1177 private: | 1172 private: |
1178 #define HR(name, caption, min, max, num_buckets) Histogram name##_; | 1173 #define HR(name, caption, min, max, num_buckets) Histogram name##_; |
1179 HISTOGRAM_RANGE_LIST(HR) | 1174 HISTOGRAM_RANGE_LIST(HR) |
1180 #undef HR | 1175 #undef HR |
1181 | 1176 |
1182 #define HT(name, caption, max, res) HistogramTimer name##_; | 1177 #define HT(name, caption, max, res) HistogramTimer name##_; |
1183 HISTOGRAM_TIMER_LIST(HT) | 1178 HISTOGRAM_TIMER_LIST(HT) |
1184 #undef HT | 1179 #undef HT |
1185 | 1180 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) | 1223 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
1229 #undef SC | 1224 #undef SC |
1230 | 1225 |
1231 #define SC(name) \ | 1226 #define SC(name) \ |
1232 StatsCounter size_of_CODE_AGE_##name##_; \ | 1227 StatsCounter size_of_CODE_AGE_##name##_; \ |
1233 StatsCounter count_of_CODE_AGE_##name##_; | 1228 StatsCounter count_of_CODE_AGE_##name##_; |
1234 CODE_AGE_LIST_COMPLETE(SC) | 1229 CODE_AGE_LIST_COMPLETE(SC) |
1235 #undef SC | 1230 #undef SC |
1236 | 1231 |
1237 RuntimeCallStats runtime_call_stats_; | 1232 RuntimeCallStats runtime_call_stats_; |
| 1233 RuntimeCallStats tracing_runtime_call_stats_; |
1238 | 1234 |
1239 friend class Isolate; | 1235 friend class Isolate; |
1240 | 1236 |
1241 explicit Counters(Isolate* isolate); | 1237 explicit Counters(Isolate* isolate); |
1242 | 1238 |
1243 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1239 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
1244 }; | 1240 }; |
1245 | 1241 |
| 1242 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the |
| 1243 // the time of C++ scope. |
| 1244 class RuntimeCallTimerScope { |
| 1245 public: |
| 1246 inline RuntimeCallTimerScope(Isolate* isolate, |
| 1247 RuntimeCallStats::CounterId counter_id) { |
| 1248 if (V8_UNLIKELY(FLAG_runtime_call_stats)) { |
| 1249 isolate_ = isolate; |
| 1250 RuntimeCallStats::Enter(isolate_->counters()->runtime_call_stats(), |
| 1251 &timer_, counter_id); |
| 1252 } |
| 1253 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) { |
| 1254 isolate_for_tracing_ = isolate; |
| 1255 RuntimeCallStats::Enter( |
| 1256 isolate_for_tracing_->counters()->tracing_runtime_call_stats(), |
| 1257 &trace_event_timer_, counter_id); |
| 1258 } |
| 1259 } |
| 1260 // This constructor is here just to avoid calling GetIsolate() when the |
| 1261 // stats are disabled and the isolate is not directly available. |
| 1262 inline RuntimeCallTimerScope(HeapObject* heap_object, |
| 1263 RuntimeCallStats::CounterId counter_id); |
| 1264 |
| 1265 inline ~RuntimeCallTimerScope() { |
| 1266 if (V8_UNLIKELY(FLAG_runtime_call_stats)) { |
| 1267 RuntimeCallStats::Leave(isolate_->counters()->runtime_call_stats(), |
| 1268 &timer_); |
| 1269 } |
| 1270 if (V8_UNLIKELY(isolate_for_tracing_ != nullptr)) { |
| 1271 RuntimeCallStats::Leave( |
| 1272 isolate_for_tracing_->counters()->tracing_runtime_call_stats(), |
| 1273 &trace_event_timer_); |
| 1274 isolate_for_tracing_ = nullptr; |
| 1275 } |
| 1276 } |
| 1277 |
| 1278 private: |
| 1279 Isolate* isolate_; |
| 1280 // TODO(lpy): --runtime-call-stats and tracing should be mutually exclusive |
| 1281 // with tracing taking precendence. We need to add checks, and use a single |
| 1282 // isolate reference and a timer for both. |
| 1283 Isolate* isolate_for_tracing_ = nullptr; |
| 1284 RuntimeCallTimer timer_; |
| 1285 RuntimeCallTimer trace_event_timer_; |
| 1286 }; |
| 1287 |
1246 } // namespace internal | 1288 } // namespace internal |
1247 } // namespace v8 | 1289 } // namespace v8 |
1248 | 1290 |
1249 #endif // V8_COUNTERS_H_ | 1291 #endif // V8_COUNTERS_H_ |
OLD | NEW |