| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file | 3 // BSD-style license that can be found in the LICENSE file |
| 4 | 4 |
| 5 part of repositories; | 5 part of repositories; |
| 6 | 6 |
| 7 class HeapSnapshotLoadingProgressEvent | 7 class HeapSnapshotLoadingProgressEvent |
| 8 implements M.HeapSnapshotLoadingProgressEvent { | 8 implements M.HeapSnapshotLoadingProgressEvent { |
| 9 final HeapSnapshotLoadingProgress progress; | 9 final HeapSnapshotLoadingProgress progress; |
| 10 HeapSnapshotLoadingProgressEvent(this.progress); | 10 HeapSnapshotLoadingProgressEvent(this.progress); |
| 11 } | 11 } |
| 12 | 12 |
| 13 class HeapSnapshotLoadingProgress extends M.HeapSnapshotLoadingProgress { | 13 class HeapSnapshotLoadingProgress extends M.HeapSnapshotLoadingProgress { |
| 14 StreamController<HeapSnapshotLoadingProgressEvent> _onProgress = | 14 StreamController<HeapSnapshotLoadingProgressEvent> _onProgress = |
| 15 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast(); | 15 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast(); |
| 16 Stream<HeapSnapshotLoadingProgressEvent> get onProgress => _onProgress.stream; | 16 Stream<HeapSnapshotLoadingProgressEvent> get onProgress => _onProgress.stream; |
| 17 | 17 |
| 18 final S.Isolate isolate; | 18 final S.Isolate isolate; |
| 19 final M.HeapSnapshotRoots roots; |
| 19 final bool gc; | 20 final bool gc; |
| 20 | 21 |
| 21 M.HeapSnapshotLoadingStatus _status = M.HeapSnapshotLoadingStatus.fetching; | 22 M.HeapSnapshotLoadingStatus _status = M.HeapSnapshotLoadingStatus.fetching; |
| 22 String _stepDescription = ''; | 23 String _stepDescription = ''; |
| 23 double _progress = 0.0; | 24 double _progress = 0.0; |
| 24 final Stopwatch _fetchingTime = new Stopwatch(); | 25 final Stopwatch _fetchingTime = new Stopwatch(); |
| 25 final Stopwatch _loadingTime = new Stopwatch(); | 26 final Stopwatch _loadingTime = new Stopwatch(); |
| 26 HeapSnapshot _snapshot; | 27 HeapSnapshot _snapshot; |
| 27 | 28 |
| 28 M.HeapSnapshotLoadingStatus get status => _status; | 29 M.HeapSnapshotLoadingStatus get status => _status; |
| 29 String get stepDescription => _stepDescription; | 30 String get stepDescription => _stepDescription; |
| 30 double get progress => _progress; | 31 double get progress => _progress; |
| 31 Duration get fetchingTime => _fetchingTime.elapsed; | 32 Duration get fetchingTime => _fetchingTime.elapsed; |
| 32 Duration get loadingTime => _loadingTime.elapsed; | 33 Duration get loadingTime => _loadingTime.elapsed; |
| 33 HeapSnapshot get snapshot => _snapshot; | 34 HeapSnapshot get snapshot => _snapshot; |
| 34 | 35 |
| 35 HeapSnapshotLoadingProgress(this.isolate, this.gc) { | 36 HeapSnapshotLoadingProgress(this.isolate, this.roots, this.gc) { |
| 36 _run(); | 37 _run(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 Future _run() async { | 40 Future _run() async { |
| 40 _fetchingTime.start(); | 41 _fetchingTime.start(); |
| 41 try { | 42 try { |
| 42 _status = M.HeapSnapshotLoadingStatus.fetching; | 43 _status = M.HeapSnapshotLoadingStatus.fetching; |
| 43 _triggerOnProgress(); | 44 _triggerOnProgress(); |
| 44 | 45 |
| 45 await isolate.getClassRefs(); | 46 await isolate.getClassRefs(); |
| 46 | 47 |
| 47 final stream = isolate.fetchHeapSnapshot(gc); | 48 final stream = isolate.fetchHeapSnapshot(roots, gc); |
| 48 | 49 |
| 49 stream.listen((status) { | 50 stream.listen((status) { |
| 50 if (status is List) { | 51 if (status is List) { |
| 51 _progress = status[0] * 100.0 / status[1]; | 52 _progress = status[0] * 100.0 / status[1]; |
| 52 _stepDescription = 'Receiving snapshot chunk ${status[0] + 1}' | 53 _stepDescription = 'Receiving snapshot chunk ${status[0] + 1}' |
| 53 ' of ${status[1]}...'; | 54 ' of ${status[1]}...'; |
| 54 _triggerOnProgress(); | 55 _triggerOnProgress(); |
| 55 } | 56 } |
| 56 }); | 57 }); |
| 57 | 58 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 _onProgress = | 93 _onProgress = |
| 93 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast(); | 94 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast(); |
| 94 (() async { | 95 (() async { |
| 95 _triggerOnProgress(); | 96 _triggerOnProgress(); |
| 96 _onProgress.close(); | 97 _onProgress.close(); |
| 97 }()); | 98 }()); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 class HeapSnapshotRepository implements M.HeapSnapshotRepository { | 102 class HeapSnapshotRepository implements M.HeapSnapshotRepository { |
| 102 Stream<HeapSnapshotLoadingProgressEvent> get(M.IsolateRef i, | 103 Stream<HeapSnapshotLoadingProgressEvent> get( |
| 103 {bool gc: false}) { | 104 M.IsolateRef i, |
| 105 {M.HeapSnapshotRoots roots: M.HeapSnapshotRoots.vm, |
| 106 bool gc: false}) { |
| 104 S.Isolate isolate = i as S.Isolate; | 107 S.Isolate isolate = i as S.Isolate; |
| 105 assert(isolate != null); | 108 assert(isolate != null); |
| 106 assert(gc != null); | 109 assert(gc != null); |
| 107 return new HeapSnapshotLoadingProgress(isolate, gc).onProgress; | 110 return new HeapSnapshotLoadingProgress(isolate, roots, gc).onProgress; |
| 108 } | 111 } |
| 109 } | 112 } |
| OLD | NEW |