Add trace-to-file switch (flutter/engine#45553)
This commit is contained in:
@@ -146,6 +146,7 @@ struct Settings {
|
||||
std::optional<std::vector<std::string>> trace_skia_allowlist;
|
||||
bool trace_startup = false;
|
||||
bool trace_systrace = false;
|
||||
std::string trace_to_file;
|
||||
bool enable_timeline_event_handler = true;
|
||||
bool dump_skp_on_shader_compilation = false;
|
||||
bool cache_sksl = false;
|
||||
|
||||
@@ -99,6 +99,12 @@ static const char* kDartSystraceTraceBufferArgs[] = {
|
||||
"--systrace_timeline",
|
||||
};
|
||||
|
||||
static std::string DartFileRecorderArgs(const std::string& path) {
|
||||
std::ostringstream oss;
|
||||
oss << "--timeline_recorder=perfettofile:" << path;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
FML_ALLOW_UNUSED_TYPE
|
||||
static const char* kDartDefaultTraceStreamsArgs[]{
|
||||
"--timeline_streams=Dart,Embedder,GC",
|
||||
@@ -390,6 +396,14 @@ DartVM::DartVM(const std::shared_ptr<const DartVMData>& vm_data,
|
||||
fml::size(kDartSystraceTraceStreamsArgs));
|
||||
}
|
||||
|
||||
std::string file_recorder_args;
|
||||
if (!settings_.trace_to_file.empty()) {
|
||||
file_recorder_args = DartFileRecorderArgs(settings_.trace_to_file);
|
||||
args.push_back(file_recorder_args.c_str());
|
||||
PushBackAll(&args, kDartSystraceTraceStreamsArgs,
|
||||
fml::size(kDartSystraceTraceStreamsArgs));
|
||||
}
|
||||
|
||||
if (settings_.trace_startup) {
|
||||
PushBackAll(&args, kDartStartupTraceStreamsArgs,
|
||||
fml::size(kDartStartupTraceStreamsArgs));
|
||||
|
||||
@@ -354,6 +354,9 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
|
||||
settings.trace_systrace =
|
||||
command_line.HasOption(FlagForSwitch(Switch::TraceSystrace));
|
||||
|
||||
command_line.GetOptionValue(FlagForSwitch(Switch::TraceToFile),
|
||||
&settings.trace_to_file);
|
||||
|
||||
settings.skia_deterministic_rendering_on_cpu =
|
||||
command_line.HasOption(FlagForSwitch(Switch::SkiaDeterministicRendering));
|
||||
|
||||
|
||||
@@ -197,6 +197,11 @@ DEF_SWITCH(
|
||||
"Trace to the system tracer (instead of the timeline) on platforms where "
|
||||
"such a tracer is available. Currently only supported on Android and "
|
||||
"Fuchsia.")
|
||||
DEF_SWITCH(TraceToFile,
|
||||
"trace-to-file",
|
||||
"Write the timeline trace to a file at the specified path. The file "
|
||||
"will be in Perfetto's proto format; it will be possible to load "
|
||||
"the file into Perfetto's trace viewer.")
|
||||
DEF_SWITCH(UseTestFonts,
|
||||
"use-test-fonts",
|
||||
"Running tests that layout and measure text will not yield "
|
||||
|
||||
@@ -51,6 +51,14 @@ TEST(SwitchesTest, SkiaTraceAllowlistFlag) {
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(SwitchesTest, TraceToFile) {
|
||||
fml::CommandLine command_line = fml::CommandLineFromInitializerList(
|
||||
{"command", "--trace-to-file=trace.binpb"});
|
||||
EXPECT_TRUE(command_line.HasOption("trace-to-file"));
|
||||
Settings settings = SettingsFromCommandLine(command_line);
|
||||
EXPECT_EQ(settings.trace_to_file, "trace.binpb");
|
||||
}
|
||||
|
||||
TEST(SwitchesTest, RouteParsedFlag) {
|
||||
fml::CommandLine command_line =
|
||||
fml::CommandLineFromInitializerList({"command", "--route=/animation"});
|
||||
|
||||
@@ -314,6 +314,9 @@ public final class FlutterActivityDelegate
|
||||
if (intent.getBooleanExtra("trace-systrace", false)) {
|
||||
args.add("--trace-systrace");
|
||||
}
|
||||
if (intent.hasExtra("trace-to-file")) {
|
||||
args.add("--trace-to-file=" + intent.getStringExtra("trace-to-file"));
|
||||
}
|
||||
if (intent.getBooleanExtra("dump-skp-on-shader-compilation", false)) {
|
||||
args.add("--dump-skp-on-shader-compilation");
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ public class FlutterShellArgs {
|
||||
public static final String ARG_TRACE_SKIA_ALLOWLIST = "--trace-skia-allowlist=";
|
||||
public static final String ARG_KEY_TRACE_SYSTRACE = "trace-systrace";
|
||||
public static final String ARG_TRACE_SYSTRACE = "--trace-systrace";
|
||||
public static final String ARG_KEY_TRACE_TO_FILE = "trace-to-file";
|
||||
public static final String ARG_TRACE_TO_FILE = "--trace-to-file";
|
||||
public static final String ARG_KEY_ENABLE_IMPELLER = "enable-impeller";
|
||||
public static final String ARG_ENABLE_IMPELLER = "--enable-impeller";
|
||||
public static final String ARG_KEY_ENABLE_VULKAN_VALIDATION = "enable-vulkan-validation";
|
||||
@@ -120,6 +122,9 @@ public class FlutterShellArgs {
|
||||
if (intent.getBooleanExtra(ARG_KEY_TRACE_SYSTRACE, false)) {
|
||||
args.add(ARG_TRACE_SYSTRACE);
|
||||
}
|
||||
if (intent.hasExtra(ARG_KEY_TRACE_TO_FILE)) {
|
||||
args.add(ARG_TRACE_TO_FILE + "=" + intent.getStringExtra(ARG_KEY_TRACE_TO_FILE));
|
||||
}
|
||||
if (intent.getBooleanExtra(ARG_KEY_ENABLE_IMPELLER, false)) {
|
||||
args.add(ARG_ENABLE_IMPELLER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user