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