5#ifndef V8_HEAP_CPPGC_TRACE_EVENT_H_
6#define V8_HEAP_CPPGC_TRACE_EVENT_H_
8#if !CPPGC_IS_STANDALONE
36#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
37 TRACE_EVENT_API_LOAD_CATEGORY_GROUP_ENABLED() & \
38 (kEnabledForRecording_CategoryGroupEnabledFlags | \
39 kEnabledForEventCallback_CategoryGroupEnabledFlags)
54#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
55 platform->GetTracingController()->GetCategoryGroupEnabled
70#define TRACE_EVENT_API_ADD_TRACE_EVENT cppgc::internal::AddTraceEventImpl
74#define TRACE_EVENT_API_ATOMIC_WORD v8::base::AtomicWord
75#define TRACE_EVENT_API_ATOMIC_LOAD(var) v8::base::Acquire_Load(&(var))
76#define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
77 v8::base::Release_Store(&(var), (value))
81#define TRACE_EVENT_API_LOAD_CATEGORY_GROUP_ENABLED() \
82 v8::base::Relaxed_Load(reinterpret_cast<const v8::base::Atomic8*>( \
83 INTERNAL_TRACE_EVENT_UID(category_group_enabled)))
90#define INTERNAL_TRACE_EVENT_UID3(a, b) cppgc_trace_event_unique_##a##b
91#define INTERNAL_TRACE_EVENT_UID2(a, b) INTERNAL_TRACE_EVENT_UID3(a, b)
92#define INTERNAL_TRACE_EVENT_UID(name_prefix) \
93 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
99#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
100 category_group, atomic, category_group_enabled) \
101 category_group_enabled = \
102 reinterpret_cast<const uint8_t*>(TRACE_EVENT_API_ATOMIC_LOAD(atomic)); \
103 if (!category_group_enabled) { \
104 category_group_enabled = \
105 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \
106 TRACE_EVENT_API_ATOMIC_STORE( \
107 atomic, reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \
108 category_group_enabled)); \
111#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
112 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
113 const uint8_t* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \
114 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
115 category_group, INTERNAL_TRACE_EVENT_UID(atomic), \
116 INTERNAL_TRACE_EVENT_UID(category_group_enabled));
120#define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
121 DCHECK_NOT_NULL(name); \
123 cppgc::Platform* platform = stats_collector_->platform_; \
124 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
125 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
126 cppgc::internal::AddTraceEvent( \
127 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
128 nullptr , 0 , 0 , flags, platform, \
138class TraceEventHelper {
143static V8_INLINE uint64_t AddTraceEventImpl(
144 char phase,
const uint8_t* category_group_enabled,
const char* name,
145 const char* scope, uint64_t
id, uint64_t bind_id, int32_t num_args,
146 const char** arg_names,
const uint8_t* arg_types,
147 const uint64_t* arg_values,
unsigned int flags, Platform* platform) {
148 std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2];
151 static_cast<intptr_t
>(arg_values[0])));
155 static_cast<intptr_t
>(arg_values[1])));
159 return controller->
AddTraceEvent(phase, category_group_enabled, name, scope,
160 id, bind_id, num_args, arg_names, arg_types,
161 arg_values, arg_convertables, flags);
170 std::is_integral<T>::value || std::is_enum<T>::value,
void>::type
171SetTraceValue(T arg,
unsigned char* type, uint64_t* value) {
172 *type = std::is_same<T, bool>::value
176 *value =
static_cast<uint64_t
>(arg);
179#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, value_type_id) \
180 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \
182 *type = value_type_id; \
184 static_assert(sizeof(arg) <= sizeof(*value)); \
185 memcpy(value, &arg, sizeof(arg)); \
189#undef INTERNAL_DECLARE_SET_TRACE_VALUE
197static V8_INLINE uint64_t AddTraceEvent(
char phase,
198 const uint8_t* category_group_enabled,
199 const char* name,
const char* scope,
200 uint64_t
id, uint64_t bind_id,
202 Platform* platform) {
204 phase, category_group_enabled, name, scope,
id, bind_id, 0 ,
205 nullptr,
nullptr,
nullptr, flags, platform);
208template <
class ARG1_TYPE>
210 char phase,
const uint8_t* category_group_enabled,
const char* name,
211 const char* scope, uint64_t
id, uint64_t bind_id,
unsigned int flags,
212 Platform* platform,
const char* arg1_name, ARG1_TYPE&& arg1_val) {
213 const int num_args = 1;
216 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
218 phase, category_group_enabled, name, scope,
id, bind_id, num_args,
219 &arg1_name, &arg_type, &arg_value, flags, platform);
222template <
class ARG1_TYPE,
class ARG2_TYPE>
224 char phase,
const uint8_t* category_group_enabled,
const char* name,
225 const char* scope, uint64_t
id, uint64_t bind_id,
unsigned int flags,
226 Platform* platform,
const char* arg1_name, ARG1_TYPE&& arg1_val,
227 const char* arg2_name, ARG2_TYPE&& arg2_val) {
228 const int num_args = 2;
229 const char* arg_names[2] = {arg1_name, arg2_name};
230 unsigned char arg_types[2];
231 uint64_t arg_values[2];
232 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0],
234 SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1],
237 phase, category_group_enabled, name, scope,
id, bind_id, num_args,
238 arg_names, arg_types, arg_values, flags, platform);
virtual uint64_t AddTraceEvent(char phase, const uint8_t *category_enabled_flag, 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, std::unique_ptr< ConvertableToTraceFormat > *arg_convertables, unsigned int flags)
v8::TracingController TracingController
#define DCHECK_LE(v1, v2)
#define V8_EXPORT_PRIVATE
#define TRACE_VALUE_TYPE_STRING
#define TRACE_VALUE_TYPE_BOOL
#define TRACE_VALUE_TYPE_INT
#define TRACE_VALUE_TYPE_UINT
#define TRACE_VALUE_TYPE_DOUBLE
#define TRACE_VALUE_TYPE_CONVERTABLE
CategoryGroupEnabledFlags
@ kEnabledForEventCallback_CategoryGroupEnabledFlags
@ kEnabledForRecording_CategoryGroupEnabledFlags
#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, value_type_id)
#define TRACE_EVENT_API_ADD_TRACE_EVENT