| 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 => | 16 Stream<HeapSnapshotLoadingProgressEvent> get onProgress => _onProgress.stream; |
| 17 _onProgress.stream; | |
| 18 | 17 |
| 19 final S.Isolate isolate; | 18 final S.Isolate isolate; |
| 20 final bool gc; | 19 final bool gc; |
| 21 | 20 |
| 22 M.HeapSnapshotLoadingStatus _status = M.HeapSnapshotLoadingStatus.fetching; | 21 M.HeapSnapshotLoadingStatus _status = M.HeapSnapshotLoadingStatus.fetching; |
| 23 String _stepDescription = ''; | 22 String _stepDescription = ''; |
| 24 double _progress = 0.0; | 23 double _progress = 0.0; |
| 25 final Stopwatch _fetchingTime = new Stopwatch(); | 24 final Stopwatch _fetchingTime = new Stopwatch(); |
| 26 final Stopwatch _loadingTime = new Stopwatch(); | 25 final Stopwatch _loadingTime = new Stopwatch(); |
| 27 HeapSnapshot _snapshot; | 26 HeapSnapshot _snapshot; |
| 28 | 27 |
| 29 M.HeapSnapshotLoadingStatus get status => _status; | 28 M.HeapSnapshotLoadingStatus get status => _status; |
| 30 String get stepDescription => _stepDescription; | 29 String get stepDescription => _stepDescription; |
| 31 double get progress => _progress; | 30 double get progress => _progress; |
| 32 Duration get fetchingTime => _fetchingTime.elapsed; | 31 Duration get fetchingTime => _fetchingTime.elapsed; |
| 33 Duration get loadingTime => _loadingTime.elapsed; | 32 Duration get loadingTime => _loadingTime.elapsed; |
| 34 HeapSnapshot get snapshot => _snapshot; | 33 HeapSnapshot get snapshot => _snapshot; |
| 35 | 34 |
| 36 HeapSnapshotLoadingProgress(this.isolate, this.gc) { | 35 HeapSnapshotLoadingProgress(this.isolate, this.gc) { |
| 37 _run(); | 36 _run(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 Future _run() async { | 39 Future _run() async { |
| 41 _fetchingTime.start(); | 40 _fetchingTime.start(); |
| 42 try { | 41 try { |
| 43 _status = M.HeapSnapshotLoadingStatus.fetching; | 42 _status = M.HeapSnapshotLoadingStatus.fetching; |
| 44 _triggerOnProgress(); | 43 _triggerOnProgress(); |
| 45 | 44 |
| 46 await isolate.getClassRefs(); | 45 await isolate.getClassRefs(); |
| 47 | 46 |
| 48 final stream = isolate.fetchHeapSnapshot(gc); | 47 final stream = isolate.fetchHeapSnapshot(gc); |
| 49 | 48 |
| 50 stream.listen((status) { | 49 stream.listen((status) { |
| 51 if (status is List) { | 50 if (status is List) { |
| 52 _progress = status[0] * 100.0 / status[1]; | 51 _progress = status[0] * 100.0 / status[1]; |
| 53 _stepDescription = 'Receiving snapshot chunk ${status[0] + 1}' | 52 _stepDescription = 'Receiving snapshot chunk ${status[0] + 1}' |
| 54 ' of ${status[1]}...'; | 53 ' of ${status[1]}...'; |
| 55 _triggerOnProgress(); | 54 _triggerOnProgress(); |
| 56 } | 55 } |
| 57 }); | 56 }); |
| 58 | 57 |
| 59 final response = await stream.last; | 58 final response = await stream.last; |
| 60 | 59 |
| 61 _fetchingTime.stop(); | 60 _fetchingTime.stop(); |
| 62 _loadingTime.start(); | 61 _loadingTime.start(); |
| 63 _status = M.HeapSnapshotLoadingStatus.loading; | 62 _status = M.HeapSnapshotLoadingStatus.loading; |
| 64 _stepDescription = ''; | 63 _stepDescription = ''; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 _onProgress.close(); | 83 _onProgress.close(); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 void _triggerOnProgress() { | 87 void _triggerOnProgress() { |
| 89 _onProgress.add(new HeapSnapshotLoadingProgressEvent(this)); | 88 _onProgress.add(new HeapSnapshotLoadingProgressEvent(this)); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void reuse() { | 91 void reuse() { |
| 93 _onProgress = | 92 _onProgress = |
| 94 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast(); | 93 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast(); |
| 95 (() async { | 94 (() async { |
| 96 _triggerOnProgress(); | 95 _triggerOnProgress(); |
| 97 _onProgress.close(); | 96 _onProgress.close(); |
| 98 }()); | 97 }()); |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 | 100 |
| 102 class HeapSnapshotRepository | 101 class HeapSnapshotRepository implements M.HeapSnapshotRepository { |
| 103 implements M.HeapSnapshotRepository { | |
| 104 | |
| 105 Stream<HeapSnapshotLoadingProgressEvent> get(M.IsolateRef i, | 102 Stream<HeapSnapshotLoadingProgressEvent> get(M.IsolateRef i, |
| 106 {bool gc: false}) { | 103 {bool gc: false}) { |
| 107 S.Isolate isolate = i as S.Isolate; | 104 S.Isolate isolate = i as S.Isolate; |
| 108 assert(isolate != null); | 105 assert(isolate != null); |
| 109 assert(gc != null); | 106 assert(gc != null); |
| 110 return new HeapSnapshotLoadingProgress(isolate, gc).onProgress; | 107 return new HeapSnapshotLoadingProgress(isolate, gc).onProgress; |
| 111 } | 108 } |
| 112 } | 109 } |
| OLD | NEW |