Flutter Engine
The Flutter Engine
EventTracingPriv.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
11#include "src/core/SkATrace.h"
16
17// SkPerfettoTrace is only relevant when Perfetto is requested, and for in-process tracing. It is
18// incompatible with the alternate "direct macro override" approach to using Perfetto, which is
19// currently used for SK_BUILD_FOR_ANDROID_FRAMEWORK. Skia's Perfetto integration is currently in
20// in a transitionary period, see go/skia-perfetto for details.
21#if defined(SK_USE_PERFETTO)
22 #if defined(SK_ANDROID_FRAMEWORK_USE_PERFETTO)
23 #error "SK_USE_PERFETTO and SK_ANDROID_FRAMEWORK_USE_PERFETTO are mutually exclusive"
24 #endif
25
27#endif
28
29static DEFINE_string(trace,
30 "",
31 "Log trace events in one of several modes:\n"
32 " debugf : Show events using SkDebugf\n"
33 " atrace : Send events to Android ATrace\n"
34 " perfetto : Send events to Perfetto (Linux, Android, and Mac only)\n"
35 " <filename> : Any other string is interpreted as a filename. Writes\n"
36 " trace events to specified file as JSON, for viewing\n"
37 " with chrome://tracing");
38
39static DEFINE_string(traceMatch,
40 "",
41 "Filter which categories are traced.\n"
42 "Uses same format as --match\n");
43
44void initializeEventTracingForTools(const char* traceFlag) {
45 if (!traceFlag) {
46 if (FLAGS_trace.isEmpty()) {
47 return;
48 }
49 traceFlag = FLAGS_trace[0];
50 }
51
52 SkEventTracer* eventTracer = nullptr;
53 if (0 == strcmp(traceFlag, "atrace")) {
54 eventTracer = new SkATrace();
55 } else if (0 == strcmp(traceFlag, "debugf")) {
56 eventTracer = new SkDebugfTracer();
57 } else if (0 == strcmp(traceFlag, "perfetto")) {
58 #if defined(SK_USE_PERFETTO)
59 eventTracer = new SkPerfettoTrace();
60 #else
61 // TODO(b/259248961): update this explanation (and associated docs) as the Perfetto
62 // transition progresses.
63 SkDebugf("Perfetto is not enabled (SK_USE_PERFETTO is false). Perfetto tracing will not "
64 "be performed.\nTracing tools with Perfetto is only enabled for Linux, Android, "
65 "and Mac.\n");
66 return;
67 #endif
68 }
69 else {
70 eventTracer = new ChromeTracingTracer(traceFlag);
71 }
72
74}
75
77 static_assert(0 == offsetof(CategoryState, fEnabled), "CategoryState");
78
79 // We ignore the "disabled-by-default-" prefix in our internal tools
81 name += strlen(TRACE_CATEGORY_PREFIX);
82 }
83
84 // Chrome's implementation of this API does a two-phase lookup (once without a lock, then again
85 // with a lock. But the tracing macros avoid calling these functions more than once per site,
86 // so just do something simple (and easier to reason about):
87 SkAutoMutexExclusive lock(fMutex);
88 for (int i = 0; i < fNumCategories; ++i) {
89 if (0 == strcmp(name, fCategories[i].fName)) {
90 return reinterpret_cast<uint8_t*>(&fCategories[i]);
91 }
92 }
93
94 if (fNumCategories >= kMaxCategories) {
95 SkDEBUGFAIL("Exhausted event tracing categories. Increase kMaxCategories.");
96 return reinterpret_cast<uint8_t*>(&fCategories[0]);
97 }
98
99 fCategories[fNumCategories].fEnabled =
100 CommandLineFlags::ShouldSkip(FLAGS_traceMatch, name)
101 ? 0
103
104 fCategories[fNumCategories].fName = name;
105 return reinterpret_cast<uint8_t*>(&fCategories[fNumCategories++]);
106}
107
108const char* SkEventTracingCategories::getCategoryGroupName(const uint8_t* categoryEnabledFlag) {
109 if (categoryEnabledFlag) {
110 return reinterpret_cast<const CategoryState*>(categoryEnabledFlag)->fName;
111 }
112 return nullptr;
113}
void initializeEventTracingForTools(const char *traceFlag)
static DEFINE_string(trace, "", "Log trace events in one of several modes:\n" " debugf : Show events using SkDebugf\n" " atrace : Send events to Android ATrace\n" " perfetto : Send events to Perfetto (Linux, Android, and Mac only)\n" " <filename> : Any other string is interpreted as a filename. Writes\n" " trace events to specified file as JSON, for viewing\n" " with chrome://tracing")
const char * fName
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static bool SkStrStartsWith(const char string[], const char prefixStr[])
Definition: SkString.h:26
#define TRACE_CATEGORY_PREFIX
Definition: SkTraceEvent.h:129
static bool ShouldSkip(const SkTDArray< const char * > &strings, const char *name)
static bool SetInstance(SkEventTracer *, bool leakTracer=false)
@ kEnabledForRecording_CategoryGroupEnabledFlags
Definition: SkEventTracer.h:55
const char * getCategoryGroupName(const uint8_t *categoryEnabledFlag)
uint8_t * getCategoryGroupEnabled(const char *name)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32