2019-09-25 00:39:56 +00:00
|
|
|
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
import 'package:test/test.dart';
|
2021-04-20 22:21:28 +00:00
|
|
|
import 'package:vm_service/vm_service.dart';
|
2019-09-25 00:39:56 +00:00
|
|
|
|
|
|
|
import 'common/test_helper.dart';
|
|
|
|
|
|
|
|
Future<void> sleep(int milliseconds) =>
|
|
|
|
Future.delayed(Duration(milliseconds: milliseconds));
|
|
|
|
|
|
|
|
var tests = <IsolateTest>[
|
|
|
|
(VmService service, IsolateRef isolate) async {
|
2021-01-20 00:37:05 +00:00
|
|
|
final isolateId = isolate.id!;
|
|
|
|
|
|
|
|
AllocationProfile result = await service.getAllocationProfile(isolateId);
|
2019-09-25 00:39:56 +00:00
|
|
|
expect(result.dateLastAccumulatorReset, isNull);
|
|
|
|
expect(result.dateLastServiceGC, isNull);
|
2021-01-20 00:37:05 +00:00
|
|
|
expect(result.members!.length, isPositive);
|
2019-09-25 00:39:56 +00:00
|
|
|
|
2021-01-20 00:37:05 +00:00
|
|
|
ClassHeapStats member = result.members![0];
|
2019-09-25 00:39:56 +00:00
|
|
|
expect(member.instancesAccumulated, isNotNull);
|
|
|
|
expect(member.instancesCurrent, isNotNull);
|
|
|
|
expect(member.bytesCurrent, isNotNull);
|
|
|
|
expect(member.accumulatedSize, isNotNull);
|
|
|
|
|
|
|
|
// reset.
|
2021-01-20 00:37:05 +00:00
|
|
|
result = await service.getAllocationProfile(isolateId, reset: true);
|
2019-09-25 00:39:56 +00:00
|
|
|
final firstReset = result.dateLastAccumulatorReset;
|
|
|
|
expect(firstReset, isNotNull);
|
|
|
|
expect(result.dateLastServiceGC, isNull);
|
2021-01-20 00:37:05 +00:00
|
|
|
expect(result.members!.length, isPositive);
|
2019-09-25 00:39:56 +00:00
|
|
|
|
2021-01-20 00:37:05 +00:00
|
|
|
member = result.members![0];
|
2019-09-25 00:39:56 +00:00
|
|
|
expect(member.instancesAccumulated, isNotNull);
|
|
|
|
expect(member.instancesCurrent, isNotNull);
|
|
|
|
expect(member.bytesCurrent, isNotNull);
|
|
|
|
expect(member.accumulatedSize, isNotNull);
|
|
|
|
|
|
|
|
await sleep(1000);
|
|
|
|
|
2021-01-20 00:37:05 +00:00
|
|
|
result = await service.getAllocationProfile(isolateId, reset: true);
|
2019-09-25 00:39:56 +00:00
|
|
|
final secondReset = result.dateLastAccumulatorReset;
|
|
|
|
expect(secondReset, isNot(firstReset));
|
|
|
|
|
|
|
|
// gc.
|
2021-01-20 00:37:05 +00:00
|
|
|
result = await service.getAllocationProfile(isolateId, gc: true);
|
2019-09-25 00:39:56 +00:00
|
|
|
expect(result.dateLastAccumulatorReset, secondReset);
|
|
|
|
final firstGC = result.dateLastServiceGC;
|
|
|
|
expect(firstGC, isNotNull);
|
2021-01-20 00:37:05 +00:00
|
|
|
expect(result.members!.length, isPositive);
|
2019-09-25 00:39:56 +00:00
|
|
|
|
2021-01-20 00:37:05 +00:00
|
|
|
member = result.members![0];
|
2019-09-25 00:39:56 +00:00
|
|
|
expect(member.instancesAccumulated, isNotNull);
|
|
|
|
expect(member.instancesCurrent, isNotNull);
|
|
|
|
expect(member.bytesCurrent, isNotNull);
|
|
|
|
expect(member.accumulatedSize, isNotNull);
|
|
|
|
|
|
|
|
await sleep(1000);
|
|
|
|
|
2021-01-20 00:37:05 +00:00
|
|
|
result = await service.getAllocationProfile(isolateId, gc: true);
|
2019-09-25 00:39:56 +00:00
|
|
|
final secondGC = result.dateLastAccumulatorReset;
|
|
|
|
expect(secondGC, isNot(firstGC));
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-02-12 07:12:54 +00:00
|
|
|
main([args = const <String>[]]) async => runIsolateTests(
|
|
|
|
args,
|
|
|
|
tests,
|
|
|
|
'get_allocation_profile_rpc_test.dart',
|
|
|
|
);
|