10#ifndef SkTraceEvent_DEFINED
11#define SkTraceEvent_DEFINED
18#if defined(SK_ANDROID_FRAMEWORK_USE_PERFETTO)
28 #define TRACE_FUNC __FUNCSIG__
30 #define TRACE_FUNC __PRETTY_FUNCTION__
34#if defined(SK_ANDROID_FRAMEWORK_USE_PERFETTO)
43 #define TRACE_STR_COPY(str) (::perfetto::DynamicString{str})
53 #define TRACE_STR_STATIC(str) (::perfetto::StaticString{str})
63 #define TRACE_STR_COPY(str) (::skia_private::TraceStringWithCopy(str))
73 #define TRACE_STR_STATIC(str) (str)
76#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
77 *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
78 (SkEventTracer::kEnabledForRecording_CategoryGroupEnabledFlags | \
79 SkEventTracer::kEnabledForEventCallback_CategoryGroupEnabledFlags)
89#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
90 SkEventTracer::GetInstance()->getCategoryGroupEnabled
103#define TRACE_EVENT_API_ADD_TRACE_EVENT \
104 SkEventTracer::GetInstance()->addTraceEvent
111#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
112 SkEventTracer::GetInstance()->updateTraceEventDuration
114#ifdef SK_ANDROID_FRAMEWORK_USE_PERFETTO
115 #define TRACE_EVENT_API_NEW_TRACE_SECTION(...) do {} while (0)
120 #define TRACE_EVENT_API_NEW_TRACE_SECTION \
121 SkEventTracer::GetInstance()->newTracingSection
125#define TRACE_EVENT_API_CLASS_EXPORT SK_API
129#define TRACE_CATEGORY_PREFIX "disabled-by-default-"
136#define INTERNAL_TRACE_EVENT_UID3(a,b) \
137 trace_event_unique_##a##b
138#define INTERNAL_TRACE_EVENT_UID2(a,b) \
139 INTERNAL_TRACE_EVENT_UID3(a,b)
140#define INTERNAL_TRACE_EVENT_UID(name_prefix) \
141 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
146#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
147 category_group, atomic, category_group_enabled) \
148 category_group_enabled = \
149 reinterpret_cast<const uint8_t*>(atomic.load(std::memory_order_relaxed)); \
150 if (!category_group_enabled) { \
151 category_group_enabled = TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \
152 atomic.store(reinterpret_cast<intptr_t>(category_group_enabled), \
153 std::memory_order_relaxed); \
156#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
157 static std::atomic<intptr_t> INTERNAL_TRACE_EVENT_UID(atomic){0}; \
158 const uint8_t* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \
159 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
160 TRACE_CATEGORY_PREFIX category_group, \
161 INTERNAL_TRACE_EVENT_UID(atomic), \
162 INTERNAL_TRACE_EVENT_UID(category_group_enabled));
166#define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
168 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
169 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
170 skia_private::AddTraceEvent( \
171 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
172 skia_private::kNoEventId, flags, ##__VA_ARGS__); \
178#define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
181 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
182 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
183 unsigned char trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
184 skia_private::TraceID trace_event_trace_id( \
185 id, &trace_event_flags); \
186 skia_private::AddTraceEvent( \
187 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
188 name, trace_event_trace_id.data(), trace_event_flags, \
195#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
196 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
197 skia_private::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
199 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
200 SkEventTracer::Handle h = skia_private::AddTraceEvent( \
201 TRACE_EVENT_PHASE_COMPLETE, \
202 INTERNAL_TRACE_EVENT_UID(category_group_enabled), \
203 name, skia_private::kNoEventId, \
204 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
205 INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \
206 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \
223 : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(
id))) {
235 : data_(static_cast<uint64_t>(
id)) { (void)
flags; }
237 : data_(static_cast<uint64_t>(
id)) { (void)
flags; }
239 : data_(static_cast<uint64_t>(
id)) { (void)
flags; }
241 : data_(static_cast<uint64_t>(
id)) { (void)
flags; }
243 : data_(static_cast<uint64_t>(
id)) { (void)
flags; }
245 uint64_t
data()
const {
return data_; }
255 operator const char* ()
const {
return str_; }
265 static_assert(
sizeof(
T) <=
sizeof(uint64_t),
"Trace value is larger than uint64_t");
272 *
value =
reinterpret_cast<uintptr_t
>(arg);
275 *
value =
reinterpret_cast<uintptr_t
>(
static_cast<const char*
>(arg));
278 *
value =
reinterpret_cast<uintptr_t
>(arg);
279 }
else if constexpr (std::is_unsigned_v<T>) {
282 }
else if constexpr (std::is_signed_v<T>) {
284 *
value =
static_cast<uint64_t
>(arg);
285 }
else if constexpr (std::is_floating_point_v<T>) {
287 *
value = sk_bit_cast<uint64_t>(arg);
291 static_assert(!
sizeof(
T),
"Unsupported type for trace argument");
297 return reinterpret_cast<const char*
>(
static_cast<uintptr_t
>(
value));
301 return reinterpret_cast<const void*
>(
static_cast<uintptr_t
>(
value));
312 const uint8_t* category_group_enabled,
315 unsigned char flags) {
317 phase, category_group_enabled,
name,
id,
321template<
class ARG1_TYPE>
325 const uint8_t* category_group_enabled,
329 const char* arg1_name,
330 const ARG1_TYPE& arg1_val) {
331 const int num_args = 1;
332 uint8_t arg_types[1];
333 uint64_t arg_values[1];
336 phase, category_group_enabled,
name,
id,
337 num_args, &arg1_name, arg_types, arg_values,
flags);
340template<
class ARG1_TYPE,
class ARG2_TYPE>
344 const uint8_t* category_group_enabled,
348 const char* arg1_name,
349 const ARG1_TYPE& arg1_val,
350 const char* arg2_name,
351 const ARG2_TYPE& arg2_val) {
352 const int num_args = 2;
353 const char* arg_names[2] = { arg1_name, arg2_name };
354 unsigned char arg_types[2];
355 uint64_t arg_values[2];
359 phase, category_group_enabled,
name,
id,
360 num_args, arg_names, arg_types, arg_values,
flags);
370 if (p_data_ && *data_.category_group_enabled)
372 data_.category_group_enabled, data_.name, data_.event_handle);
378 data_.category_group_enabled = category_group_enabled;
380 data_.event_handle = event_handle;
393 const uint8_t* category_group_enabled;
#define TRACE_EVENT_FLAG_MANGLE_ID
#define TRACE_VALUE_TYPE_STRING
#define TRACE_VALUE_TYPE_BOOL
#define TRACE_VALUE_TYPE_POINTER
#define TRACE_VALUE_TYPE_COPY_STRING
#define TRACE_VALUE_TYPE_INT
#define TRACE_VALUE_TYPE_UINT
#define TRACE_VALUE_TYPE_DOUBLE
#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION
#define TRACE_EVENT_API_CLASS_EXPORT
#define TRACE_EVENT_API_ADD_TRACE_EVENT
void Initialize(const uint8_t *category_group_enabled, const char *name, SkEventTracer::Handle event_handle)
TraceID(unsigned char id, unsigned char *flags)
TraceID(uint64_t id, unsigned char *flags)
TraceID(long id, unsigned char *flags)
TraceID(signed char id, unsigned char *flags)
TraceID(unsigned int id, unsigned char *flags)
TraceID(short id, unsigned char *flags)
TraceID(unsigned short id, unsigned char *flags)
TraceID(int id, unsigned char *flags)
TraceID(long long id, unsigned char *flags)
TraceID(const void *id, unsigned char *flags)
TraceStringWithCopy(const char *str)
FlutterSemanticsFlag flags
DEF_SWITCHES_START aot vmservice shared library name
struct PathData * Data(SkPath *path)
static const void * TraceValueAsPointer(uint64_t value)
static const char * TraceValueAsString(uint64_t value)
static SkEventTracer::Handle AddTraceEvent(char phase, const uint8_t *category_group_enabled, const char *name, uint64_t id, unsigned char flags)
static void SetTraceValue(const T &arg, unsigned char *type, uint64_t *value)
const uint64_t kNoEventId