[dart2js] Updating runtime allocations to store a JSON-decoded map instead of a JSON string

This was requested by internal teams for easier querying/processing.

Change-Id: I59fea565f79bf92d4cf808cc0466b4e9cfa37fe8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253707
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
This commit is contained in:
Mark Zhou 2022-08-06 00:02:37 +00:00 committed by Commit Bot
parent a34e93f9d3
commit ad8d2ccb06
3 changed files with 15 additions and 11 deletions

View file

@ -8,9 +8,7 @@ import 'package:dart2js_runtime_metrics/runtime_metrics.dart';
import 'package:expect/expect.dart';
void main() {
Map<String, Object> metrics = runtimeMetrics;
print('metrics: $metrics');
Map metrics = runtimeMetrics;
String expectedRuntime;
if (1.0 is! int) {
@ -34,6 +32,9 @@ void main() {
if (expectedRuntime == 'dart2js') {
Expect.isTrue(metrics.containsKey('allocations'));
dynamic allocations = metrics['allocations'];
// We assume dart:_rti:Rti is always instantiated in the dart2js runtime.
Expect.isTrue(allocations.containsKey('dart:_rti:Rti'));
return;
}

View file

@ -6,7 +6,7 @@ library dart2js_runtime_metrics;
import 'dart:_js_helper'
show
copyAndStringifyProperties,
copyAndJsonifyProperties,
fillLiteralMap,
rawRuntimeMetrics,
rawStartupMetrics;
@ -51,12 +51,12 @@ Map<String, Object> get startupMetrics {
///
/// - `runtime`: `'dart2js'`
///
/// - `allocations`: A string representation of a Json Map<String, Object>,
/// which holds every class or closure created at runtime. The key contains
/// a resolved path of the class or closure. The value is currently unused.
/// - `allocations`: A JSON Map<String, Object> that holds every
/// runtime-allocated class or closure. The key contains a resolved path of
/// the class or closure. The value is currently unused.
Map<String, Object> get runtimeMetrics {
final Map<String, Object> result = {'runtime': 'dart2js'};
final raw = rawRuntimeMetrics();
copyAndStringifyProperties(raw, result);
copyAndJsonifyProperties(raw, result);
return result;
}

View file

@ -26,6 +26,8 @@ import 'dart:_js_shared_embedded_names' show JsBuiltin, JsGetName;
import 'dart:collection';
import 'dart:convert' show jsonDecode;
import 'dart:async' show Completer, DeferredLoadException, Future, Zone;
import 'dart:_foreign_helper'
@ -1799,9 +1801,9 @@ fillLiteralSet(values, Set result) {
return result;
}
/// Called by generated code to move and stringify properties from an object
/// Called by generated code to move and JSON-ify properties from an object
/// to a map literal.
copyAndStringifyProperties(from, Map to) {
copyAndJsonifyProperties(from, Map to) {
if (JS('bool', '!#', from)) return to;
List keys = JS('JSArray', r'Object.keys(#)', from);
int index = 0;
@ -1809,7 +1811,8 @@ copyAndStringifyProperties(from, Map to) {
while (index < length) {
var key = getIndex(keys, index++);
var value = JS('String', r'JSON.stringify(#[#])', from, key);
to[key] = value;
Map jsonValue = jsonDecode(value);
to[key] = jsonValue;
}
return to;
}