Disable the timeline in release mode on Android unless systrace is enabled (flutter/engine#32909)
This commit is contained in:
@@ -136,6 +136,7 @@ struct Settings {
|
||||
std::optional<std::vector<std::string>> trace_skia_allowlist;
|
||||
bool trace_startup = false;
|
||||
bool trace_systrace = false;
|
||||
bool enable_timeline_event_handler = true;
|
||||
bool dump_skp_on_shader_compilation = false;
|
||||
bool cache_sksl = false;
|
||||
bool purge_persistent_cache = false;
|
||||
|
||||
@@ -51,6 +51,11 @@ void TraceSetTimelineEventHandler(TimelineEventHandler handler) {
|
||||
gTimelineEventHandler = handler;
|
||||
}
|
||||
|
||||
bool TraceHasTimelineEventHandler() {
|
||||
return static_cast<bool>(
|
||||
gTimelineEventHandler.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
void TraceSetTimelineMicrosSource(TimelineMicrosSource source) {
|
||||
gTimelineMicrosSource = source;
|
||||
}
|
||||
@@ -307,6 +312,10 @@ void TraceSetAllowlist(const std::vector<std::string>& allowlist) {}
|
||||
|
||||
void TraceSetTimelineEventHandler(TimelineEventHandler handler) {}
|
||||
|
||||
bool TraceHasTimelineEventHandler() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void TraceSetTimelineMicrosSource(TimelineMicrosSource source) {}
|
||||
|
||||
size_t TraceNonce() {
|
||||
|
||||
@@ -159,6 +159,8 @@ using TimelineMicrosSource = int64_t (*)();
|
||||
|
||||
void TraceSetTimelineEventHandler(TimelineEventHandler handler);
|
||||
|
||||
bool TraceHasTimelineEventHandler();
|
||||
|
||||
void TraceSetTimelineMicrosSource(TimelineMicrosSource source);
|
||||
|
||||
void TraceTimelineEvent(TraceArg category_group,
|
||||
|
||||
@@ -458,7 +458,8 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
|
||||
params.thread_exit = ThreadExitCallback;
|
||||
params.get_service_assets = GetVMServiceAssetsArchiveCallback;
|
||||
params.entropy_source = dart::bin::GetEntropy;
|
||||
DartVMInitializer::Initialize(¶ms);
|
||||
DartVMInitializer::Initialize(¶ms,
|
||||
settings_.enable_timeline_event_handler);
|
||||
// Send the earliest available timestamp in the application lifecycle to
|
||||
// timeline. The difference between this timestamp and the time we render
|
||||
// the very first frame gives us a good idea about Flutter's startup time.
|
||||
|
||||
@@ -79,7 +79,8 @@ void ReportUnhandledException(Dart_Handle exception_handle,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void DartVMInitializer::Initialize(Dart_InitializeParams* params) {
|
||||
void DartVMInitializer::Initialize(Dart_InitializeParams* params,
|
||||
bool enable_timeline_event_handler) {
|
||||
FML_DCHECK(!gDartInitialized);
|
||||
|
||||
char* error = Dart_Initialize(params);
|
||||
@@ -90,9 +91,12 @@ void DartVMInitializer::Initialize(Dart_InitializeParams* params) {
|
||||
gDartInitialized = true;
|
||||
}
|
||||
|
||||
if (enable_timeline_event_handler) {
|
||||
fml::tracing::TraceSetTimelineMicrosSource(Dart_TimelineGetMicros);
|
||||
fml::tracing::TraceSetTimelineEventHandler(LogDartTimelineEvent);
|
||||
}
|
||||
|
||||
fml::TimePoint::SetClockSource(flutter::DartTimelineTicksSinceEpoch);
|
||||
fml::tracing::TraceSetTimelineEventHandler(LogDartTimelineEvent);
|
||||
fml::tracing::TraceSetTimelineMicrosSource(Dart_TimelineGetMicros);
|
||||
tonic::SetUnhandledExceptionReporter(&ReportUnhandledException);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
class DartVMInitializer {
|
||||
public:
|
||||
static void Initialize(Dart_InitializeParams* params);
|
||||
static void Initialize(Dart_InitializeParams* params,
|
||||
bool enable_timeline_event_handler);
|
||||
static void Cleanup();
|
||||
|
||||
private:
|
||||
|
||||
@@ -43,5 +43,14 @@ TEST_F(DartVMTest, OldGenHeapSize) {
|
||||
ASSERT_TRUE(vm);
|
||||
}
|
||||
|
||||
TEST_F(DartVMTest, DisableTimelineEventHandler) {
|
||||
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
|
||||
fml::tracing::TraceSetTimelineEventHandler(nullptr);
|
||||
auto settings = CreateSettingsForFixture();
|
||||
settings.enable_timeline_event_handler = false;
|
||||
auto vm = DartVMRef::Create(settings);
|
||||
ASSERT_FALSE(fml::tracing::TraceHasTimelineEventHandler());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@@ -105,6 +105,12 @@ void FlutterMain::Init(JNIEnv* env,
|
||||
}
|
||||
}
|
||||
|
||||
#if FLUTTER_RELEASE
|
||||
// On most platforms the timeline is always disabled in release mode.
|
||||
// On Android, enable it in release mode only when using systrace.
|
||||
settings.enable_timeline_event_handler = settings.trace_systrace;
|
||||
#endif // FLUTTER_RELEASE
|
||||
|
||||
int64_t init_time_micros = initTimeMillis * 1000;
|
||||
settings.engine_start_timestamp =
|
||||
std::chrono::microseconds(Dart_TimelineGetMicros() - init_time_micros);
|
||||
|
||||
Reference in New Issue
Block a user