diff --git a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc index 2939e896cd..ca129cb4d9 100644 --- a/engine/src/flutter/lib/ui/dart_runtime_hooks.cc +++ b/engine/src/flutter/lib/ui/dart_runtime_hooks.cc @@ -47,6 +47,7 @@ namespace blink { #define BUILTIN_NATIVE_LIST(V) \ V(Logger_PrintString, 1) \ + V(SaveCompilationTrace, 0) \ V(ScheduleMicrotask, 1) BUILTIN_NATIVE_LIST(DECLARE_FUNCTION); @@ -199,6 +200,24 @@ void Logger_PrintString(Dart_NativeArguments args) { } } +void SaveCompilationTrace(Dart_NativeArguments args) { + uint8_t* buffer = nullptr; + intptr_t length = 0; + Dart_Handle result = Dart_SaveCompilationTrace(&buffer, &length); + if (Dart_IsError(result)) { + Dart_SetReturnValue(args, result); + return; + } + + result = Dart_NewExternalTypedData(Dart_TypedData_kUint8, buffer, length); + if (Dart_IsError(result)) { + Dart_SetReturnValue(args, result); + return; + } + + Dart_SetReturnValue(args, result); +} + void ScheduleMicrotask(Dart_NativeArguments args) { Dart_Handle closure = Dart_GetNativeArgument(args, 0); UIDartState::Current()->ScheduleMicrotask(closure); diff --git a/engine/src/flutter/lib/ui/natives.dart b/engine/src/flutter/lib/ui/natives.dart index b5123099ae..0a38460734 100644 --- a/engine/src/flutter/lib/ui/natives.dart +++ b/engine/src/flutter/lib/ui/natives.dart @@ -35,6 +35,17 @@ void _setupHooks() { }()); } +void saveCompilationTrace(String filePath) { + final result = _saveCompilationTrace(); + if (result is Error) + throw result; + + final file = new File(filePath); + file.writeAsBytesSync(result); +} + +dynamic _saveCompilationTrace() native 'SaveCompilationTrace'; + void _scheduleMicrotask(void callback()) native 'ScheduleMicrotask'; // Required for gen_snapshot to work correctly. diff --git a/engine/src/flutter/lib/ui/ui.dart b/engine/src/flutter/lib/ui/ui.dart index 149cbde210..b6d22ca293 100644 --- a/engine/src/flutter/lib/ui/ui.dart +++ b/engine/src/flutter/lib/ui/ui.dart @@ -16,6 +16,7 @@ import 'dart:async'; import 'dart:collection' as collection; import 'dart:convert'; import 'dart:developer' as developer; +import 'dart:io'; import 'dart:math' as math; import 'dart:nativewrappers'; import 'dart:typed_data';