Add --trace-skia parameter to flutter run (flutter/engine#4100)
Skia tracing is extremely useful for internal debug, but reduces the amount of space available in the Dart Timeline buffers. Disable skia tracing by default and expose them via the --trace-skia flag.
This commit is contained in:
committed by
GitHub
parent
11a9ee14fe
commit
e0ef51ea00
@@ -196,7 +196,8 @@ void Shell::InitStandalone(fxl::CommandLine command_line,
|
||||
|
||||
void Shell::Init(fxl::CommandLine command_line) {
|
||||
#if FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_RELEASE
|
||||
InitSkiaEventTracer();
|
||||
bool trace_skia = command_line.HasOption(FlagForSwitch(Switch::TraceSkia));
|
||||
InitSkiaEventTracer(trace_skia);
|
||||
#endif
|
||||
|
||||
FXL_DCHECK(!g_shell);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "dart/runtime/include/dart_tools_api.h"
|
||||
#include "lib/fxl/logging.h"
|
||||
#include "third_party/skia/include/utils/SkEventTracer.h"
|
||||
#include "third_party/skia/src/core/SkTraceEventCommon.h"
|
||||
@@ -18,8 +19,10 @@ namespace skia {
|
||||
class FlutterEventTracer : public SkEventTracer {
|
||||
public:
|
||||
static constexpr const char* kSkiaTag = "skia";
|
||||
static constexpr uint8_t kYes = 1;
|
||||
static constexpr uint8_t kNo = 0;
|
||||
|
||||
FlutterEventTracer() = default;
|
||||
FlutterEventTracer(bool enabled) : enabled_(enabled ? kYes : kNo){};
|
||||
|
||||
SkEventTracer::Handle addTraceEvent(char phase,
|
||||
const uint8_t* category_enabled_flag,
|
||||
@@ -62,8 +65,7 @@ class FlutterEventTracer : public SkEventTracer {
|
||||
}
|
||||
|
||||
const uint8_t* getCategoryGroupEnabled(const char* name) override {
|
||||
static const uint8_t kYes = 1;
|
||||
return &kYes;
|
||||
return &enabled_;
|
||||
}
|
||||
|
||||
const char* getCategoryGroupName(
|
||||
@@ -71,14 +73,33 @@ class FlutterEventTracer : public SkEventTracer {
|
||||
return kSkiaTag;
|
||||
}
|
||||
|
||||
void enable() { enabled_ = kYes; }
|
||||
|
||||
private:
|
||||
uint8_t enabled_;
|
||||
FXL_DISALLOW_COPY_AND_ASSIGN(FlutterEventTracer);
|
||||
};
|
||||
|
||||
bool enableSkiaTracingCallback(const char* method,
|
||||
const char** param_keys,
|
||||
const char** param_values,
|
||||
intptr_t num_params,
|
||||
void* user_data,
|
||||
const char** json_object) {
|
||||
FlutterEventTracer* tracer = static_cast<FlutterEventTracer*>(user_data);
|
||||
tracer->enable();
|
||||
*json_object = strdup("{\"type\":\"Success\"}");
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace skia
|
||||
|
||||
void InitSkiaEventTracer() {
|
||||
void InitSkiaEventTracer(bool enabled) {
|
||||
skia::FlutterEventTracer* tracer = new skia::FlutterEventTracer(enabled);
|
||||
Dart_RegisterRootServiceRequestCallback("_flutter.enableSkiaTracing",
|
||||
skia::enableSkiaTracingCallback,
|
||||
static_cast<void*>(tracer));
|
||||
// Initialize the binding to Skia's tracing events. Skia will
|
||||
// take ownership of and clean up the memory allocated here.
|
||||
SkEventTracer::SetInstance(new skia::FlutterEventTracer());
|
||||
SkEventTracer::SetInstance(tracer);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#ifndef FLUTTER_SHELL_COMMON_SKIA_EVENT_TRACER_IMPL_H_
|
||||
#define FLUTTER_SHELL_COMMON_SKIA_EVENT_TRACER_IMPL_H_
|
||||
|
||||
void InitSkiaEventTracer();
|
||||
void InitSkiaEventTracer(bool enabled);
|
||||
|
||||
#endif // FLUTTER_SHELL_COMMON_SKIA_EVENT_TRACER_IMPL_H_
|
||||
|
||||
@@ -84,6 +84,11 @@ DEF_SWITCH(TraceStartup,
|
||||
"trace-startup",
|
||||
"Trace early application lifecycle. Automatically switches to an "
|
||||
"endless trace buffer.")
|
||||
DEF_SWITCH(TraceSkia,
|
||||
"trace-skia",
|
||||
"Trace Skia calls. This is useful when debugging the GPU threed."
|
||||
"By default, Skia tracing is not enable to reduce the number of "
|
||||
"traced events")
|
||||
DEF_SWITCH(UseTestFonts,
|
||||
"use-test-fonts",
|
||||
"Running tests that layout and measure text will not yield "
|
||||
|
||||
@@ -266,6 +266,9 @@ public final class FlutterActivityDelegate
|
||||
if (intent.getBooleanExtra("enable-software-rendering", false)) {
|
||||
args.add("--enable-software-rendering");
|
||||
}
|
||||
if (intent.getBooleanExtra("trace-skia", false)) {
|
||||
args.add("--trace-skia");
|
||||
}
|
||||
if (!args.isEmpty()) {
|
||||
String[] argsArray = new String[args.size()];
|
||||
return args.toArray(argsArray);
|
||||
|
||||
Reference in New Issue
Block a user