1cb93a386Sopenharmony_ci// Copyright 2015 The Chromium Authors. All rights reserved.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
3cb93a386Sopenharmony_ci// found in the LICENSE file.
4cb93a386Sopenharmony_ci#ifndef SkTraceEventCommon_DEFINED
5cb93a386Sopenharmony_ci#define SkTraceEventCommon_DEFINED
6cb93a386Sopenharmony_ci
7cb93a386Sopenharmony_ci#include "include/core/SkTypes.h"
8cb93a386Sopenharmony_ci#include "include/utils/SkTraceEventPhase.h"
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci// Trace events are for tracking application performance and resource usage.
11cb93a386Sopenharmony_ci// Macros are provided to track:
12cb93a386Sopenharmony_ci//    Duration of scoped regions
13cb93a386Sopenharmony_ci//    Instantaneous events
14cb93a386Sopenharmony_ci//    Counters
15cb93a386Sopenharmony_ci//
16cb93a386Sopenharmony_ci// The first two arguments to all TRACE macros are the category and name. Both are strings, and
17cb93a386Sopenharmony_ci// must have application lifetime (statics or literals). The same applies to arg_names, and string
18cb93a386Sopenharmony_ci// argument values. However, you can force a copy of a string argument value with TRACE_STR_COPY:
19cb93a386Sopenharmony_ci//     TRACE_EVENT1("category", "name", "arg1", "literal string is only referenced");
20cb93a386Sopenharmony_ci//     TRACE_EVENT1("category", "name", "arg1", TRACE_STR_COPY("string will be copied"));
21cb93a386Sopenharmony_ci//
22cb93a386Sopenharmony_ci//
23cb93a386Sopenharmony_ci// Categories are used to group events, and
24cb93a386Sopenharmony_ci// can be enabled or disabled by the tracing framework. The trace system will automatically add the
25cb93a386Sopenharmony_ci// process id, thread id, and microsecond timestamp to all events.
26cb93a386Sopenharmony_ci//
27cb93a386Sopenharmony_ci//
28cb93a386Sopenharmony_ci// The TRACE_EVENT[0-2] macros trace the duration of entire scopes:
29cb93a386Sopenharmony_ci//   void doSomethingCostly() {
30cb93a386Sopenharmony_ci//     TRACE_EVENT0("MY_SUBSYSTEM", "doSomethingCostly");
31cb93a386Sopenharmony_ci//     ...
32cb93a386Sopenharmony_ci//   }
33cb93a386Sopenharmony_ci//
34cb93a386Sopenharmony_ci// Additional parameters can be associated with an event:
35cb93a386Sopenharmony_ci//   void doSomethingCostly2(int howMuch) {
36cb93a386Sopenharmony_ci//     TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly", "howMuch", howMuch);
37cb93a386Sopenharmony_ci//     ...
38cb93a386Sopenharmony_ci//   }
39cb93a386Sopenharmony_ci//
40cb93a386Sopenharmony_ci//
41cb93a386Sopenharmony_ci// Trace event also supports counters, which is a way to track a quantity as it varies over time.
42cb93a386Sopenharmony_ci// Counters are created with the following macro:
43cb93a386Sopenharmony_ci//   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue);
44cb93a386Sopenharmony_ci//
45cb93a386Sopenharmony_ci// Counters are process-specific. The macro itself can be issued from any thread, however.
46cb93a386Sopenharmony_ci//
47cb93a386Sopenharmony_ci// Sometimes, you want to track two counters at once. You can do this with two counter macros:
48cb93a386Sopenharmony_ci//   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]);
49cb93a386Sopenharmony_ci//   TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter1", g_myCounterValue[1]);
50cb93a386Sopenharmony_ci// Or you can do it with a combined macro:
51cb93a386Sopenharmony_ci//   TRACE_COUNTER2("MY_SUBSYSTEM", "myCounter",
52cb93a386Sopenharmony_ci//                  "bytesPinned", g_myCounterValue[0],
53cb93a386Sopenharmony_ci//                  "bytesAllocated", g_myCounterValue[1]);
54cb93a386Sopenharmony_ci// The tracing UI will show these counters in a single graph, as a summed area chart.
55cb93a386Sopenharmony_ci
56cb93a386Sopenharmony_ci#if defined(TRACE_EVENT0)
57cb93a386Sopenharmony_ci#error "Another copy of this file has already been included."
58cb93a386Sopenharmony_ci#endif
59cb93a386Sopenharmony_ci
60cb93a386Sopenharmony_ci#define TRACE_EMPTY do {} while (0)
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ci#ifdef SK_DISABLE_TRACING
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) TRACE_EMPTY
65cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) TRACE_EMPTY
66cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_ALWAYS(name) TRACE_EMPTY
67cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_FMT_ALWAYS(fmt, ...) TRACE_EMPTY
68cb93a386Sopenharmony_ci#define SKIA_OHOS_TRACE_PRIV(category_group, name) TRACE_EMPTY
69cb93a386Sopenharmony_ci#define TRACE_EVENT0(cg, n) TRACE_EMPTY
70cb93a386Sopenharmony_ci#define TRACE_EVENT0_ALWAYS(cg, n) TRACE_EMPTY
71cb93a386Sopenharmony_ci#define TRACE_EVENT1(cg, n, a1n, a1v) TRACE_EMPTY
72cb93a386Sopenharmony_ci#define TRACE_EVENT2(cg, n, a1n, a1v, a2n, a2v) TRACE_EMPTY
73cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT0(cg, n, scope) TRACE_EMPTY
74cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT1(cg, n, scope, a1n, a1v) TRACE_EMPTY
75cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT2(cg, n, scope, a1n, a1v, a2n, a2v) TRACE_EMPTY
76cb93a386Sopenharmony_ci#define TRACE_COUNTER1(cg, n, value) TRACE_EMPTY
77cb93a386Sopenharmony_ci#define TRACE_COUNTER2(cg, n, v1n, v1v, v2n, v2v) TRACE_EMPTY
78cb93a386Sopenharmony_ci
79cb93a386Sopenharmony_ci#elif defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
80cb93a386Sopenharmony_ci
81cb93a386Sopenharmony_ci#include <cutils/trace.h>
82cb93a386Sopenharmony_ci#include <stdarg.h>
83cb93a386Sopenharmony_ci
84cb93a386Sopenharmony_ciclass SkAndroidFrameworkTraceUtil {
85cb93a386Sopenharmony_cipublic:
86cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtil(const char* name) {
87cb93a386Sopenharmony_ci        if (CC_UNLIKELY(gEnableAndroidTracing)) {
88cb93a386Sopenharmony_ci            ATRACE_BEGIN(name);
89cb93a386Sopenharmony_ci        }
90cb93a386Sopenharmony_ci    }
91cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtil(bool, const char* fmt, ...) {
92cb93a386Sopenharmony_ci        if (CC_LIKELY((!gEnableAndroidTracing) || (!ATRACE_ENABLED()))) return;
93cb93a386Sopenharmony_ci
94cb93a386Sopenharmony_ci        const int BUFFER_SIZE = 256;
95cb93a386Sopenharmony_ci        va_list ap;
96cb93a386Sopenharmony_ci        char buf[BUFFER_SIZE];
97cb93a386Sopenharmony_ci
98cb93a386Sopenharmony_ci        va_start(ap, fmt);
99cb93a386Sopenharmony_ci        vsnprintf(buf, BUFFER_SIZE, fmt, ap);
100cb93a386Sopenharmony_ci        va_end(ap);
101cb93a386Sopenharmony_ci
102cb93a386Sopenharmony_ci        ATRACE_BEGIN(buf);
103cb93a386Sopenharmony_ci    }
104cb93a386Sopenharmony_ci    ~SkAndroidFrameworkTraceUtil() {
105cb93a386Sopenharmony_ci        if (CC_UNLIKELY(gEnableAndroidTracing)) {
106cb93a386Sopenharmony_ci            ATRACE_END();
107cb93a386Sopenharmony_ci        }
108cb93a386Sopenharmony_ci    }
109cb93a386Sopenharmony_ci
110cb93a386Sopenharmony_ci    static void setEnableTracing(bool enableAndroidTracing) {
111cb93a386Sopenharmony_ci        gEnableAndroidTracing = enableAndroidTracing;
112cb93a386Sopenharmony_ci    }
113cb93a386Sopenharmony_ci
114cb93a386Sopenharmony_ci    static bool getEnableTracing() {
115cb93a386Sopenharmony_ci        return gEnableAndroidTracing;
116cb93a386Sopenharmony_ci    }
117cb93a386Sopenharmony_ci
118cb93a386Sopenharmony_ciprivate:
119cb93a386Sopenharmony_ci    static bool gEnableAndroidTracing;
120cb93a386Sopenharmony_ci};
121cb93a386Sopenharmony_ci
122cb93a386Sopenharmony_ciclass SkAndroidFrameworkTraceUtilAlways {
123cb93a386Sopenharmony_cipublic:
124cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtilAlways(const char* fmt, ...) {
125cb93a386Sopenharmony_ci        if (!ATRACE_ENABLED()) return;
126cb93a386Sopenharmony_ci
127cb93a386Sopenharmony_ci        const int BUFFER_SIZE = 256;
128cb93a386Sopenharmony_ci        va_list ap;
129cb93a386Sopenharmony_ci        char buf[BUFFER_SIZE];
130cb93a386Sopenharmony_ci
131cb93a386Sopenharmony_ci        va_start(ap, fmt);
132cb93a386Sopenharmony_ci        vsnprintf(buf, BUFFER_SIZE, fmt, ap);
133cb93a386Sopenharmony_ci        va_end(ap);
134cb93a386Sopenharmony_ci
135cb93a386Sopenharmony_ci        ATRACE_BEGIN(buf);
136cb93a386Sopenharmony_ci    }
137cb93a386Sopenharmony_ci    ~SkAndroidFrameworkTraceUtilAlways() {
138cb93a386Sopenharmony_ci        ATRACE_END();
139cb93a386Sopenharmony_ci    }
140cb93a386Sopenharmony_ci};
141cb93a386Sopenharmony_ci
142cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) SkAndroidFrameworkTraceUtil __trace(true, fmt, ##__VA_ARGS__)
143cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) SkAndroidFrameworkTraceUtilAlways __trace_always(fmt, ##__VA_ARGS__)
144cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_ALWAYS(name) TRACE_EMPTY
145cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_FMT_ALWAYS(fmt, ...) TRACE_EMPTY
146cb93a386Sopenharmony_ci#define SKIA_OHOS_TRACE_PRIV(category_group, name) TRACE_EMPTY
147cb93a386Sopenharmony_ci
148cb93a386Sopenharmony_ci// Records a pair of begin and end events called "name" for the current scope, with 0, 1 or 2
149cb93a386Sopenharmony_ci// associated arguments. In the framework, the arguments are ignored.
150cb93a386Sopenharmony_ci#define TRACE_EVENT0(category_group, name) \
151cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtil __trace(name)
152cb93a386Sopenharmony_ci#define TRACE_EVENT0_ALWAYS(category_group, name) \
153cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtilAlways __trace_always(name)
154cb93a386Sopenharmony_ci#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
155cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtil __trace(name)
156cb93a386Sopenharmony_ci#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
157cb93a386Sopenharmony_ci    SkAndroidFrameworkTraceUtil __trace(name)
158cb93a386Sopenharmony_ci
159cb93a386Sopenharmony_ci// Records a single event called "name" immediately, with 0, 1 or 2 associated arguments. If the
160cb93a386Sopenharmony_ci// category is not enabled, then this does nothing.
161cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT0(category_group, name, scope) \
162cb93a386Sopenharmony_ci    do { SkAndroidFrameworkTraceUtil __trace(name); } while(0)
163cb93a386Sopenharmony_ci
164cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
165cb93a386Sopenharmony_ci    do { SkAndroidFrameworkTraceUtil __trace(name); } while(0)
166cb93a386Sopenharmony_ci
167cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
168cb93a386Sopenharmony_ci                             arg2_name, arg2_val)                              \
169cb93a386Sopenharmony_ci    do { SkAndroidFrameworkTraceUtil __trace(name); } while(0)
170cb93a386Sopenharmony_ci
171cb93a386Sopenharmony_ci// Records the value of a counter called "name" immediately. Value
172cb93a386Sopenharmony_ci// must be representable as a 32 bit integer.
173cb93a386Sopenharmony_ci#define TRACE_COUNTER1(category_group, name, value) \
174cb93a386Sopenharmony_ci    if (CC_UNLIKELY(SkAndroidFrameworkTraceUtil::getEnableTracing())) { \
175cb93a386Sopenharmony_ci        ATRACE_INT(name, value); \
176cb93a386Sopenharmony_ci    }
177cb93a386Sopenharmony_ci
178cb93a386Sopenharmony_ci// Records the values of a multi-parted counter called "name" immediately.
179cb93a386Sopenharmony_ci// In Chrome, this macro produces a stacked bar chart. ATrace doesn't support
180cb93a386Sopenharmony_ci// that, so this just produces two separate counters.
181cb93a386Sopenharmony_ci#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, value2_name, value2_val) \
182cb93a386Sopenharmony_ci    do { \
183cb93a386Sopenharmony_ci        if (CC_UNLIKELY(SkAndroidFrameworkTraceUtil::getEnableTracing())) { \
184cb93a386Sopenharmony_ci            ATRACE_INT(name "-" value1_name, value1_val); \
185cb93a386Sopenharmony_ci            ATRACE_INT(name "-" value2_name, value2_val); \
186cb93a386Sopenharmony_ci        } \
187cb93a386Sopenharmony_ci    } while (0)
188cb93a386Sopenharmony_ci
189cb93a386Sopenharmony_ci// ATrace has no object tracking
190cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) TRACE_EMPTY
191cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) TRACE_EMPTY
192cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) TRACE_EMPTY
193cb93a386Sopenharmony_ci
194cb93a386Sopenharmony_ci// Macro to efficiently determine if a given category group is enabled.
195cb93a386Sopenharmony_ci// This is only used for some shader text logging that isn't supported in ATrace anyway.
196cb93a386Sopenharmony_ci#define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret)             \
197cb93a386Sopenharmony_ci  do { *ret = false; } while (0)
198cb93a386Sopenharmony_ci
199cb93a386Sopenharmony_ci#elif defined(SKIA_OHOS_FOR_OHOS_TRACE)
200cb93a386Sopenharmony_ci
201cb93a386Sopenharmony_ci#include "hitrace_meter.h"
202cb93a386Sopenharmony_ci
203cb93a386Sopenharmony_ci#define UNLIKELY(exp) (__builtin_expect((exp) != 0, false))
204cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) TRACE_EMPTY
205cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) TRACE_EMPTY
206cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_ALWAYS(name) HITRACE_METER_NAME(HITRACE_TAG_GRAPHIC_AGP | HITRACE_TAG_COMMERCIAL, name)
207cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_FMT_ALWAYS(fmt, ...) \
208cb93a386Sopenharmony_ci    HITRACE_METER_FMT(HITRACE_TAG_GRAPHIC_AGP | HITRACE_TAG_COMMERCIAL, fmt, ##__VA_ARGS__)
209cb93a386Sopenharmony_ci
210cb93a386Sopenharmony_ci// print ohos trace without SKIA_OHOS_DEBUG macro
211cb93a386Sopenharmony_ci#define SKIA_OHOS_TRACE_PRIV(category_group, name) \
212cb93a386Sopenharmony_ci    HitraceScoped _trace(HITRACE_TAG_GRAPHIC_AGP, name)
213cb93a386Sopenharmony_ci
214cb93a386Sopenharmony_ci// Records a pair of begin and end events called "name" for the current scope, with 0, 1 or 2
215cb93a386Sopenharmony_ci// associated arguments. If the category is not enabled, then this does nothing.
216cb93a386Sopenharmony_ci#ifdef SKIA_OHOS_DEBUG
217cb93a386Sopenharmony_ci#define TRACE_EVENT0(category_group, name) \
218cb93a386Sopenharmony_ci    HitraceScoped _trace(HITRACE_TAG_GRAPHIC_AGP, name)
219cb93a386Sopenharmony_ci
220cb93a386Sopenharmony_ci#define TRACE_EVENT0_ALWAYS(category_group, name) \
221cb93a386Sopenharmony_ci    HitraceScoped _trace(HITRACE_TAG_GRAPHIC_AGP, name)
222cb93a386Sopenharmony_ci
223cb93a386Sopenharmony_ci#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
224cb93a386Sopenharmony_ci    HitraceScoped _trace(HITRACE_TAG_GRAPHIC_AGP, name)
225cb93a386Sopenharmony_ci
226cb93a386Sopenharmony_ci#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
227cb93a386Sopenharmony_ci    HitraceScoped _trace(HITRACE_TAG_GRAPHIC_AGP, name)
228cb93a386Sopenharmony_ci#else
229cb93a386Sopenharmony_ci#define TRACE_EVENT0(category_group, name) TRACE_EMPTY
230cb93a386Sopenharmony_ci#define TRACE_EVENT0_ALWAYS(category_group, name) TRACE_EMPTY
231cb93a386Sopenharmony_ci#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) TRACE_EMPTY
232cb93a386Sopenharmony_ci#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) TRACE_EMPTY
233cb93a386Sopenharmony_ci#endif
234cb93a386Sopenharmony_ci
235cb93a386Sopenharmony_ci// Records a single event called "name" immediately, with 0, 1 or 2 associated arguments. If the
236cb93a386Sopenharmony_ci// category is not enabled, then this does nothing.
237cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT0(category_group, name, scope) TRACE_EMPTY
238cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) TRACE_EMPTY
239cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, arg2_name, arg2_val) TRACE_EMPTY
240cb93a386Sopenharmony_ci
241cb93a386Sopenharmony_ci// Records the value of a counter called "name" immediately. Value
242cb93a386Sopenharmony_ci// must be representable as a 32 bit integer.
243cb93a386Sopenharmony_ci#define TRACE_COUNTER1(category_group, name, value) TRACE_EMPTY
244cb93a386Sopenharmony_ci
245cb93a386Sopenharmony_ci// Records the values of a multi-parted counter called "name" immediately.
246cb93a386Sopenharmony_ci#ifdef SKIA_OHOS_DEBUG
247cb93a386Sopenharmony_ci#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, value2_name, value2_val) \
248cb93a386Sopenharmony_ci    do { \
249cb93a386Sopenharmony_ci        if (UNLIKELY(IsTagEnabled(HITRACE_TAG_GRAPHIC_AGP))) { \
250cb93a386Sopenharmony_ci            std::string tid = std::to_string(gettid()); \
251cb93a386Sopenharmony_ci            std::string threadValue1Name = tid + "-" + name + "-" + value1_name; \
252cb93a386Sopenharmony_ci            std::string threadValue2Name = tid + "-" + name + "-" + value2_name; \
253cb93a386Sopenharmony_ci            CountTrace(HITRACE_TAG_GRAPHIC_AGP, threadValue1Name, value1_val); \
254cb93a386Sopenharmony_ci            CountTrace(HITRACE_TAG_GRAPHIC_AGP, threadValue2Name, value2_val); \
255cb93a386Sopenharmony_ci        } \
256cb93a386Sopenharmony_ci    } while (0)
257cb93a386Sopenharmony_ci#else
258cb93a386Sopenharmony_ci#define TRACE_COUNTER2(category_group, name, value1_name, value1_val, value2_name, value2_val) TRACE_EMPTY
259cb93a386Sopenharmony_ci#endif
260cb93a386Sopenharmony_ci
261cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_BEGIN0(category, name, id) TRACE_EMPTY
262cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val) TRACE_EMPTY
263cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) TRACE_EMPTY
264cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_END0(category, name, id) TRACE_EMPTY
265cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_END1(category, name, id, arg1_name, arg1_val) TRACE_EMPTY
266cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) TRACE_EMPTY
267cb93a386Sopenharmony_ci
268cb93a386Sopenharmony_ci// Macros to track the life time and value of arbitrary client objects.
269cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) TRACE_EMPTY
270cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, snapshot) TRACE_EMPTY
271cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) TRACE_EMPTY
272cb93a386Sopenharmony_ci
273cb93a386Sopenharmony_ci// Macro to efficiently determine if a given category group is enabled.
274cb93a386Sopenharmony_ci#define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret)             \
275cb93a386Sopenharmony_ci    do { *ret = false; } while (0)
276cb93a386Sopenharmony_ci
277cb93a386Sopenharmony_ci#else // !SK_BUILD_FOR_ANDROID_FRAMEWORK && !SK_DISABLE_TRACING
278cb93a386Sopenharmony_ci
279cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK(fmt, ...) TRACE_EMPTY
280cb93a386Sopenharmony_ci#define ATRACE_ANDROID_FRAMEWORK_ALWAYS(fmt, ...) TRACE_EMPTY
281cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_ALWAYS(name) TRACE_EMPTY
282cb93a386Sopenharmony_ci#define HITRACE_OHOS_NAME_FMT_ALWAYS(fmt, ...) TRACE_EMPTY
283cb93a386Sopenharmony_ci#define SKIA_OHOS_TRACE_PRIV(category_group, name) TRACE_EMPTY
284cb93a386Sopenharmony_ci
285cb93a386Sopenharmony_ci// Records a pair of begin and end events called "name" for the current scope, with 0, 1 or 2
286cb93a386Sopenharmony_ci// associated arguments. If the category is not enabled, then this does nothing.
287cb93a386Sopenharmony_ci#define TRACE_EVENT0(category_group, name) \
288cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
289cb93a386Sopenharmony_ci
290cb93a386Sopenharmony_ci#define TRACE_EVENT0_ALWAYS(category_group, name) \
291cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name)
292cb93a386Sopenharmony_ci
293cb93a386Sopenharmony_ci#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val) \
294cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val)
295cb93a386Sopenharmony_ci
296cb93a386Sopenharmony_ci#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val) \
297cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
298cb93a386Sopenharmony_ci
299cb93a386Sopenharmony_ci// Records a single event called "name" immediately, with 0, 1 or 2 associated arguments. If the
300cb93a386Sopenharmony_ci// category is not enabled, then this does nothing.
301cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT0(category_group, name, scope)                   \
302cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name, \
303cb93a386Sopenharmony_ci                           TRACE_EVENT_FLAG_NONE | scope)
304cb93a386Sopenharmony_ci
305cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT1(category_group, name, scope, arg1_name, arg1_val) \
306cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
307cb93a386Sopenharmony_ci                           TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val)
308cb93a386Sopenharmony_ci
309cb93a386Sopenharmony_ci#define TRACE_EVENT_INSTANT2(category_group, name, scope, arg1_name, arg1_val, \
310cb93a386Sopenharmony_ci                             arg2_name, arg2_val)                              \
311cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, category_group, name,    \
312cb93a386Sopenharmony_ci                           TRACE_EVENT_FLAG_NONE | scope, arg1_name, arg1_val, \
313cb93a386Sopenharmony_ci                           arg2_name, arg2_val)
314cb93a386Sopenharmony_ci
315cb93a386Sopenharmony_ci// Records the value of a counter called "name" immediately. Value
316cb93a386Sopenharmony_ci// must be representable as a 32 bit integer.
317cb93a386Sopenharmony_ci#define TRACE_COUNTER1(category_group, name, value)                         \
318cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
319cb93a386Sopenharmony_ci                           TRACE_EVENT_FLAG_NONE, "value",                  \
320cb93a386Sopenharmony_ci                           static_cast<int>(value))
321cb93a386Sopenharmony_ci
322cb93a386Sopenharmony_ci// Records the values of a multi-parted counter called "name" immediately.
323cb93a386Sopenharmony_ci// The UI will treat value1 and value2 as parts of a whole, displaying their
324cb93a386Sopenharmony_ci// values as a stacked-bar chart.
325cb93a386Sopenharmony_ci#define TRACE_COUNTER2(category_group, name, value1_name, value1_val,       \
326cb93a386Sopenharmony_ci                       value2_name, value2_val)                             \
327cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_COUNTER, category_group, name, \
328cb93a386Sopenharmony_ci                           TRACE_EVENT_FLAG_NONE, value1_name,              \
329cb93a386Sopenharmony_ci                           static_cast<int>(value1_val), value2_name,       \
330cb93a386Sopenharmony_ci                           static_cast<int>(value2_val))
331cb93a386Sopenharmony_ci
332cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_BEGIN0(category, name, id)                                           \
333cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                                          \
334cb93a386Sopenharmony_ci        TRACE_EVENT_PHASE_ASYNC_BEGIN, category, name, id, TRACE_EVENT_FLAG_NONE)
335cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_BEGIN1(category, name, id, arg1_name, arg1_val)                      \
336cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN,                            \
337cb93a386Sopenharmony_ci        category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
338cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_BEGIN2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
339cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_BEGIN,                            \
340cb93a386Sopenharmony_ci        category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
341cb93a386Sopenharmony_ci
342cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_END0(category, name, id)                                           \
343cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,                            \
344cb93a386Sopenharmony_ci        category, name, id, TRACE_EVENT_FLAG_NONE)
345cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_END1(category, name, id, arg1_name, arg1_val)                      \
346cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,                            \
347cb93a386Sopenharmony_ci        category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val)
348cb93a386Sopenharmony_ci#define TRACE_EVENT_ASYNC_END2(category, name, id, arg1_name, arg1_val, arg2_name, arg2_val) \
349cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_ASYNC_END,                            \
350cb93a386Sopenharmony_ci        category, name, id, TRACE_EVENT_FLAG_NONE, arg1_name, arg1_val, arg2_name, arg2_val)
351cb93a386Sopenharmony_ci
352cb93a386Sopenharmony_ci// Macros to track the life time and value of arbitrary client objects.
353cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_CREATED_WITH_ID(category_group, name, id) \
354cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
355cb93a386Sopenharmony_ci      TRACE_EVENT_PHASE_CREATE_OBJECT, category_group, name, id,     \
356cb93a386Sopenharmony_ci      TRACE_EVENT_FLAG_NONE)
357cb93a386Sopenharmony_ci
358cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(category_group, name, id, \
359cb93a386Sopenharmony_ci                                            snapshot)                 \
360cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                   \
361cb93a386Sopenharmony_ci      TRACE_EVENT_PHASE_SNAPSHOT_OBJECT, category_group, name,        \
362cb93a386Sopenharmony_ci      id, TRACE_EVENT_FLAG_NONE, "snapshot", snapshot)
363cb93a386Sopenharmony_ci
364cb93a386Sopenharmony_ci#define TRACE_EVENT_OBJECT_DELETED_WITH_ID(category_group, name, id) \
365cb93a386Sopenharmony_ci  INTERNAL_TRACE_EVENT_ADD_WITH_ID(                                  \
366cb93a386Sopenharmony_ci      TRACE_EVENT_PHASE_DELETE_OBJECT, category_group, name, id,     \
367cb93a386Sopenharmony_ci      TRACE_EVENT_FLAG_NONE)
368cb93a386Sopenharmony_ci
369cb93a386Sopenharmony_ci// Macro to efficiently determine if a given category group is enabled.
370cb93a386Sopenharmony_ci#define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret)             \
371cb93a386Sopenharmony_ci  do {                                                                      \
372cb93a386Sopenharmony_ci    INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group);                 \
373cb93a386Sopenharmony_ci    if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
374cb93a386Sopenharmony_ci      *ret = true;                                                          \
375cb93a386Sopenharmony_ci    } else {                                                                \
376cb93a386Sopenharmony_ci      *ret = false;                                                         \
377cb93a386Sopenharmony_ci    }                                                                       \
378cb93a386Sopenharmony_ci  } while (0)
379cb93a386Sopenharmony_ci
380cb93a386Sopenharmony_ci#endif
381cb93a386Sopenharmony_ci
382cb93a386Sopenharmony_ci// Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
383cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_NONE (static_cast<unsigned int>(0))
384cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_COPY (static_cast<unsigned int>(1 << 0))
385cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_HAS_ID (static_cast<unsigned int>(1 << 1))
386cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_MANGLE_ID (static_cast<unsigned int>(1 << 2))
387cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_SCOPE_OFFSET (static_cast<unsigned int>(1 << 3))
388cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_SCOPE_EXTRA (static_cast<unsigned int>(1 << 4))
389cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP (static_cast<unsigned int>(1 << 5))
390cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_ASYNC_TTS (static_cast<unsigned int>(1 << 6))
391cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_BIND_TO_ENCLOSING (static_cast<unsigned int>(1 << 7))
392cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_FLOW_IN (static_cast<unsigned int>(1 << 8))
393cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_FLOW_OUT (static_cast<unsigned int>(1 << 9))
394cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_HAS_CONTEXT_ID (static_cast<unsigned int>(1 << 10))
395cb93a386Sopenharmony_ci
396cb93a386Sopenharmony_ci#define TRACE_EVENT_FLAG_SCOPE_MASK                          \
397cb93a386Sopenharmony_ci  (static_cast<unsigned int>(TRACE_EVENT_FLAG_SCOPE_OFFSET | \
398cb93a386Sopenharmony_ci                             TRACE_EVENT_FLAG_SCOPE_EXTRA))
399cb93a386Sopenharmony_ci
400cb93a386Sopenharmony_ci// Type values for identifying types in the TraceValue union.
401cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_BOOL (static_cast<unsigned char>(1))
402cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_UINT (static_cast<unsigned char>(2))
403cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_INT (static_cast<unsigned char>(3))
404cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_DOUBLE (static_cast<unsigned char>(4))
405cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_POINTER (static_cast<unsigned char>(5))
406cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_STRING (static_cast<unsigned char>(6))
407cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_COPY_STRING (static_cast<unsigned char>(7))
408cb93a386Sopenharmony_ci#define TRACE_VALUE_TYPE_CONVERTABLE (static_cast<unsigned char>(8))
409cb93a386Sopenharmony_ci
410cb93a386Sopenharmony_ci// Enum reflecting the scope of an INSTANT event. Must fit within TRACE_EVENT_FLAG_SCOPE_MASK.
411cb93a386Sopenharmony_ci#define TRACE_EVENT_SCOPE_GLOBAL (static_cast<unsigned char>(0 << 3))
412cb93a386Sopenharmony_ci#define TRACE_EVENT_SCOPE_PROCESS (static_cast<unsigned char>(1 << 3))
413cb93a386Sopenharmony_ci#define TRACE_EVENT_SCOPE_THREAD (static_cast<unsigned char>(2 << 3))
414cb93a386Sopenharmony_ci
415cb93a386Sopenharmony_ci#define TRACE_EVENT_SCOPE_NAME_GLOBAL ('g')
416cb93a386Sopenharmony_ci#define TRACE_EVENT_SCOPE_NAME_PROCESS ('p')
417cb93a386Sopenharmony_ci#define TRACE_EVENT_SCOPE_NAME_THREAD ('t')
418cb93a386Sopenharmony_ci
419cb93a386Sopenharmony_ci#endif  // SkTraceEventCommon_DEFINED
420