19 "Output directory for perfetto trace file(s).\n"
20 "Note: not the name of the file itself.\n"
21 "Will only have an effect if perfetto tracing is enabled. See --trace.");
23 "Output file name (excluding path and file extension) for the perfetto trace"
24 "file.\nNote: When splitting trace files by benchmark (see "
25 "--splitPerfettoTracesByBenchmark), file name will be determined by the "
27 "Will only have an effect if perfetto tracing is enabled. See --trace.");
29 "Output file extension for perfetto trace file(s).\n"
30 "Will only have an effect if perfetto tracing is enabled. See --trace.");
32 "Perfetto within Skia is optimized for tracing performance of 'smaller' traces"
33 "(~10 seconds or less). Set this flag to true to optimize for longer tracing"
35 "Will only have an effect if perfetto tracing is enabled. See --trace.");
38 fOutputPath = FLAGS_perfettoOutputDir[0];
39 fOutputFileExtension = FLAGS_perfettoOutputFileExtension[0];
40 this->openNewTracingSession(FLAGS_perfettoOutputFileName[0]);
44 this->closeTracingSession();
47void SkPerfettoTrace::openNewTracingSession(
const std::string& baseFileName) {
48 perfetto::TracingInitArgs
args;
52 fCurrentSessionFullOutputPath = fOutputPath + baseFileName + fOutputFileExtension;
56 args.backends |= perfetto::kInProcessBackend;
58 if (FLAGS_longPerfettoTrace) {
61 args.shmem_size_hint_kb = 2000;
67 perfetto::protos::gen::TrackEventConfig track_event_cfg;
68 perfetto::TraceConfig cfg;
71 cfg.add_buffers()->set_size_kb(32000);
73 if (FLAGS_longPerfettoTrace) {
76 cfg.set_write_into_file(
true);
79 cfg.set_file_write_period_ms(5000);
82 cfg.set_flush_period_ms(10000);
85 auto* ds_cfg = cfg.add_data_sources()->mutable_config();
86 ds_cfg->set_name(
"track_event");
87 ds_cfg->set_track_event_config_raw(track_event_cfg.SerializeAsString());
90 tracingSession = perfetto::Tracing::NewTrace();
91 if (FLAGS_longPerfettoTrace) {
92 fd = open(fCurrentSessionFullOutputPath.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0600);
93 tracingSession->Setup(cfg, fd);
95 tracingSession->Setup(cfg);
97 tracingSession->StartBlocking();
100void SkPerfettoTrace::closeTracingSession() {
102 tracingSession->StopBlocking();
103 if (!FLAGS_longPerfettoTrace) {
104 std::vector<char> trace_data(tracingSession->ReadTraceBlocking());
107 output.write(&trace_data[0], trace_data.size());
115 const uint8_t* categoryEnabledFlag,
119 const char** argNames,
120 const uint8_t* argTypes,
121 const uint64_t* argValues,
128 this->triggerTraceEvent(categoryEnabledFlag,
name);
132 this->triggerTraceEvent(categoryEnabledFlag,
name, argNames[0], argTypes[0],
137 this->triggerTraceEvent(categoryEnabledFlag,
name, argNames[0], argTypes[0],
138 argValues[0], argNames[1], argTypes[1], argValues[1]);
143 TRACE_EVENT_END(category);
147 TRACE_EVENT_END(category);
157 TRACE_EVENT_END(category);
168void SkPerfettoTrace::triggerTraceEvent(
const uint8_t* categoryEnabledFlag,
169 const char* eventName) {
171 TRACE_EVENT_BEGIN(category,
nullptr, [&](perfetto::EventContext ctx) {
172 ctx.event()->set_name(eventName);
176void SkPerfettoTrace::triggerTraceEvent(
const uint8_t* categoryEnabledFlag,
const char* eventName,
177 const char* arg1Name,
const uint8_t& arg1Type,
178 const uint64_t& arg1Val) {
183 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name,
SkToBool(arg1Val),
184 [&](perfetto::EventContext ctx) {
185 ctx.event()->set_name(eventName); });
189 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val,
190 [&](perfetto::EventContext ctx) {
191 ctx.event()->set_name(eventName); });
195 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name,
static_cast<int64_t
>(arg1Val),
196 [&](perfetto::EventContext ctx) {
197 ctx.event()->set_name(eventName); });
201 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, sk_bit_cast<double>(arg1Val),
202 [&](perfetto::EventContext ctx) {
203 ctx.event()->set_name(eventName); });
207 TRACE_EVENT_BEGIN(category,
nullptr,
209 [&](perfetto::EventContext ctx) {
210 ctx.event()->set_name(eventName); });
215 TRACE_EVENT_BEGIN(category,
nullptr,
217 [&](perfetto::EventContext ctx) {
218 ctx.event()->set_name(eventName); });
232void begin_event_with_second_arg(
const char * categoryName,
const char* eventName,
233 const char* arg1Name,
T arg1Val,
const char* arg2Name,
234 const uint8_t& arg2Type,
const uint64_t& arg2Val) {
235 perfetto::DynamicCategory category{categoryName};
239 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val, arg2Name,
SkToBool(arg2Val),
240 [&](perfetto::EventContext ctx) {
241 ctx.event()->set_name(eventName); });
245 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val, arg2Name, arg2Val,
246 [&](perfetto::EventContext ctx) {
247 ctx.event()->set_name(eventName); });
251 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val,
252 arg2Name,
static_cast<int64_t
>(arg2Val),
253 [&](perfetto::EventContext ctx) {
254 ctx.event()->set_name(eventName); });
258 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val,
259 arg2Name, sk_bit_cast<double>(arg2Val),
260 [&](perfetto::EventContext ctx) {
261 ctx.event()->set_name(eventName); });
265 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val,
267 [&](perfetto::EventContext ctx) {
268 ctx.event()->set_name(eventName); });
273 TRACE_EVENT_BEGIN(category,
nullptr, arg1Name, arg1Val,
275 [&](perfetto::EventContext ctx) {
276 ctx.event()->set_name(eventName); });
287void SkPerfettoTrace::triggerTraceEvent(
const uint8_t* categoryEnabledFlag,
288 const char* eventName,
const char* arg1Name,
289 const uint8_t& arg1Type,
const uint64_t& arg1Val,
290 const char* arg2Name,
const uint8_t& arg2Type,
291 const uint64_t& arg2Val) {
297 begin_event_with_second_arg(category, eventName, arg1Name,
SkToBool(arg1Val),
298 arg2Name, arg2Type, arg2Val);
302 begin_event_with_second_arg(category, eventName, arg1Name, arg1Val,
303 arg2Name, arg2Type, arg2Val);
307 begin_event_with_second_arg(category, eventName,
308 arg1Name,
static_cast<int64_t
>(arg1Val),
309 arg2Name, arg2Type, arg2Val);
313 begin_event_with_second_arg(category, eventName, arg1Name, sk_bit_cast<double>(arg1Val),
314 arg2Name, arg2Type, arg2Val);
318 begin_event_with_second_arg(category, eventName,
320 arg2Name, arg2Type, arg2Val);
325 begin_event_with_second_arg(category, eventName,
327 arg2Name, arg2Type, arg2Val);
337 if (perfetto::Tracing::IsInitialized()) {
338 this->closeTracingSession();
340 this->openNewTracingSession(
name);
PERFETTO_TRACK_EVENT_STATIC_STORAGE()
static DEFINE_bool(longPerfettoTrace, false, "Perfetto within Skia is optimized for tracing performance of 'smaller' traces" "(~10 seconds or less). Set this flag to true to optimize for longer tracing" "sessions.\n" "Will only have an effect if perfetto tracing is enabled. See --trace.")
static DEFINE_string(perfettoOutputDir, "./", "Output directory for perfetto trace file(s).\n" "Note: not the name of the file itself.\n" "Will only have an effect if perfetto tracing is enabled. See --trace.")
static constexpr bool SkToBool(const T &x)
#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_PHASE_END
#define TRACE_EVENT_PHASE_INSTANT
#define TRACE_EVENT_PHASE_COMPLETE
const char * getCategoryGroupName(const uint8_t *categoryEnabledFlag)
uint8_t * getCategoryGroupEnabled(const char *name)
SkEventTracer::Handle addTraceEvent(char phase, const uint8_t *categoryEnabledFlag, const char *name, uint64_t id, int numArgs, const char **argNames, const uint8_t *argTypes, const uint64_t *argValues, uint8_t flags) override
~SkPerfettoTrace() override
void updateTraceEventDuration(const uint8_t *categoryEnabledFlag, const char *name, SkEventTracer::Handle handle) override
const uint8_t * getCategoryGroupEnabled(const char *name) override
void newTracingSection(const char *name) override
const char * getCategoryGroupName(const uint8_t *categoryEnabledFlag) override
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
DEF_SWITCHES_START aot vmservice shared library name
void Initialize(zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
void Flush(SkSurface *surface)
static const void * TraceValueAsPointer(uint64_t value)
static const char * TraceValueAsString(uint64_t value)