Commit a0369806 authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[fuchsia_reload] Give more information in the module list (#9400)

parent cedc9fb2
...@@ -9,6 +9,7 @@ import '../base/common.dart'; ...@@ -9,6 +9,7 @@ import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/utils.dart';
import '../cache.dart'; import '../cache.dart';
import '../device.dart'; import '../device.dart';
import '../flx.dart' as flx; import '../flx.dart' as flx;
...@@ -150,9 +151,30 @@ class FuchsiaReloadCommand extends FlutterCommand { ...@@ -150,9 +151,30 @@ class FuchsiaReloadCommand extends FlutterCommand {
} }
Future<Null> _listViews(List<int> ports) async { Future<Null> _listViews(List<int> ports) async {
const String bold = '\u001B[0;1m';
const String reset = '\u001B[0m';
for (FlutterView v in await _getViews(ports)) { for (FlutterView v in await _getViews(ports)) {
final Uri addr = v.owner.vmService.httpAddress; final Uri addr = v.owner.vmService.httpAddress;
printStatus('At $addr, found view: ${v.uiIsolate.name}'); final Isolate i = v.uiIsolate;
final String name = i.name;
final String shortName = name.substring(0, name.indexOf('\$'));
final String main = '\$main-';
final String number = name.substring(name.indexOf(main) + main.length);
final String newUsed = getSizeAsMB(i.newSpace.used);
final String newCap = getSizeAsMB(i.newSpace.capacity);
final String newFreq = '${i.newSpace.avgCollectionTime.inMilliseconds}ms';
final String newPer = '${i.newSpace.avgCollectionPeriod.inSeconds}s';
final String oldUsed = getSizeAsMB(i.oldSpace.used);
final String oldCap = getSizeAsMB(i.oldSpace.capacity);
final String oldFreq = '${i.oldSpace.avgCollectionTime.inMilliseconds}ms';
final String oldPer = '${i.oldSpace.avgCollectionPeriod.inSeconds}s';
printStatus(
'$bold$shortName$reset\n'
'\tIsolate number: $number\n'
'\tObservatory: $addr\n'
'\tNew gen: $newUsed used of $newCap, GC: $newFreq every $newPer\n'
'\tOld gen: $oldUsed used of $oldCap, GC: $oldFreq every $oldPer\n'
);
} }
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert' show BASE64; import 'dart:convert' show BASE64;
import 'dart:math' as math;
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:json_rpc_2/error_code.dart' as rpc_error_code; import 'package:json_rpc_2/error_code.dart' as rpc_error_code;
...@@ -773,6 +774,44 @@ class VM extends ServiceObjectOwner { ...@@ -773,6 +774,44 @@ class VM extends ServiceObjectOwner {
} }
} }
class HeapSpace extends ServiceObject {
HeapSpace._empty(ServiceObjectOwner owner) : super._empty(owner);
int _used = 0;
int _capacity = 0;
int _external = 0;
int _collections = 0;
double _totalCollectionTimeInSeconds = 0.0;
double _averageCollectionPeriodInMillis = 0.0;
int get used => _used;
int get capacity => _capacity;
int get external => _external;
Duration get avgCollectionTime {
final double mcs = _totalCollectionTimeInSeconds *
Duration.MICROSECONDS_PER_SECOND /
math.max(_collections, 1);
return new Duration(microseconds: mcs.ceil());
}
Duration get avgCollectionPeriod {
final double mcs = _averageCollectionPeriodInMillis *
Duration.MICROSECONDS_PER_MILLISECOND;
return new Duration(microseconds: mcs.ceil());
}
@override
void _update(Map<String, dynamic> map, bool mapIsRef) {
_used = map['used'];
_capacity = map['capacity'];
_external = map['external'];
_collections = map['collections'];
_totalCollectionTimeInSeconds = map['time'];
_averageCollectionPeriodInMillis = map['avgCollectionPeriodMillis'];
}
}
/// An isolate running inside the VM. Instances of the Isolate class are always /// An isolate running inside the VM. Instances of the Isolate class are always
/// canonicalized. /// canonicalized.
class Isolate extends ServiceObjectOwner { class Isolate extends ServiceObjectOwner {
...@@ -792,11 +831,16 @@ class Isolate extends ServiceObjectOwner { ...@@ -792,11 +831,16 @@ class Isolate extends ServiceObjectOwner {
final Map<String, ServiceObject> _cache = <String, ServiceObject>{}; final Map<String, ServiceObject> _cache = <String, ServiceObject>{};
HeapSpace _newSpace;
HeapSpace _oldSpace;
HeapSpace get newSpace => _newSpace;
HeapSpace get oldSpace => _oldSpace;
@override @override
ServiceObject getFromMap(Map<String, dynamic> map) { ServiceObject getFromMap(Map<String, dynamic> map) {
if (map == null) { if (map == null)
return null; return null;
}
final String mapType = _stripRef(map['type']); final String mapType = _stripRef(map['type']);
if (mapType == 'Isolate') { if (mapType == 'Isolate') {
// There are sometimes isolate refs in ServiceEvents. // There are sometimes isolate refs in ServiceEvents.
...@@ -811,9 +855,8 @@ class Isolate extends ServiceObjectOwner { ...@@ -811,9 +855,8 @@ class Isolate extends ServiceObjectOwner {
} }
// Build the object from the map directly. // Build the object from the map directly.
serviceObject = new ServiceObject._fromMap(this, map); serviceObject = new ServiceObject._fromMap(this, map);
if ((serviceObject != null) && serviceObject.canCache) { if ((serviceObject != null) && serviceObject.canCache)
_cache[mapId] = serviceObject; _cache[mapId] = serviceObject;
}
return serviceObject; return serviceObject;
} }
...@@ -844,6 +887,15 @@ class Isolate extends ServiceObjectOwner { ...@@ -844,6 +887,15 @@ class Isolate extends ServiceObjectOwner {
return getFromMap(await invokeRpcRaw(method, params: params)); return getFromMap(await invokeRpcRaw(method, params: params));
} }
void _updateHeaps(Map<String, dynamic> map, bool mapIsRef) {
if (_newSpace == null)
_newSpace = new HeapSpace._empty(this);
_newSpace._update(map['new'], mapIsRef);
if (_oldSpace == null)
_oldSpace = new HeapSpace._empty(this);
_oldSpace._update(map['old'], mapIsRef);
}
@override @override
void _update(Map<String, dynamic> map, bool mapIsRef) { void _update(Map<String, dynamic> map, bool mapIsRef) {
if (mapIsRef) if (mapIsRef)
...@@ -856,6 +908,8 @@ class Isolate extends ServiceObjectOwner { ...@@ -856,6 +908,8 @@ class Isolate extends ServiceObjectOwner {
_upgradeCollection(map, this); _upgradeCollection(map, this);
pauseEvent = map['pauseEvent']; pauseEvent = map['pauseEvent'];
_updateHeaps(map['_heaps'], mapIsRef);
} }
static final int kIsolateReloadBarred = 1005; static final int kIsolateReloadBarred = 1005;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment