Skip to content

Commit

Permalink
Support for saving Dart compilation trace on device. (flutter#5443)
Browse files Browse the repository at this point in the history
Support for saving Dart compilation trace on device.
  • Loading branch information
sbaranov authored Jun 8, 2018
1 parent d328f4e commit d4f5ef6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/ui/dart_runtime_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions lib/ui/natives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/ui/ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d4f5ef6

Please sign in to comment.