Log all Skia trace events if the --trace-skia flag is passed (flutter/engine#27680)

This commit is contained in:
Jason Simmons
2021-07-27 14:34:02 -07:00
committed by GitHub
parent 9bfd5820b9
commit 27d018d498
7 changed files with 81 additions and 17 deletions

View File

@@ -731,6 +731,7 @@ FILE: ../../../flutter/shell/common/skp_shader_warmup_unittests.cc
FILE: ../../../flutter/shell/common/snapshot_surface_producer.h
FILE: ../../../flutter/shell/common/switches.cc
FILE: ../../../flutter/shell/common/switches.h
FILE: ../../../flutter/shell/common/switches_unittests.cc
FILE: ../../../flutter/shell/common/thread_host.cc
FILE: ../../../flutter/shell/common/thread_host.h
FILE: ../../../flutter/shell/common/vsync_waiter.cc

View File

@@ -111,7 +111,7 @@ struct Settings {
bool start_paused = false;
bool trace_skia = false;
std::vector<std::string> trace_allowlist;
std::vector<std::string> trace_skia_allowlist;
std::optional<std::vector<std::string>> trace_skia_allowlist;
bool trace_startup = false;
bool trace_systrace = false;
bool dump_skp_on_shader_compilation = false;

View File

@@ -259,6 +259,7 @@ if (enable_unittests) {
"rasterizer_unittests.cc",
"shell_unittests.cc",
"skp_shader_warmup_unittests.cc",
"switches_unittests.cc",
]
deps = [

View File

@@ -79,10 +79,14 @@ class FlutterEventTracer : public SkEventTracer {
static constexpr uint8_t kYes = 1;
static constexpr uint8_t kNo = 0;
FlutterEventTracer(bool enabled, const std::vector<std::string>& allowlist)
FlutterEventTracer(bool enabled,
const std::optional<std::vector<std::string>>& allowlist)
: enabled_(enabled ? kYes : kNo), shaders_category_flag_(nullptr) {
for (const std::string& category : allowlist) {
allowlist_.insert(std::string(kTraceCategoryPrefix) + category);
if (allowlist.has_value()) {
allowlist_.emplace();
for (const std::string& category : *allowlist) {
allowlist_->insert(std::string(kTraceCategoryPrefix) + category);
}
}
};
@@ -274,8 +278,8 @@ class FlutterEventTracer : public SkEventTracer {
if (flag_it == category_flag_map_.end()) {
bool allowed;
if (enabled_) {
allowed =
allowlist_.empty() || allowlist_.find(name) != allowlist_.end();
allowed = !allowlist_.has_value() ||
allowlist_->find(name) != allowlist_->end();
} else {
allowed = false;
}
@@ -301,15 +305,16 @@ class FlutterEventTracer : public SkEventTracer {
private:
uint8_t enabled_;
std::set<std::string> allowlist_;
std::optional<std::set<std::string>> allowlist_;
std::map<const char*, uint8_t> category_flag_map_;
std::map<const uint8_t*, const char*> reverse_flag_map_;
const uint8_t* shaders_category_flag_;
FML_DISALLOW_COPY_AND_ASSIGN(FlutterEventTracer);
};
void InitSkiaEventTracer(bool enabled,
const std::vector<std::string>& allowlist) {
void InitSkiaEventTracer(
bool enabled,
const std::optional<std::vector<std::string>>& allowlist) {
auto tracer = new FlutterEventTracer(enabled, allowlist);
// Initialize the binding to Skia's tracing events. Skia will
// take ownership of and clean up the memory allocated here.

View File

@@ -5,13 +5,15 @@
#ifndef FLUTTER_SHELL_COMMON_SKIA_EVENT_TRACER_IMPL_H_
#define FLUTTER_SHELL_COMMON_SKIA_EVENT_TRACER_IMPL_H_
#include <optional>
#include <string>
#include <vector>
namespace flutter {
void InitSkiaEventTracer(bool enabled,
const std::vector<std::string>& allowlist);
void InitSkiaEventTracer(
bool enabled,
const std::optional<std::vector<std::string>>& allowlist);
} // namespace flutter

View File

@@ -299,13 +299,18 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
#if !FLUTTER_RELEASE
settings.trace_skia = true;
std::string trace_skia_allowlist;
command_line.GetOptionValue(FlagForSwitch(Switch::TraceSkiaAllowlist),
&trace_skia_allowlist);
if (trace_skia_allowlist.size()) {
settings.trace_skia_allowlist = ParseCommaDelimited(trace_skia_allowlist);
if (command_line.HasOption(FlagForSwitch(Switch::TraceSkia))) {
// If --trace-skia is specified, then log all Skia events.
settings.trace_skia_allowlist.reset();
} else {
settings.trace_skia_allowlist = {"skia.shaders"};
std::string trace_skia_allowlist;
command_line.GetOptionValue(FlagForSwitch(Switch::TraceSkiaAllowlist),
&trace_skia_allowlist);
if (trace_skia_allowlist.size()) {
settings.trace_skia_allowlist = ParseCommaDelimited(trace_skia_allowlist);
} else {
settings.trace_skia_allowlist = {"skia.shaders"};
}
}
#endif // !FLUTTER_RELEASE

View File

@@ -0,0 +1,50 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/common/settings.h"
#include "flutter/fml/command_line.h"
#include "flutter/shell/common/switches.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
TEST(SwitchesTest, SkiaTraceAllowlistFlag) {
fml::CommandLine command_line =
fml::CommandLineFromInitializerList({"command"});
Settings settings = SettingsFromCommandLine(command_line);
#if !FLUTTER_RELEASE
EXPECT_TRUE(settings.trace_skia);
EXPECT_TRUE(settings.trace_skia_allowlist.has_value());
EXPECT_EQ(settings.trace_skia_allowlist->size(), 1ul);
#else
EXPECT_FALSE(settings.trace_skia);
#endif
command_line =
fml::CommandLineFromInitializerList({"command", "--trace-skia"});
settings = SettingsFromCommandLine(command_line);
#if !FLUTTER_RELEASE
EXPECT_TRUE(settings.trace_skia);
EXPECT_FALSE(settings.trace_skia_allowlist.has_value());
#else
EXPECT_FALSE(settings.trace_skia);
#endif
command_line = fml::CommandLineFromInitializerList(
{"command", "--trace-skia-allowlist=aaa,bbb,ccc"});
settings = SettingsFromCommandLine(command_line);
#if !FLUTTER_RELEASE
EXPECT_TRUE(settings.trace_skia);
EXPECT_TRUE(settings.trace_skia_allowlist.has_value());
EXPECT_EQ(settings.trace_skia_allowlist->size(), 3ul);
EXPECT_EQ(settings.trace_skia_allowlist->back(), "ccc");
#else
EXPECT_FALSE(settings.trace_skia);
#endif
}
} // namespace testing
} // namespace flutter