forked from firka/flutter
Avoid calling Dart_TimelineGetMicros when systrace is enabled (flutter/engine#32968)
This commit is contained in:
@@ -56,6 +56,10 @@ bool TraceHasTimelineEventHandler() {
|
||||
gTimelineEventHandler.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
int64_t TraceGetTimelineMicros() {
|
||||
return gTimelineMicrosSource.load()();
|
||||
}
|
||||
|
||||
void TraceSetTimelineMicrosSource(TimelineMicrosSource source) {
|
||||
gTimelineMicrosSource = source;
|
||||
}
|
||||
@@ -316,6 +320,10 @@ bool TraceHasTimelineEventHandler() {
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t TraceGetTimelineMicros() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TraceSetTimelineMicrosSource(TimelineMicrosSource source) {}
|
||||
|
||||
size_t TraceNonce() {
|
||||
|
||||
@@ -163,6 +163,8 @@ bool TraceHasTimelineEventHandler();
|
||||
|
||||
void TraceSetTimelineMicrosSource(TimelineMicrosSource source);
|
||||
|
||||
int64_t TraceGetTimelineMicros();
|
||||
|
||||
void TraceTimelineEvent(TraceArg category_group,
|
||||
TraceArg name,
|
||||
int64_t timestamp_micros,
|
||||
|
||||
@@ -463,7 +463,8 @@ DartVM::DartVM(std::shared_ptr<const DartVMData> vm_data,
|
||||
params.entropy_source = dart::bin::GetEntropy;
|
||||
params.get_service_assets = GetVMServiceAssetsArchiveCallback;
|
||||
DartVMInitializer::Initialize(¶ms,
|
||||
settings_.enable_timeline_event_handler);
|
||||
settings_.enable_timeline_event_handler,
|
||||
settings_.trace_systrace);
|
||||
// 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.
|
||||
|
||||
@@ -80,7 +80,8 @@ void ReportUnhandledException(Dart_Handle exception_handle,
|
||||
} // namespace
|
||||
|
||||
void DartVMInitializer::Initialize(Dart_InitializeParams* params,
|
||||
bool enable_timeline_event_handler) {
|
||||
bool enable_timeline_event_handler,
|
||||
bool trace_systrace) {
|
||||
FML_DCHECK(!gDartInitialized);
|
||||
|
||||
char* error = Dart_Initialize(params);
|
||||
@@ -92,7 +93,16 @@ void DartVMInitializer::Initialize(Dart_InitializeParams* params,
|
||||
}
|
||||
|
||||
if (enable_timeline_event_handler) {
|
||||
fml::tracing::TraceSetTimelineMicrosSource(Dart_TimelineGetMicros);
|
||||
if (!trace_systrace) {
|
||||
// Systrace on all platforms except Fuchsia ignores the timestamp provided
|
||||
// here. On Android in particular, calls to get the system clock show up
|
||||
// in profiles.
|
||||
// Fuchsia does not use the TraceSetTimelineMicrosSource.
|
||||
fml::tracing::TraceSetTimelineMicrosSource(Dart_TimelineGetMicros);
|
||||
} else {
|
||||
fml::tracing::TraceSetTimelineMicrosSource(
|
||||
[]() -> int64_t { return -1; });
|
||||
}
|
||||
fml::tracing::TraceSetTimelineEventHandler(LogDartTimelineEvent);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
class DartVMInitializer {
|
||||
public:
|
||||
static void Initialize(Dart_InitializeParams* params,
|
||||
bool enable_timeline_event_handler);
|
||||
bool enable_timeline_event_handler,
|
||||
bool trace_systrace);
|
||||
static void Cleanup();
|
||||
|
||||
private:
|
||||
|
||||
@@ -52,5 +52,13 @@ TEST_F(DartVMTest, DisableTimelineEventHandler) {
|
||||
ASSERT_FALSE(fml::tracing::TraceHasTimelineEventHandler());
|
||||
}
|
||||
|
||||
TEST_F(DartVMTest, TraceGetTimelineMicrosDoesNotGetClockWhenSystraceIsEnabled) {
|
||||
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
|
||||
auto settings = CreateSettingsForFixture();
|
||||
settings.trace_systrace = true;
|
||||
auto vm = DartVMRef::Create(settings);
|
||||
ASSERT_EQ(-1, fml::tracing::TraceGetTimelineMicros());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
Reference in New Issue
Block a user