From e0ef51ea00e9b9eb2fe93d94dfeed56195c27323 Mon Sep 17 00:00:00 2001 From: Carlo Bernaschina Date: Wed, 13 Sep 2017 10:18:45 -0700 Subject: [PATCH] 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. --- engine/src/flutter/shell/common/shell.cc | 3 +- .../shell/common/skia_event_tracer_impl.cc | 31 ++++++++++++++++--- .../shell/common/skia_event_tracer_impl.h | 2 +- engine/src/flutter/shell/common/switches.h | 5 +++ .../flutter/app/FlutterActivityDelegate.java | 3 ++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index f4a256c182..1ced6c92c5 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -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); diff --git a/engine/src/flutter/shell/common/skia_event_tracer_impl.cc b/engine/src/flutter/shell/common/skia_event_tracer_impl.cc index 4bb577c7fb..79f468e6d8 100644 --- a/engine/src/flutter/shell/common/skia_event_tracer_impl.cc +++ b/engine/src/flutter/shell/common/skia_event_tracer_impl.cc @@ -9,6 +9,7 @@ #include +#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(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(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); } diff --git a/engine/src/flutter/shell/common/skia_event_tracer_impl.h b/engine/src/flutter/shell/common/skia_event_tracer_impl.h index f6a61214ff..55305b9cbd 100644 --- a/engine/src/flutter/shell/common/skia_event_tracer_impl.h +++ b/engine/src/flutter/shell/common/skia_event_tracer_impl.h @@ -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_ diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index 16a4632baa..856dd9bde7 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.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 " diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 6f674ffe35..ba91f9eb99 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -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);