Chromium Code Reviews| Index: src/counters.cc |
| diff --git a/src/counters.cc b/src/counters.cc |
| index 4f962abcf31fa9f8ae9b1907d522cb68ce7898b2..83565e57eed8fa459fb4e0c4d2cc0c6f1fe4ca65 100644 |
| --- a/src/counters.cc |
| +++ b/src/counters.cc |
| @@ -284,10 +284,16 @@ void RuntimeCallCounter::Dump(v8::tracing::TracedValue* value) { |
| value->EndArray(); |
| } |
| +void RuntimeCallCounter::Add(RuntimeCallCounter* other) { |
| + count += other->count; |
| + time += other->time; |
| +} |
| + |
| // 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 +307,23 @@ 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) { |
| + RuntimeCallCounter* current = &(this->First); |
|
vogelheim
2016/11/14 10:20:33
(here and below):
I take it you use First & Last
Camillo Bruni
2016/11/14 12:43:46
Yes, that's right, given that First and Last are j
|
| + RuntimeCallCounter* other_counter = &(other->First); |
| + while (current < &(this->Last)) { |
| + current = reinterpret_cast<RuntimeCallCounter*>( |
| + reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
| + other_counter = reinterpret_cast<RuntimeCallCounter*>( |
| + reinterpret_cast<intptr_t>(other_counter) + sizeof(RuntimeCallCounter)); |
|
vogelheim
2016/11/14 10:20:33
A nitpick, loosely related to the comment above: T
Camillo Bruni
2016/11/14 12:43:46
Right, I had some discussions around this as it is
|
| + current->Add(other_counter); |
| + } |
| +} |
| + |
| // static |
| void RuntimeCallStats::CorrectCurrentCounterId(RuntimeCallStats* stats, |
| CounterId counter_id) { |
| @@ -321,27 +338,12 @@ 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 |
| - |
| + RuntimeCallCounter* current = &(this->First); |
| + while (current < &(this->Last)) { |
| + current = reinterpret_cast<RuntimeCallCounter*>( |
| + reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
| + entries.Add(current); |
| + } |
| entries.Print(os); |
| } |
| @@ -356,54 +358,23 @@ 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 |
| + RuntimeCallCounter* current = &(this->First); |
| + while (current < &(this->Last)) { |
| + current = reinterpret_cast<RuntimeCallCounter*>( |
| + reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
| + current->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 |
| + RuntimeCallCounter* current = &(this->First); |
| + while (current < &(this->Last)) { |
| + current = reinterpret_cast<RuntimeCallCounter*>( |
| + reinterpret_cast<intptr_t>(current) + sizeof(RuntimeCallCounter)); |
| + if (current->count > 0) current->Dump(value); |
| + } |
| in_use_ = false; |
| } |