Index: src/counters.cc |
diff --git a/src/counters.cc b/src/counters.cc |
index 4f962abcf31fa9f8ae9b1907d522cb68ce7898b2..ae9ebb79f205f74b3599cf80612ab12e52ad8b1e 100644 |
--- a/src/counters.cc |
+++ b/src/counters.cc |
@@ -284,10 +284,36 @@ void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { |
value->EndArray(); |
} |
+void RuntimeCallCounter::Add(RuntimeCallCounter* other) { |
+ count += other->count; |
+ time += other->time; |
+} |
+ |
+// static |
+const RuntimeCallStats::CounterId RuntimeCallStats::counters[] = { |
+#define CALL_RUNTIME_COUNTER(name) &RuntimeCallStats::name, |
+ FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) // |
+#undef CALL_RUNTIME_COUNTER |
+#define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ |
+ &RuntimeCallStats::Runtime_##name, // |
+ FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) // |
+#undef CALL_RUNTIME_COUNTER |
+#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Builtin_##name, |
+ BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) // |
+#undef CALL_BUILTIN_COUNTER |
+#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::API_##name, |
+ FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) // |
+#undef CALL_BUILTIN_COUNTER |
+#define CALL_BUILTIN_COUNTER(name) &RuntimeCallStats::Handler_##name, |
+ FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) |
+#undef CALL_BUILTIN_COUNTER |
+}; |
+ |
// static |
void RuntimeCallStats::Enter(RuntimeCallStats* stats, RuntimeCallTimer* timer, |
CounterId counter_id) { |
RuntimeCallCounter* counter = &(stats->*counter_id); |
+ DCHECK(counter->name != NULL); |
timer->Start(counter, stats->current_timer_.Value()); |
stats->current_timer_.SetValue(timer); |
} |
@@ -301,12 +327,20 @@ void RuntimeCallStats::Leave(RuntimeCallStats* stats, RuntimeCallTimer* timer) { |
// buried one that's leaving. We don't care about keeping nested timings |
// accurate, just avoid crashing by keeping the chain intact. |
RuntimeCallTimer* next = stats->current_timer_.Value(); |
- while (next && next->parent() != timer) next = next->parent(); |
- if (next == nullptr) return; |
+ while (next->parent() != timer) next = next->parent(); |
next->parent_.SetValue(timer->Stop()); |
} |
} |
+void RuntimeCallStats::Add(RuntimeCallStats* other) { |
+ for (const RuntimeCallStats::CounterId counter_id : |
+ RuntimeCallStats::counters) { |
+ RuntimeCallCounter* counter = &(this->*counter_id); |
+ RuntimeCallCounter* other_counter = &(other->*counter_id); |
+ counter->Add(other_counter); |
+ } |
+} |
+ |
// static |
void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, |
CounterId counter_id) { |
@@ -321,27 +355,11 @@ void RuntimeCallStats::Print(std::ostream& os) { |
if (current_timer_.Value() != nullptr) { |
current_timer_.Value()->Elapsed(); |
} |
- |
-#define PRINT_COUNTER(name) entries.Add(&this->name); |
- FOR_EACH_MANUAL_COUNTER(PRINT_COUNTER) |
-#undef PRINT_COUNTER |
- |
-#define PRINT_COUNTER(name, nargs, ressize) entries.Add(&this->Runtime_##name); |
- FOR_EACH_INTRINSIC(PRINT_COUNTER) |
-#undef PRINT_COUNTER |
- |
-#define PRINT_COUNTER(name) entries.Add(&this->Builtin_##name); |
- BUILTIN_LIST_C(PRINT_COUNTER) |
-#undef PRINT_COUNTER |
- |
-#define PRINT_COUNTER(name) entries.Add(&this->API_##name); |
- FOR_EACH_API_COUNTER(PRINT_COUNTER) |
-#undef PRINT_COUNTER |
- |
-#define PRINT_COUNTER(name) entries.Add(&this->Handler_##name); |
- FOR_EACH_HANDLER_COUNTER(PRINT_COUNTER) |
-#undef PRINT_COUNTER |
- |
+ for (const RuntimeCallStats::CounterId counter_id : |
+ RuntimeCallStats::counters) { |
+ RuntimeCallCounter* counter = &(this->*counter_id); |
+ entries.Add(counter); |
+ } |
entries.Print(os); |
} |
@@ -356,54 +374,21 @@ void RuntimeCallStats::Reset() { |
current_timer_.SetValue(current_timer_.Value()->Stop()); |
} |
-#define RESET_COUNTER(name) this->name.Reset(); |
- FOR_EACH_MANUAL_COUNTER(RESET_COUNTER) |
-#undef RESET_COUNTER |
- |
-#define RESET_COUNTER(name, nargs, result_size) this->Runtime_##name.Reset(); |
- FOR_EACH_INTRINSIC(RESET_COUNTER) |
-#undef RESET_COUNTER |
- |
-#define RESET_COUNTER(name) this->Builtin_##name.Reset(); |
- BUILTIN_LIST_C(RESET_COUNTER) |
-#undef RESET_COUNTER |
- |
-#define RESET_COUNTER(name) this->API_##name.Reset(); |
- FOR_EACH_API_COUNTER(RESET_COUNTER) |
-#undef RESET_COUNTER |
- |
-#define RESET_COUNTER(name) this->Handler_##name.Reset(); |
- FOR_EACH_HANDLER_COUNTER(RESET_COUNTER) |
-#undef RESET_COUNTER |
+ for (const RuntimeCallStats::CounterId counter_id : |
+ RuntimeCallStats::counters) { |
+ RuntimeCallCounter* counter = &(this->*counter_id); |
+ counter->Reset(); |
+ } |
in_use_ = true; |
} |
void RuntimeCallStats::Dump(v8::tracing::TracedValue* value) { |
-#define DUMP_COUNTER(name) \ |
- if (this->name.count > 0) this->name.Dump(value); |
- FOR_EACH_MANUAL_COUNTER(DUMP_COUNTER) |
-#undef DUMP_COUNTER |
- |
-#define DUMP_COUNTER(name, nargs, result_size) \ |
- if (this->Runtime_##name.count > 0) this->Runtime_##name.Dump(value); |
- FOR_EACH_INTRINSIC(DUMP_COUNTER) |
-#undef DUMP_COUNTER |
- |
-#define DUMP_COUNTER(name) \ |
- if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(value); |
- BUILTIN_LIST_C(DUMP_COUNTER) |
-#undef DUMP_COUNTER |
- |
-#define DUMP_COUNTER(name) \ |
- if (this->API_##name.count > 0) this->API_##name.Dump(value); |
- FOR_EACH_API_COUNTER(DUMP_COUNTER) |
-#undef DUMP_COUNTER |
- |
-#define DUMP_COUNTER(name) \ |
- if (this->Handler_##name.count > 0) this->Handler_##name.Dump(value); |
- FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER) |
-#undef DUMP_COUNTER |
+ for (const RuntimeCallStats::CounterId counter_id : |
+ RuntimeCallStats::counters) { |
+ RuntimeCallCounter* counter = &(this->*counter_id); |
+ if (counter->count > 0) counter->Dump(value); |
+ } |
in_use_ = false; |
} |