Chromium Code Reviews| Index: src/tracing/trace-event.cc |
| diff --git a/src/tracing/trace-event.cc b/src/tracing/trace-event.cc |
| index 04f1f2e2ea0d0a8df9f504b24954cfc7857cd413..70f0ab15f9721ac0dc6eeee2666aab6ce5e34ab7 100644 |
| --- a/src/tracing/trace-event.cc |
| +++ b/src/tracing/trace-event.cc |
| @@ -4,16 +4,154 @@ |
| #include "src/tracing/trace-event.h" |
| +#include <string.h> |
| + |
| +#include "src/isolate.h" |
| #include "src/v8.h" |
| namespace v8 { |
| namespace internal { |
| namespace tracing { |
| +// A global flag used as a shortcut to check for the |
| +// v8.runtime category due to its high frequency use. |
| +int kRuntimeCallsTracingEnabled = 0; |
|
Camillo Bruni
2016/07/27 08:29:07
Please make this a bool to make your intentions a
lpy
2016/07/27 19:58:37
Done.
|
| + |
| v8::Platform* TraceEventHelper::GetCurrentPlatform() { |
| return v8::internal::V8::GetCurrentPlatform(); |
| } |
| +CallStatsScopedTracer::~CallStatsScopedTracer() { |
| + if (p_data_ && *data_.category_group_enabled) { |
|
Camillo Bruni
2016/07/27 08:29:07
can you put the test in the header and delegate th
lpy
2016/07/27 19:58:37
Done.
|
| + if (!has_parent_scope_) { |
| + v8::internal::tracing::AddTraceEvent( |
| + TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, |
| + v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
| + TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId, |
| + "runtime-call-stat", |
| + p_data_->isolate |
| + ? TRACE_STR_COPY( |
| + p_data_->isolate->trace_event_stats_table()->Dump()) |
| + : ""); |
| + } else { |
| + v8::internal::tracing::AddTraceEvent( |
| + TRACE_EVENT_PHASE_END, p_data_->category_group_enabled, p_data_->name, |
| + v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
| + TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); |
| + } |
| + } |
| +} |
| + |
| +void CallStatsScopedTracer::Initialize(Isolate* isolate, |
| + const uint8_t* category_group_enabled, |
| + const char* name) { |
| + data_.isolate = isolate; |
| + data_.category_group_enabled = category_group_enabled; |
| + data_.name = name; |
| + p_data_ = &data_; |
| + TraceEventStatsTable* table = isolate->trace_event_stats_table(); |
| + has_parent_scope_ = table->InUse(); |
| + if (!has_parent_scope_) table->Reset(); |
| + v8::internal::tracing::AddTraceEvent( |
| + TRACE_EVENT_PHASE_BEGIN, category_group_enabled, name, |
| + v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, |
| + TRACE_EVENT_FLAG_NONE, v8::internal::tracing::kNoId); |
| +} |
| + |
| +void TraceEventStatsTable::Enter(Isolate* isolate, |
| + TraceEventCallStatsTimer* timer, |
| + CounterId counter_id) { |
| + TraceEventStatsTable* table = isolate->trace_event_stats_table(); |
| + RuntimeCallCounter* counter = &(table->*counter_id); |
| + timer->Start(counter, table->current_timer_); |
| + table->current_timer_ = timer; |
| +} |
| + |
| +void TraceEventStatsTable::Leave(Isolate* isolate, |
| + TraceEventCallStatsTimer* timer) { |
| + TraceEventStatsTable* table = isolate->trace_event_stats_table(); |
| + if (table->current_timer_ == timer) { |
| + table->current_timer_ = timer->Stop(); |
| + } |
| +} |
| + |
| +void TraceEventStatsTable::Reset() { |
| + in_use_ = true; |
| + current_timer_ = nullptr; |
| +#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 |
| +} |
| + |
| +const char* TraceEventStatsTable::Dump() { |
| + buffer_.str(""); |
| + buffer_.clear(); |
| + buffer_ << "{"; |
| +#define DUMP_COUNTER(name) \ |
| + if (this->name.count > 0) this->name.Dump(buffer_); |
| + 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(buffer_); |
| + FOR_EACH_INTRINSIC(DUMP_COUNTER) |
| +#undef DUMP_COUNTER |
| + |
| +#define DUMP_COUNTER(name) \ |
| + if (this->Builtin_##name.count > 0) this->Builtin_##name.Dump(buffer_); |
| + BUILTIN_LIST_C(DUMP_COUNTER) |
| +#undef DUMP_COUNTER |
| + |
| +#define DUMP_COUNTER(name) \ |
| + if (this->API_##name.count > 0) this->API_##name.Dump(buffer_); |
| + FOR_EACH_API_COUNTER(DUMP_COUNTER) |
| +#undef DUMP_COUNTER |
| + |
| +#define DUMP_COUNTER(name) \ |
| + if (this->Handler_##name.count > 0) this->Handler_##name.Dump(buffer_); |
| + FOR_EACH_HANDLER_COUNTER(DUMP_COUNTER) |
| +#undef DUMP_COUNTER |
| + buffer_ << "\"END\":[]}"; |
| + std::string buffer_str = buffer_.str(); |
| + size_t length = buffer_str.size(); |
| + char* buffer_c_str = new char[length + 1]; |
| + memcpy(buffer_c_str, buffer_str.c_str(), length + 1); |
| + in_use_ = false; |
| + return buffer_c_str; |
| +} |
| + |
| +CounterScope::CounterScope(Isolate* isolate, |
| + TraceEventStatsTable::CounterId counter_id) |
| + : isolate_(nullptr) { |
| + if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED())) { |
| + isolate_ = isolate; |
| + TraceEventStatsTable::Enter(isolate_, &timer_, counter_id); |
| + } |
| +} |
| + |
| +CounterScope::~CounterScope() { |
| + if (V8_UNLIKELY(TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED()) && |
| + isolate_) { |
| + TraceEventStatsTable::Leave(isolate_, &timer_); |
| + } |
| +} |
| + |
| } // namespace tracing |
| } // namespace internal |
| } // namespace v8 |