1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-05 09:20:04 +00:00

Migrate Isolate benchmarks to null safety

Change-Id: I420a60c58d9f727cf8d9cca99c211331ce8e3b57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151844
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
William Hesse 2020-06-22 23:45:55 +00:00
parent 9030ade7e2
commit 78617979b2
8 changed files with 161 additions and 168 deletions

View File

@ -8,11 +8,10 @@ import 'dart:typed_data';
import 'package:benchmark_harness/benchmark_harness.dart'
show PrintEmitter, ScoreEmitter;
import 'package:meta/meta.dart';
class SendReceiveBytes extends AsyncBenchmarkBase {
SendReceiveBytes(String name,
{@required int this.size, @required bool this.useTransferable})
{required this.size, required this.useTransferable})
: super(name);
@override
@ -33,7 +32,7 @@ class SendReceiveBytes extends AsyncBenchmarkBase {
final bool useTransferable;
final int size;
SendReceiveHelper helper;
late SendReceiveHelper helper;
}
// Identical to BenchmarkBase from package:benchmark_harness but async.
@ -86,10 +85,10 @@ class StartMessage {
// Measures how long sending and receiving of [size]-length Uint8List takes.
class SendReceiveHelper {
SendReceiveHelper(this.size, {@required bool this.useTransferable});
SendReceiveHelper(this.size, {required this.useTransferable});
Future<void> setup() async {
data = new Uint8List(size);
data = Uint8List(size);
port = ReceivePort();
inbox = StreamIterator<dynamic>(port);
@ -121,24 +120,24 @@ class SendReceiveHelper {
}
}
Uint8List data;
ReceivePort port;
StreamIterator<dynamic> inbox;
SendPort outbox;
Isolate worker;
Completer<bool> workerCompleted;
ReceivePort workerExitedPort;
late Uint8List data;
late ReceivePort port;
late StreamIterator<dynamic> inbox;
late SendPort outbox;
late Isolate worker;
late Completer<bool> workerCompleted;
late ReceivePort workerExitedPort;
final int size;
final bool useTransferable;
}
packageList(Uint8List data, bool useTransferable) =>
Object packageList(Uint8List data, bool useTransferable) =>
useTransferable ? TransferableTypedData.fromList(<Uint8List>[data]) : data;
Future<void> isolate(StartMessage startMessage) async {
final port = ReceivePort();
final inbox = StreamIterator<dynamic>(port);
final data = Uint8List.view(new Uint8List(startMessage.size).buffer);
final data = Uint8List.view(Uint8List(startMessage.size).buffer);
startMessage.sendPort.send(port.sendPort);
while (true) {
@ -163,22 +162,22 @@ class SizeName {
final String name;
}
final List<SizeName> sizes = <SizeName>[
SizeName(1 * 1024, "1KB"),
SizeName(10 * 1024, "10KB"),
SizeName(100 * 1024, "100KB"),
SizeName(1 * 1024 * 1024, "1MB"),
SizeName(10 * 1024 * 1024, "10MB"),
SizeName(100 * 1024 * 1024, "100MB")
const List<SizeName> sizes = <SizeName>[
SizeName(1 * 1024, '1KB'),
SizeName(10 * 1024, '10KB'),
SizeName(100 * 1024, '100KB'),
SizeName(1 * 1024 * 1024, '1MB'),
SizeName(10 * 1024 * 1024, '10MB'),
SizeName(100 * 1024 * 1024, '100MB')
];
Future<void> main() async {
for (SizeName sizeName in sizes) {
await SendReceiveBytes("Isolate.SendReceiveBytes${sizeName.name}",
for (final sizeName in sizes) {
await SendReceiveBytes('Isolate.SendReceiveBytes${sizeName.name}',
size: sizeName.size, useTransferable: false)
.report();
await SendReceiveBytes(
"Isolate.SendReceiveBytesTransferable${sizeName.name}",
'Isolate.SendReceiveBytesTransferable${sizeName.name}',
size: sizeName.size,
useTransferable: true)
.report();

View File

@ -12,7 +12,7 @@ import 'package:meta/meta.dart';
class SendReceiveBytes extends AsyncBenchmarkBase {
SendReceiveBytes(String name,
{@required int this.size, @required bool this.useTransferable})
{@required this.size, @required this.useTransferable})
: super(name);
@override
@ -86,10 +86,10 @@ class StartMessage {
// Measures how long sending and receiving of [size]-length Uint8List takes.
class SendReceiveHelper {
SendReceiveHelper(this.size, {@required bool this.useTransferable});
SendReceiveHelper(this.size, {@required this.useTransferable});
Future<void> setup() async {
data = new Uint8List(size);
data = Uint8List(size);
port = ReceivePort();
inbox = StreamIterator<dynamic>(port);
@ -132,13 +132,13 @@ class SendReceiveHelper {
final bool useTransferable;
}
packageList(Uint8List data, bool useTransferable) =>
Object packageList(Uint8List data, bool useTransferable) =>
useTransferable ? TransferableTypedData.fromList(<Uint8List>[data]) : data;
Future<void> isolate(StartMessage startMessage) async {
final port = ReceivePort();
final inbox = StreamIterator<dynamic>(port);
final data = Uint8List.view(new Uint8List(startMessage.size).buffer);
final data = Uint8List.view(Uint8List(startMessage.size).buffer);
startMessage.sendPort.send(port.sendPort);
while (true) {
@ -163,22 +163,22 @@ class SizeName {
final String name;
}
final List<SizeName> sizes = <SizeName>[
SizeName(1 * 1024, "1KB"),
SizeName(10 * 1024, "10KB"),
SizeName(100 * 1024, "100KB"),
SizeName(1 * 1024 * 1024, "1MB"),
SizeName(10 * 1024 * 1024, "10MB"),
SizeName(100 * 1024 * 1024, "100MB")
const List<SizeName> sizes = <SizeName>[
SizeName(1 * 1024, '1KB'),
SizeName(10 * 1024, '10KB'),
SizeName(100 * 1024, '100KB'),
SizeName(1 * 1024 * 1024, '1MB'),
SizeName(10 * 1024 * 1024, '10MB'),
SizeName(100 * 1024 * 1024, '100MB')
];
Future<void> main() async {
for (SizeName sizeName in sizes) {
await SendReceiveBytes("Isolate.SendReceiveBytes${sizeName.name}",
for (final sizeName in sizes) {
await SendReceiveBytes('Isolate.SendReceiveBytes${sizeName.name}',
size: sizeName.size, useTransferable: false)
.report();
await SendReceiveBytes(
"Isolate.SendReceiveBytesTransferable${sizeName.name}",
'Isolate.SendReceiveBytesTransferable${sizeName.name}',
size: sizeName.size,
useTransferable: true)
.report();

View File

@ -9,15 +9,14 @@ import 'dart:isolate';
import 'dart:typed_data';
import 'package:benchmark_harness/benchmark_harness.dart' show BenchmarkBase;
import 'package:meta/meta.dart';
import 'runtime/tests/vm/dart/export_sendAndExit_helper.dart' show sendAndExit;
class JsonDecodingBenchmark {
JsonDecodingBenchmark(this.name,
{@required this.sample,
@required this.numTasks,
@required this.useSendAndExit});
{required this.sample,
required this.numTasks,
required this.useSendAndExit});
Future<void> report() async {
final stopwatch = Stopwatch()..start();
@ -30,7 +29,7 @@ class JsonDecodingBenchmark {
await Future.wait(decodedFutures);
}
print("$name(RunTime): ${stopwatch.elapsedMicroseconds} us.");
print('$name(RunTime): ${stopwatch.elapsedMicroseconds} us.');
}
final String name;
@ -45,7 +44,7 @@ Uint8List createSampleJson(final size) {
for (int i = 0; i < size; i++) {
map['$i'] = list;
}
return utf8.encode(json.encode(map));
return utf8.encode(json.encode(map)) as Uint8List;
}
class JsonDecodeRequest {
@ -73,7 +72,7 @@ Future<Map> decodeJson(bool useSendAndExit, Uint8List encodedJson) async {
workerExitedPort.close();
workerErroredPort.close();
await inbox.moveNext();
final decodedJson = inbox.current;
final decodedJson = inbox.current as Map;
port.close();
return decodedJson;
}
@ -89,7 +88,7 @@ Future<void> jsonDecodingIsolate(JsonDecodeRequest request) async {
class SyncJsonDecodingBenchmark extends BenchmarkBase {
SyncJsonDecodingBenchmark(String name,
{@required this.sample, @required this.iterations})
{required this.sample, required this.iterations})
: super(name);
@override
@ -116,43 +115,46 @@ class BenchmarkConfig {
Future<void> main() async {
final jsonString =
File('benchmarks/IsolateJson/dart/sample.json').readAsStringSync();
final json250KB = utf8.encode(jsonString); // 294356 bytes
final json250KB = utf8.encode(jsonString) as Uint8List; // 294356 bytes
final decoded = json.decode(utf8.decode(json250KB));
final decoded1MB = <dynamic, dynamic>{
"1": decoded["1"],
"2": decoded["1"],
"3": decoded["1"],
"4": decoded["1"],
'1': decoded['1'],
'2': decoded['1'],
'3': decoded['1'],
'4': decoded['1'],
};
final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes
decoded["1"] = (decoded["1"] as List).sublist(0, 200);
final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes
decoded["1"] = (decoded["1"] as List).sublist(0, 100);
final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes
final json1MB =
utf8.encode(json.encode(decoded1MB)) as Uint8List; // 1177397 bytes
decoded['1'] = (decoded['1'] as List).sublist(0, 200);
final json100KB =
utf8.encode(json.encode(decoded)) as Uint8List; // 104685 bytes
decoded['1'] = (decoded['1'] as List).sublist(0, 100);
final json50KB =
utf8.encode(json.encode(decoded)) as Uint8List; // 51760 bytes
final configs = <BenchmarkConfig>[
BenchmarkConfig("50KB", json50KB),
BenchmarkConfig("100KB", json100KB),
BenchmarkConfig("250KB", json250KB),
BenchmarkConfig("1MB", json1MB),
BenchmarkConfig('50KB', json50KB),
BenchmarkConfig('100KB', json100KB),
BenchmarkConfig('250KB', json250KB),
BenchmarkConfig('1MB', json1MB),
];
for (BenchmarkConfig config in configs) {
for (final config in configs) {
for (final iterations in <int>[1, 4]) {
await JsonDecodingBenchmark(
"IsolateJson.Decode${config.suffix}x$iterations",
'IsolateJson.Decode${config.suffix}x$iterations',
useSendAndExit: false,
sample: config.sample,
numTasks: iterations)
.report();
await JsonDecodingBenchmark(
"IsolateJson.SendAndExit_Decode${config.suffix}x$iterations",
'IsolateJson.SendAndExit_Decode${config.suffix}x$iterations',
useSendAndExit: true,
sample: config.sample,
numTasks: iterations)
.report();
SyncJsonDecodingBenchmark(
"IsolateJson.SyncDecode${config.suffix}x$iterations",
'IsolateJson.SyncDecode${config.suffix}x$iterations',
sample: config.sample,
iterations: iterations)
.report();

View File

@ -30,7 +30,7 @@ class JsonDecodingBenchmark {
await Future.wait(decodedFutures);
}
print("$name(RunTime): ${stopwatch.elapsedMicroseconds} us.");
print('$name(RunTime): ${stopwatch.elapsedMicroseconds} us.');
}
final String name;
@ -119,40 +119,40 @@ Future<void> main() async {
final json250KB = utf8.encode(jsonString); // 294356 bytes
final decoded = json.decode(utf8.decode(json250KB));
final decoded1MB = <dynamic, dynamic>{
"1": decoded["1"],
"2": decoded["1"],
"3": decoded["1"],
"4": decoded["1"],
'1': decoded['1'],
'2': decoded['1'],
'3': decoded['1'],
'4': decoded['1'],
};
final json1MB = utf8.encode(json.encode(decoded1MB)); // 1177397 bytes
decoded["1"] = (decoded["1"] as List).sublist(0, 200);
decoded['1'] = (decoded['1'] as List).sublist(0, 200);
final json100KB = utf8.encode(json.encode(decoded)); // 104685 bytes
decoded["1"] = (decoded["1"] as List).sublist(0, 100);
decoded['1'] = (decoded['1'] as List).sublist(0, 100);
final json50KB = utf8.encode(json.encode(decoded)); // 51760 bytes
final configs = <BenchmarkConfig>[
BenchmarkConfig("50KB", json50KB),
BenchmarkConfig("100KB", json100KB),
BenchmarkConfig("250KB", json250KB),
BenchmarkConfig("1MB", json1MB),
BenchmarkConfig('50KB', json50KB),
BenchmarkConfig('100KB', json100KB),
BenchmarkConfig('250KB', json250KB),
BenchmarkConfig('1MB', json1MB),
];
for (BenchmarkConfig config in configs) {
for (final config in configs) {
for (final iterations in <int>[1, 4]) {
await JsonDecodingBenchmark(
"IsolateJson.Decode${config.suffix}x$iterations",
'IsolateJson.Decode${config.suffix}x$iterations',
useSendAndExit: false,
sample: config.sample,
numTasks: iterations)
.report();
await JsonDecodingBenchmark(
"IsolateJson.SendAndExit_Decode${config.suffix}x$iterations",
'IsolateJson.SendAndExit_Decode${config.suffix}x$iterations',
useSendAndExit: true,
sample: config.sample,
numTasks: iterations)
.report();
SyncJsonDecodingBenchmark(
"IsolateJson.SyncDecode${config.suffix}x$iterations",
'IsolateJson.SyncDecode${config.suffix}x$iterations',
sample: config.sample,
iterations: iterations)
.report();

View File

@ -6,8 +6,6 @@ import 'dart:async';
import 'dart:isolate';
import 'dart:math';
import 'package:meta/meta.dart';
import 'package:compiler/src/dart2js.dart' as dart2js_main;
class SpawnLatency {
@ -16,17 +14,17 @@ class SpawnLatency {
Future<ResultMessageLatency> run() async {
final completerResult = Completer();
final receivePort = ReceivePort()..listen(completerResult.complete);
final Completer<DateTime> isolateExitedCompleter = Completer<DateTime>();
final isolateExitedCompleter = Completer<DateTime>();
final onExitReceivePort = ReceivePort()
..listen((_) {
isolateExitedCompleter.complete(DateTime.now());
});
final DateTime beforeSpawn = DateTime.now();
final beforeSpawn = DateTime.now();
await Isolate.spawn(
isolateCompiler, StartMessageLatency(receivePort.sendPort, beforeSpawn),
onExit: onExitReceivePort.sendPort,
onError: onExitReceivePort.sendPort);
final DateTime afterSpawn = DateTime.now();
final afterSpawn = DateTime.now();
final ResultMessageLatency result = await completerResult.future;
receivePort.close();
@ -42,13 +40,13 @@ class SpawnLatency {
Future<AggregatedResultMessageLatency> measureFor(int minimumMillis) async {
final minimumMicros = minimumMillis * 1000;
final watch = Stopwatch()..start();
final Metric toAfterIsolateSpawnUs = LatencyMetric("${name}ToAfterSpawn");
final Metric toStartRunningCodeUs = LatencyMetric("${name}ToStartRunning");
final Metric toAfterIsolateSpawnUs = LatencyMetric('${name}ToAfterSpawn');
final Metric toStartRunningCodeUs = LatencyMetric('${name}ToStartRunning');
final Metric toFinishRunningCodeUs =
LatencyMetric("${name}ToFinishRunning");
final Metric toExitUs = LatencyMetric("${name}ToExit");
LatencyMetric('${name}ToFinishRunning');
final Metric toExitUs = LatencyMetric('${name}ToExit');
while (watch.elapsedMicroseconds < minimumMicros) {
final ResultMessageLatency result = await run();
final result = await run();
toAfterIsolateSpawnUs.add(result.timeToIsolateSpawnUs);
toStartRunningCodeUs.add(result.timeToStartRunningCodeUs);
toFinishRunningCodeUs.add(result.timeToFinishRunningCodeUs);
@ -64,16 +62,16 @@ class SpawnLatency {
}
Future<void> report() async {
final AggregatedResultMessageLatency result = await measure();
final result = await measure();
print(result);
}
final String name;
RawReceivePort receivePort;
late RawReceivePort receivePort;
}
class Metric {
Metric({@required this.prefix, @required this.suffix});
Metric({required this.prefix, required this.suffix});
void add(int value) {
if (value > max) {
@ -87,9 +85,10 @@ class Metric {
double _average() => sum / count;
double _rms() => sqrt(sumOfSquares / count);
toString() => "$prefix): ${_average()}$suffix\n"
"${prefix}Max): $max$suffix\n"
"${prefix}RMS): ${_rms()}$suffix";
@override
String toString() => '$prefix): ${_average()}$suffix\n'
'${prefix}Max): $max$suffix\n'
'${prefix}RMS): ${_rms()}$suffix';
final String prefix;
final String suffix;
@ -100,7 +99,7 @@ class Metric {
}
class LatencyMetric extends Metric {
LatencyMetric(String name) : super(prefix: "$name(Latency", suffix: " us.");
LatencyMetric(String name) : super(prefix: '$name(Latency', suffix: ' us.');
}
class StartMessageLatency {
@ -112,16 +111,14 @@ class StartMessageLatency {
class ResultMessageLatency {
ResultMessageLatency(
{this.timeToStartRunningCodeUs,
this.timeToFinishRunningCodeUs,
this.deltaHeap});
{required this.timeToStartRunningCodeUs,
required this.timeToFinishRunningCodeUs});
final int timeToStartRunningCodeUs;
final int timeToFinishRunningCodeUs;
final int deltaHeap;
int timeToIsolateSpawnUs;
int timeToExitUs;
late int timeToIsolateSpawnUs;
late int timeToExitUs;
}
class AggregatedResultMessageLatency {
@ -132,10 +129,11 @@ class AggregatedResultMessageLatency {
this.toExitUs,
);
String toString() => """$toAfterIsolateSpawnUs
@override
String toString() => '''$toAfterIsolateSpawnUs
$toStartRunningCodeUs
$toFinishRunningCodeUs
$toExitUs""";
$toExitUs''';
final Metric toAfterIsolateSpawnUs;
final Metric toStartRunningCodeUs;
@ -144,15 +142,15 @@ $toExitUs""";
}
Future<void> isolateCompiler(StartMessageLatency start) async {
final DateTime timeRunningCodeUs = DateTime.now();
final timeRunningCodeUs = DateTime.now();
await runZoned(
() => dart2js_main.internalMain(<String>[
"benchmarks/IsolateSpawn/dart/helloworld.dart",
'benchmarks/IsolateSpawn/dart/helloworld.dart',
'--libraries-spec=sdk/lib/libraries.json'
]),
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {}));
final DateTime timeFinishRunningCodeUs = DateTime.now();
final timeFinishRunningCodeUs = DateTime.now();
start.sendPort.send(ResultMessageLatency(
timeToStartRunningCodeUs:
timeRunningCodeUs.difference(start.spawned).inMicroseconds,
@ -161,5 +159,5 @@ Future<void> isolateCompiler(StartMessageLatency start) async {
}
Future<void> main() async {
await SpawnLatency("IsolateSpawn.Dart2JS").report();
await SpawnLatency('IsolateSpawn.Dart2JS').report();
}

View File

@ -16,17 +16,17 @@ class SpawnLatency {
Future<ResultMessageLatency> run() async {
final completerResult = Completer();
final receivePort = ReceivePort()..listen(completerResult.complete);
final Completer<DateTime> isolateExitedCompleter = Completer<DateTime>();
final isolateExitedCompleter = Completer<DateTime>();
final onExitReceivePort = ReceivePort()
..listen((_) {
isolateExitedCompleter.complete(DateTime.now());
});
final DateTime beforeSpawn = DateTime.now();
final beforeSpawn = DateTime.now();
await Isolate.spawn(
isolateCompiler, StartMessageLatency(receivePort.sendPort, beforeSpawn),
onExit: onExitReceivePort.sendPort,
onError: onExitReceivePort.sendPort);
final DateTime afterSpawn = DateTime.now();
final afterSpawn = DateTime.now();
final ResultMessageLatency result = await completerResult.future;
receivePort.close();
@ -42,13 +42,13 @@ class SpawnLatency {
Future<AggregatedResultMessageLatency> measureFor(int minimumMillis) async {
final minimumMicros = minimumMillis * 1000;
final watch = Stopwatch()..start();
final Metric toAfterIsolateSpawnUs = LatencyMetric("${name}ToAfterSpawn");
final Metric toStartRunningCodeUs = LatencyMetric("${name}ToStartRunning");
final Metric toAfterIsolateSpawnUs = LatencyMetric('${name}ToAfterSpawn');
final Metric toStartRunningCodeUs = LatencyMetric('${name}ToStartRunning');
final Metric toFinishRunningCodeUs =
LatencyMetric("${name}ToFinishRunning");
final Metric toExitUs = LatencyMetric("${name}ToExit");
LatencyMetric('${name}ToFinishRunning');
final Metric toExitUs = LatencyMetric('${name}ToExit');
while (watch.elapsedMicroseconds < minimumMicros) {
final ResultMessageLatency result = await run();
final result = await run();
toAfterIsolateSpawnUs.add(result.timeToIsolateSpawnUs);
toStartRunningCodeUs.add(result.timeToStartRunningCodeUs);
toFinishRunningCodeUs.add(result.timeToFinishRunningCodeUs);
@ -64,7 +64,7 @@ class SpawnLatency {
}
Future<void> report() async {
final AggregatedResultMessageLatency result = await measure();
final result = await measure();
print(result);
}
@ -87,9 +87,10 @@ class Metric {
double _average() => sum / count;
double _rms() => sqrt(sumOfSquares / count);
toString() => "$prefix): ${_average()}$suffix\n"
"${prefix}Max): $max$suffix\n"
"${prefix}RMS): ${_rms()}$suffix";
@override
String toString() => '$prefix): ${_average()}$suffix\n'
'${prefix}Max): $max$suffix\n'
'${prefix}RMS): ${_rms()}$suffix';
final String prefix;
final String suffix;
@ -100,7 +101,7 @@ class Metric {
}
class LatencyMetric extends Metric {
LatencyMetric(String name) : super(prefix: "$name(Latency", suffix: " us.");
LatencyMetric(String name) : super(prefix: '$name(Latency', suffix: ' us.');
}
class StartMessageLatency {
@ -132,10 +133,11 @@ class AggregatedResultMessageLatency {
this.toExitUs,
);
String toString() => """$toAfterIsolateSpawnUs
@override
String toString() => '''$toAfterIsolateSpawnUs
$toStartRunningCodeUs
$toFinishRunningCodeUs
$toExitUs""";
$toExitUs''';
final Metric toAfterIsolateSpawnUs;
final Metric toStartRunningCodeUs;
@ -144,15 +146,15 @@ $toExitUs""";
}
Future<void> isolateCompiler(StartMessageLatency start) async {
final DateTime timeRunningCodeUs = DateTime.now();
final timeRunningCodeUs = DateTime.now();
await runZoned(
() => dart2js_main.internalMain(<String>[
"benchmarks/IsolateSpawn/dart2/helloworld.dart",
'benchmarks/IsolateSpawn/dart/helloworld.dart',
'--libraries-spec=sdk/lib/libraries.json'
]),
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {}));
final DateTime timeFinishRunningCodeUs = DateTime.now();
final timeFinishRunningCodeUs = DateTime.now();
start.sendPort.send(ResultMessageLatency(
timeToStartRunningCodeUs:
timeRunningCodeUs.difference(start.spawned).inMicroseconds,
@ -161,5 +163,5 @@ Future<void> isolateCompiler(StartMessageLatency start) async {
}
Future<void> main() async {
await SpawnLatency("IsolateSpawn.Dart2JS").report();
await SpawnLatency('IsolateSpawn.Dart2JS').report();
}

View File

@ -96,11 +96,11 @@ class SpawnMemory {
final doneDiffHeap =
math.max(0, doneHeap - beforeHeap) ~/ numberOfBenchmarks;
print("${name}RssOnStart(MemoryUse): $readyDiffRss");
print("${name}RssOnEnd(MemoryUse): $doneDiffRss");
print("${name}HeapOnStart(MemoryUse): $readyDiffHeap");
print("${name}HeapOnEnd(MemoryUse): $doneDiffHeap");
print("${name}PeakProcessRss(MemoryUse): $maxProcessRss");
print('${name}RssOnStart(MemoryUse): $readyDiffRss');
print('${name}RssOnEnd(MemoryUse): $doneDiffRss');
print('${name}HeapOnStart(MemoryUse): $readyDiffHeap');
print('${name}HeapOnEnd(MemoryUse): $doneDiffHeap');
print('${name}PeakProcessRss(MemoryUse): $maxProcessRss');
}
final String name;
@ -117,7 +117,7 @@ Future<void> isolateCompiler(StartMessage startMessage) async {
await runZoned(
() => dart2js_main.internalMain(<String>[
"benchmarks/IsolateSpawnMemory/dart/helloworld.dart",
'benchmarks/IsolateSpawnMemory/dart/helloworld.dart',
'--libraries-spec=sdk/lib/libraries.json'
]),
zoneSpecification: ZoneSpecification(
@ -133,13 +133,11 @@ Future<void> isolateCompiler(StartMessage startMessage) async {
}
Future<int> currentHeapUsage(String wsUri) async {
final vm_service.VmService vmService =
await vm_service_io.vmServiceConnectUri(wsUri);
final vmService = await vm_service_io.vmServiceConnectUri(wsUri);
final groupIds = await getGroupIds(vmService);
int sum = 0;
for (final groupId in groupIds) {
final vm_service.MemoryUsage usage =
await vmService.getIsolateGroupMemoryUsage(groupId);
final usage = await vmService.getIsolateGroupMemoryUsage(groupId);
sum += usage.heapUsage + usage.externalUsage;
}
vmService.dispose();
@ -150,11 +148,10 @@ Future<void> main() async {
// Only if we successfully reach the end will we set 0 exit code.
exitCode = 255;
final ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
final Uri observatoryUri = info.serverUri;
final String wsUri =
'ws://${observatoryUri.authority}${observatoryUri.path}ws';
await SpawnMemory("IsolateSpawnMemory.Dart2JSDelta", wsUri).report();
final info = await Service.controlWebServer(enable: true);
final observatoryUri = info.serverUri!;
final wsUri = 'ws://${observatoryUri.authority}${observatoryUri.path}ws';
await SpawnMemory('IsolateSpawnMemory.Dart2JSDelta', wsUri).report();
// Only if we successfully reach the end will we set 0 exit code.
exitCode = 0;
@ -174,10 +171,9 @@ Future<void> main() async {
Future<List<String>> getGroupIds(vm_service.VmService vmService) async {
final groupIds = <String>{};
final vm = await vmService.getVM();
for (vm_service.IsolateGroupRef groupRef in vm.isolateGroups) {
final vm_service.IsolateGroup group =
await vmService.getIsolateGroup(groupRef.id);
for (vm_service.IsolateRef isolateRef in group.isolates) {
for (final groupRef in vm.isolateGroups) {
final group = await vmService.getIsolateGroup(groupRef.id);
for (final isolateRef in group.isolates) {
final isolateOrSentinel = await vmService.getIsolate(isolateRef.id);
if (isolateOrSentinel is vm_service.Isolate) {
groupIds.add(groupRef.id);
@ -185,7 +181,7 @@ Future<List<String>> getGroupIds(vm_service.VmService vmService) async {
}
}
if (groupIds.isEmpty) {
throw "Could not find main isolate";
throw 'Could not find main isolate';
}
return groupIds.toList();
}

View File

@ -96,11 +96,11 @@ class SpawnMemory {
final doneDiffHeap =
math.max(0, doneHeap - beforeHeap) ~/ numberOfBenchmarks;
print("${name}RssOnStart(MemoryUse): $readyDiffRss");
print("${name}RssOnEnd(MemoryUse): $doneDiffRss");
print("${name}HeapOnStart(MemoryUse): $readyDiffHeap");
print("${name}HeapOnEnd(MemoryUse): $doneDiffHeap");
print("${name}PeakProcessRss(MemoryUse): $maxProcessRss");
print('${name}RssOnStart(MemoryUse): $readyDiffRss');
print('${name}RssOnEnd(MemoryUse): $doneDiffRss');
print('${name}HeapOnStart(MemoryUse): $readyDiffHeap');
print('${name}HeapOnEnd(MemoryUse): $doneDiffHeap');
print('${name}PeakProcessRss(MemoryUse): $maxProcessRss');
}
final String name;
@ -117,7 +117,7 @@ Future<void> isolateCompiler(StartMessage startMessage) async {
await runZoned(
() => dart2js_main.internalMain(<String>[
"benchmarks/IsolateSpawnMemory/dart2/helloworld.dart",
'benchmarks/IsolateSpawnMemory/dart/helloworld.dart',
'--libraries-spec=sdk/lib/libraries.json'
]),
zoneSpecification: ZoneSpecification(
@ -133,13 +133,11 @@ Future<void> isolateCompiler(StartMessage startMessage) async {
}
Future<int> currentHeapUsage(String wsUri) async {
final vm_service.VmService vmService =
await vm_service_io.vmServiceConnectUri(wsUri);
final vmService = await vm_service_io.vmServiceConnectUri(wsUri);
final groupIds = await getGroupIds(vmService);
int sum = 0;
for (final groupId in groupIds) {
final vm_service.MemoryUsage usage =
await vmService.getIsolateGroupMemoryUsage(groupId);
final usage = await vmService.getIsolateGroupMemoryUsage(groupId);
sum += usage.heapUsage + usage.externalUsage;
}
vmService.dispose();
@ -150,11 +148,10 @@ Future<void> main() async {
// Only if we successfully reach the end will we set 0 exit code.
exitCode = 255;
final ServiceProtocolInfo info = await Service.controlWebServer(enable: true);
final Uri observatoryUri = info.serverUri;
final String wsUri =
'ws://${observatoryUri.authority}${observatoryUri.path}ws';
await SpawnMemory("IsolateSpawnMemory.Dart2JSDelta", wsUri).report();
final info = await Service.controlWebServer(enable: true);
final observatoryUri = info.serverUri;
final wsUri = 'ws://${observatoryUri.authority}${observatoryUri.path}ws';
await SpawnMemory('IsolateSpawnMemory.Dart2JSDelta', wsUri).report();
// Only if we successfully reach the end will we set 0 exit code.
exitCode = 0;
@ -174,10 +171,9 @@ Future<void> main() async {
Future<List<String>> getGroupIds(vm_service.VmService vmService) async {
final groupIds = <String>{};
final vm = await vmService.getVM();
for (vm_service.IsolateGroupRef groupRef in vm.isolateGroups) {
final vm_service.IsolateGroup group =
await vmService.getIsolateGroup(groupRef.id);
for (vm_service.IsolateRef isolateRef in group.isolates) {
for (final groupRef in vm.isolateGroups) {
final group = await vmService.getIsolateGroup(groupRef.id);
for (final isolateRef in group.isolates) {
final isolateOrSentinel = await vmService.getIsolate(isolateRef.id);
if (isolateOrSentinel is vm_service.Isolate) {
groupIds.add(groupRef.id);
@ -185,7 +181,7 @@ Future<List<String>> getGroupIds(vm_service.VmService vmService) async {
}
}
if (groupIds.isEmpty) {
throw "Could not find main isolate";
throw 'Could not find main isolate';
}
return groupIds.toList();
}