diff options
Diffstat (limited to 'deps/v8/src/tracing/trace-event.h')
-rw-r--r-- | deps/v8/src/tracing/trace-event.h | 198 |
1 files changed, 57 insertions, 141 deletions
diff --git a/deps/v8/src/tracing/trace-event.h b/deps/v8/src/tracing/trace-event.h index 25ccd8045a..35d2e1507d 100644 --- a/deps/v8/src/tracing/trace-event.h +++ b/deps/v8/src/tracing/trace-event.h @@ -6,12 +6,12 @@ #define SRC_TRACING_TRACE_EVENT_H_ #include <stddef.h> +#include <memory> #include "base/trace_event/common/trace_event_common.h" #include "include/v8-platform.h" #include "src/base/atomicops.h" #include "src/base/macros.h" -#include "src/counters.h" // This header file defines implementation details of how the trace macros in // trace_event_common.h collect and store trace events. Anything not @@ -121,8 +121,7 @@ enum CategoryGroupEnabledFlags { // const uint8_t* arg_types, // const uint64_t* arg_values, // unsigned int flags) -#define TRACE_EVENT_API_ADD_TRACE_EVENT \ - v8::internal::tracing::TraceEventHelper::GetCurrentPlatform()->AddTraceEvent +#define TRACE_EVENT_API_ADD_TRACE_EVENT v8::internal::tracing::AddTraceEventImpl // Set the duration field of a COMPLETE trace event. // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( @@ -281,7 +280,7 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; uint64_t cid_; \ }; \ INTERNAL_TRACE_EVENT_UID(ScopedContext) \ - INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); + INTERNAL_TRACE_EVENT_UID(scoped_context)(context); #define TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_ENABLED() \ base::NoBarrier_Load(&v8::internal::tracing::kRuntimeCallStatsTracingEnabled) @@ -289,9 +288,6 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; #define TRACE_EVENT_CALL_STATS_SCOPED(isolate, category_group, name) \ INTERNAL_TRACE_EVENT_CALL_STATS_SCOPED(isolate, category_group, name) -#define TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(isolate, counter_id) \ - INTERNAL_TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(isolate, counter_id) - #define INTERNAL_TRACE_EVENT_CALL_STATS_SCOPED(isolate, category_group, name) \ { \ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO( \ @@ -309,13 +305,11 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3]; name); \ } -#define INTERNAL_TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED(isolate, \ - counter_id) \ - v8::internal::tracing::CounterScope INTERNAL_TRACE_EVENT_UID(scope)( \ - isolate, counter_id); - namespace v8 { namespace internal { + +class Isolate; + namespace tracing { // Specify these values when the corresponding argument of AddTraceEvent is not @@ -460,6 +454,28 @@ class TraceStringWithCopy { const char* str_; }; +static V8_INLINE uint64_t AddTraceEventImpl( + char phase, const uint8_t* category_group_enabled, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, unsigned int flags) { + std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2]; + if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) { + arg_convertables[0].reset(reinterpret_cast<ConvertableToTraceFormat*>( + static_cast<intptr_t>(arg_values[0]))); + } + if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) { + arg_convertables[1].reset(reinterpret_cast<ConvertableToTraceFormat*>( + static_cast<intptr_t>(arg_values[1]))); + } + DCHECK(num_args <= 2); + v8::Platform* platform = + v8::internal::tracing::TraceEventHelper::GetCurrentPlatform(); + return platform->AddTraceEvent(phase, category_group_enabled, name, scope, id, + bind_id, num_args, arg_names, arg_types, + arg_values, arg_convertables, flags); +} + // Define SetTraceValue for each allowed type. It stores the type and // value in the return arguments. This allows this API to avoid declaring any // structures so that it is portable to third_party libraries. @@ -500,6 +516,19 @@ INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, #undef INTERNAL_DECLARE_SET_TRACE_VALUE #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT +static V8_INLINE void SetTraceValue(ConvertableToTraceFormat* convertable_value, + unsigned char* type, uint64_t* value) { + *type = TRACE_VALUE_TYPE_CONVERTABLE; + *value = static_cast<uint64_t>(reinterpret_cast<intptr_t>(convertable_value)); +} + +template <typename T> +static V8_INLINE typename std::enable_if< + std::is_convertible<T*, ConvertableToTraceFormat*>::value>::type +SetTraceValue(std::unique_ptr<T> ptr, unsigned char* type, uint64_t* value) { + SetTraceValue(ptr.release(), type, value); +} + // These AddTraceEvent template // function is defined here instead of in the macro, because the arg_values // could be temporary objects, such as std::string. In order to store @@ -512,36 +541,38 @@ static V8_INLINE uint64_t AddTraceEvent(char phase, uint64_t id, uint64_t bind_id, unsigned int flags) { return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, - scope, id, bind_id, kZeroNumArgs, NULL, - NULL, NULL, flags); + scope, id, bind_id, kZeroNumArgs, + nullptr, nullptr, nullptr, flags); } template <class ARG1_TYPE> static V8_INLINE uint64_t AddTraceEvent( char phase, const uint8_t* category_group_enabled, const char* name, const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, - const char* arg1_name, const ARG1_TYPE& arg1_val) { + const char* arg1_name, ARG1_TYPE&& arg1_val) { const int num_args = 1; - uint8_t arg_types[1]; - uint64_t arg_values[1]; - SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); + uint8_t arg_type; + uint64_t arg_value; + SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value); return TRACE_EVENT_API_ADD_TRACE_EVENT( phase, category_group_enabled, name, scope, id, bind_id, num_args, - &arg1_name, arg_types, arg_values, flags); + &arg1_name, &arg_type, &arg_value, flags); } template <class ARG1_TYPE, class ARG2_TYPE> static V8_INLINE uint64_t AddTraceEvent( char phase, const uint8_t* category_group_enabled, const char* name, const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, - const char* arg1_name, const ARG1_TYPE& arg1_val, const char* arg2_name, - const ARG2_TYPE& arg2_val) { + const char* arg1_name, ARG1_TYPE&& arg1_val, const char* arg2_name, + ARG2_TYPE&& arg2_val) { const int num_args = 2; const char* arg_names[2] = {arg1_name, arg2_name}; unsigned char arg_types[2]; uint64_t arg_values[2]; - SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); - SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); + SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0], + &arg_values[0]); + SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1], + &arg_values[1]); return TRACE_EVENT_API_ADD_TRACE_EVENT( phase, category_group_enabled, name, scope, id, bind_id, num_args, arg_names, arg_types, arg_values, flags); @@ -634,136 +665,21 @@ class CallStatsScopedTracer { } } - void Initialize(Isolate* isolate, const uint8_t* category_group_enabled, - const char* name); + void Initialize(v8::internal::Isolate* isolate, + const uint8_t* category_group_enabled, const char* name); private: void AddEndTraceEvent(); struct Data { const uint8_t* category_group_enabled; const char* name; - Isolate* isolate; + v8::internal::Isolate* isolate; }; bool has_parent_scope_; Data* p_data_; Data data_; }; -// TraceEventCallStatsTimer is used to keep track of the stack of currently -// active timers used for properly measuring the own time of a -// RuntimeCallCounter. -class TraceEventCallStatsTimer { - public: - TraceEventCallStatsTimer() : counter_(nullptr), parent_(nullptr) {} - RuntimeCallCounter* counter() { return counter_; } - base::ElapsedTimer timer() { return timer_; } - - private: - friend class TraceEventStatsTable; - - V8_INLINE void Start(RuntimeCallCounter* counter, - TraceEventCallStatsTimer* parent) { - counter_ = counter; - parent_ = parent; - timer_.Start(); - } - - V8_INLINE TraceEventCallStatsTimer* Stop() { - base::TimeDelta delta = timer_.Elapsed(); - timer_.Stop(); - counter_->count++; - counter_->time += delta; - if (parent_ != nullptr) { - // Adjust parent timer so that it does not include sub timer's time. - parent_->counter_->time -= delta; - } - return parent_; - } - - RuntimeCallCounter* counter_; - TraceEventCallStatsTimer* parent_; - base::ElapsedTimer timer_; -}; - -class TraceEventStatsTable { - public: - typedef RuntimeCallCounter TraceEventStatsTable::*CounterId; - -#define CALL_RUNTIME_COUNTER(name) \ - RuntimeCallCounter name = RuntimeCallCounter(#name); - FOR_EACH_MANUAL_COUNTER(CALL_RUNTIME_COUNTER) -#undef CALL_RUNTIME_COUNTER -#define CALL_RUNTIME_COUNTER(name, nargs, ressize) \ - RuntimeCallCounter Runtime_##name = RuntimeCallCounter(#name); - FOR_EACH_INTRINSIC(CALL_RUNTIME_COUNTER) -#undef CALL_RUNTIME_COUNTER -#define CALL_BUILTIN_COUNTER(name) \ - RuntimeCallCounter Builtin_##name = RuntimeCallCounter(#name); - BUILTIN_LIST_C(CALL_BUILTIN_COUNTER) -#undef CALL_BUILTIN_COUNTER -#define CALL_BUILTIN_COUNTER(name) \ - RuntimeCallCounter API_##name = RuntimeCallCounter("API_" #name); - FOR_EACH_API_COUNTER(CALL_BUILTIN_COUNTER) -#undef CALL_BUILTIN_COUNTER -#define CALL_BUILTIN_COUNTER(name) \ - RuntimeCallCounter Handler_##name = RuntimeCallCounter(#name); - FOR_EACH_HANDLER_COUNTER(CALL_BUILTIN_COUNTER) -#undef CALL_BUILTIN_COUNTER - - // Starting measuring the time for a function. This will establish the - // connection to the parent counter for properly calculating the own times. - static void Enter(Isolate* isolate, TraceEventCallStatsTimer* timer, - CounterId counter_id); - - // Leave a scope for a measured runtime function. This will properly add - // the time delta to the current_counter and subtract the delta from its - // parent. - static void Leave(Isolate* isolate, TraceEventCallStatsTimer* timer); - - void Reset(); - const char* Dump(); - - TraceEventStatsTable() { - Reset(); - in_use_ = false; - } - - TraceEventCallStatsTimer* current_timer() { return current_timer_; } - bool InUse() { return in_use_; } - - private: - std::stringstream buffer_; - std::unique_ptr<char[]> buffer_c_str_; - size_t len_ = 0; - // Counter to track recursive time events. - TraceEventCallStatsTimer* current_timer_ = nullptr; - bool in_use_; -}; - -class CounterScope { - public: - 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() { - // A non-nullptr isolate_ means the stats table already entered the scope - // and started the timer, we need to leave the scope and reset the timer - // even when we stop tracing, otherwise we have the risk to have a dangling - // pointer. - if (V8_UNLIKELY(isolate_ != nullptr)) { - TraceEventStatsTable::Leave(isolate_, &timer_); - } - } - - private: - Isolate* isolate_; - TraceEventCallStatsTimer timer_; -}; - } // namespace tracing } // namespace internal } // namespace v8 |