| 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" |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 private: | 801 private: |
| 802 std::stringstream buffer_; | 802 std::stringstream buffer_; |
| 803 std::unique_ptr<char[]> buffer_c_str_; | 803 std::unique_ptr<char[]> buffer_c_str_; |
| 804 size_t len_ = 0; | 804 size_t len_ = 0; |
| 805 // Counter to track recursive time events. | 805 // Counter to track recursive time events. |
| 806 RuntimeCallTimer* current_timer_ = NULL; | 806 RuntimeCallTimer* current_timer_ = NULL; |
| 807 // Used to track nested tracing scopes. | 807 // Used to track nested tracing scopes. |
| 808 bool in_use_; | 808 bool in_use_; |
| 809 }; | 809 }; |
| 810 | 810 |
| 811 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ | 811 #define TRACE_RUNTIME_CALL_STATS(isolate, counter_name) \ |
| 812 do { \ | 812 do { \ |
| 813 if (FLAG_runtime_call_stats) { \ | 813 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() || \ |
| 814 RuntimeCallStats::CorrectCurrentCounterId( \ | 814 FLAG_runtime_call_stats)) { \ |
| 815 isolate->counters()->runtime_call_stats(), \ | 815 RuntimeCallStats::CorrectCurrentCounterId( \ |
| 816 &RuntimeCallStats::counter_name); \ | 816 isolate->counters()->runtime_call_stats(), \ |
| 817 } \ | 817 &RuntimeCallStats::counter_name); \ |
| 818 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) { \ | 818 } \ |
| 819 RuntimeCallStats::CorrectCurrentCounterId( \ | |
| 820 isolate->counters()->tracing_runtime_call_stats(), \ | |
| 821 &RuntimeCallStats::counter_name); \ | |
| 822 } \ | |
| 823 } while (false) | 819 } while (false) |
| 824 | 820 |
| 825 #define TRACE_HANDLER_STATS(isolate, counter_name) \ | 821 #define TRACE_HANDLER_STATS(isolate, counter_name) \ |
| 826 TRACE_RUNTIME_CALL_STATS(isolate, Handler_##counter_name) | 822 TRACE_RUNTIME_CALL_STATS(isolate, Handler_##counter_name) |
| 827 | 823 |
| 828 #define HISTOGRAM_RANGE_LIST(HR) \ | 824 #define HISTOGRAM_RANGE_LIST(HR) \ |
| 829 /* Generic range histograms */ \ | 825 /* Generic range histograms */ \ |
| 830 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ | 826 HR(detached_context_age_in_gc, V8.DetachedContextAgeInGC, 0, 20, 21) \ |
| 831 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ | 827 HR(gc_idle_time_allotted_in_ms, V8.GCIdleTimeAllottedInMS, 0, 10000, 101) \ |
| 832 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ | 828 HR(gc_idle_time_limit_overshot, V8.GCIdleTimeLimit.Overshot, 0, 10000, 101) \ |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 #define COUNTER_ID(name) kCountOfCODE_AGE__##name, \ | 1159 #define COUNTER_ID(name) kCountOfCODE_AGE__##name, \ |
| 1164 kSizeOfCODE_AGE__##name, | 1160 kSizeOfCODE_AGE__##name, |
| 1165 CODE_AGE_LIST_COMPLETE(COUNTER_ID) | 1161 CODE_AGE_LIST_COMPLETE(COUNTER_ID) |
| 1166 #undef COUNTER_ID | 1162 #undef COUNTER_ID |
| 1167 stats_counter_count | 1163 stats_counter_count |
| 1168 }; | 1164 }; |
| 1169 | 1165 |
| 1170 void ResetCounters(); | 1166 void ResetCounters(); |
| 1171 void ResetHistograms(); | 1167 void ResetHistograms(); |
| 1172 RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; } | 1168 RuntimeCallStats* runtime_call_stats() { return &runtime_call_stats_; } |
| 1173 RuntimeCallStats* tracing_runtime_call_stats() { | |
| 1174 return &tracing_runtime_call_stats_; | |
| 1175 } | |
| 1176 | 1169 |
| 1177 private: | 1170 private: |
| 1178 #define HR(name, caption, min, max, num_buckets) Histogram name##_; | 1171 #define HR(name, caption, min, max, num_buckets) Histogram name##_; |
| 1179 HISTOGRAM_RANGE_LIST(HR) | 1172 HISTOGRAM_RANGE_LIST(HR) |
| 1180 #undef HR | 1173 #undef HR |
| 1181 | 1174 |
| 1182 #define HT(name, caption, max, res) HistogramTimer name##_; | 1175 #define HT(name, caption, max, res) HistogramTimer name##_; |
| 1183 HISTOGRAM_TIMER_LIST(HT) | 1176 HISTOGRAM_TIMER_LIST(HT) |
| 1184 #undef HT | 1177 #undef HT |
| 1185 | 1178 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) | 1221 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(SC) |
| 1229 #undef SC | 1222 #undef SC |
| 1230 | 1223 |
| 1231 #define SC(name) \ | 1224 #define SC(name) \ |
| 1232 StatsCounter size_of_CODE_AGE_##name##_; \ | 1225 StatsCounter size_of_CODE_AGE_##name##_; \ |
| 1233 StatsCounter count_of_CODE_AGE_##name##_; | 1226 StatsCounter count_of_CODE_AGE_##name##_; |
| 1234 CODE_AGE_LIST_COMPLETE(SC) | 1227 CODE_AGE_LIST_COMPLETE(SC) |
| 1235 #undef SC | 1228 #undef SC |
| 1236 | 1229 |
| 1237 RuntimeCallStats runtime_call_stats_; | 1230 RuntimeCallStats runtime_call_stats_; |
| 1238 RuntimeCallStats tracing_runtime_call_stats_; | |
| 1239 | 1231 |
| 1240 friend class Isolate; | 1232 friend class Isolate; |
| 1241 | 1233 |
| 1242 explicit Counters(Isolate* isolate); | 1234 explicit Counters(Isolate* isolate); |
| 1243 | 1235 |
| 1244 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1236 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
| 1245 }; | 1237 }; |
| 1246 | 1238 |
| 1247 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the | 1239 // A RuntimeCallTimerScopes wraps around a RuntimeCallTimer to measure the |
| 1248 // the time of C++ scope. | 1240 // the time of C++ scope. |
| 1249 class RuntimeCallTimerScope { | 1241 class RuntimeCallTimerScope { |
| 1250 public: | 1242 public: |
| 1251 inline RuntimeCallTimerScope(Isolate* isolate, | 1243 inline RuntimeCallTimerScope(Isolate* isolate, |
| 1252 RuntimeCallStats::CounterId counter_id) { | 1244 RuntimeCallStats::CounterId counter_id); |
| 1253 if (V8_UNLIKELY(FLAG_runtime_call_stats)) { | |
| 1254 isolate_ = isolate; | |
| 1255 RuntimeCallStats::Enter(isolate_->counters()->runtime_call_stats(), | |
| 1256 &timer_, counter_id); | |
| 1257 } | |
| 1258 if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) { | |
| 1259 isolate_for_tracing_ = isolate; | |
| 1260 RuntimeCallStats::Enter( | |
| 1261 isolate_for_tracing_->counters()->tracing_runtime_call_stats(), | |
| 1262 &trace_event_timer_, counter_id); | |
| 1263 } | |
| 1264 } | |
| 1265 // This constructor is here just to avoid calling GetIsolate() when the | 1245 // This constructor is here just to avoid calling GetIsolate() when the |
| 1266 // stats are disabled and the isolate is not directly available. | 1246 // stats are disabled and the isolate is not directly available. |
| 1267 inline RuntimeCallTimerScope(HeapObject* heap_object, | 1247 inline RuntimeCallTimerScope(HeapObject* heap_object, |
| 1268 RuntimeCallStats::CounterId counter_id); | 1248 RuntimeCallStats::CounterId counter_id); |
| 1269 | 1249 |
| 1270 inline ~RuntimeCallTimerScope() { | 1250 inline ~RuntimeCallTimerScope() { |
| 1271 if (V8_UNLIKELY(FLAG_runtime_call_stats)) { | 1251 if (V8_UNLIKELY(isolate_ != nullptr)) { |
| 1272 RuntimeCallStats::Leave(isolate_->counters()->runtime_call_stats(), | 1252 RuntimeCallStats::Leave(isolate_->counters()->runtime_call_stats(), |
| 1273 &timer_); | 1253 &timer_); |
| 1274 } | 1254 } |
| 1275 if (V8_UNLIKELY(isolate_for_tracing_ != nullptr)) { | |
| 1276 RuntimeCallStats::Leave( | |
| 1277 isolate_for_tracing_->counters()->tracing_runtime_call_stats(), | |
| 1278 &trace_event_timer_); | |
| 1279 isolate_for_tracing_ = nullptr; | |
| 1280 } | |
| 1281 } | 1255 } |
| 1282 | 1256 |
| 1283 private: | 1257 private: |
| 1284 Isolate* isolate_; | 1258 Isolate* isolate_ = nullptr; |
| 1285 // TODO(lpy): --runtime-call-stats and tracing should be mutually exclusive | |
| 1286 // with tracing taking precendence. We need to add checks, and use a single | |
| 1287 // isolate reference and a timer for both. | |
| 1288 Isolate* isolate_for_tracing_ = nullptr; | |
| 1289 RuntimeCallTimer timer_; | 1259 RuntimeCallTimer timer_; |
| 1290 RuntimeCallTimer trace_event_timer_; | |
| 1291 }; | 1260 }; |
| 1292 | 1261 |
| 1293 } // namespace internal | 1262 } // namespace internal |
| 1294 } // namespace v8 | 1263 } // namespace v8 |
| 1295 | 1264 |
| 1296 #endif // V8_COUNTERS_H_ | 1265 #endif // V8_COUNTERS_H_ |
| OLD | NEW |