Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: runtime/observatory/lib/src/repositories/heap_snapshot.dart

Issue 2266343002: Converted Observatory heap-snapshot element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Added missing explanation text Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file
4
5 part of repositories;
6
7 class HeapSnapshotLoadingProgressEvent
8 implements M.HeapSnapshotLoadingProgressEvent {
9 final HeapSnapshotLoadingProgress progress;
10 HeapSnapshotLoadingProgressEvent(this.progress);
11 }
12
13 class HeapSnapshotLoadingProgress extends M.HeapSnapshotLoadingProgress {
14 StreamController<HeapSnapshotLoadingProgressEvent> _onProgress =
15 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast();
16 Stream<HeapSnapshotLoadingProgressEvent> get onProgress =>
17 _onProgress.stream;
18
19 final S.Isolate isolate;
20 final bool gc;
21
22 M.HeapSnapshotLoadingStatus _status = M.HeapSnapshotLoadingStatus.fetching;
23 double _progress = 0.0;
24 final Stopwatch _fetchingTime = new Stopwatch();
25 final Stopwatch _loadingTime = new Stopwatch();
26 HeapSnapshot _snapshot;
27
28 M.HeapSnapshotLoadingStatus get status => _status;
29 double get progress => _progress;
30 Duration get fetchingTime => _fetchingTime.elapsed;
31 Duration get loadingTime => _loadingTime.elapsed;
32 HeapSnapshot get snapshot => _snapshot;
33
34 HeapSnapshotLoadingProgress(this.isolate, this.gc) {
35 _run();
36 }
37
38 Future _run() async {
39 _fetchingTime.start();
40 try {
41 await isolate.getClassRefs();
42 final response = await isolate.fetchHeapSnapshot(gc).last;
43
44 _fetchingTime.stop();
45 _loadingTime.start();
46 _status = M.HeapSnapshotLoadingStatus.loading;
47 _triggerOnProgress();
48
49 HeapSnapshot snapshot = new HeapSnapshot();
50
51 Stream<double> progress = snapshot.loadProgress(isolate, response);
52 progress.listen((value) { _progress = value; _triggerOnProgress(); });
53
54 await progress.drain();
55
56 _snapshot = snapshot;
57
58 _loadingTime.stop();
59 _status = M.HeapSnapshotLoadingStatus.loaded;
60 _triggerOnProgress();
61 } catch (e) {
62 if (e is S.ServerRpcException) {
63 if (e.code == S.ServerRpcException.kFeatureDisabled) {
64 _status = M.HeapSnapshotLoadingStatus.disabled;
65 _triggerOnProgress();
66 }
67 }
68 rethrow;
69 } finally {
70 _onProgress.close();
71 }
72 }
73
74 void _triggerOnProgress() {
75 _onProgress.add(new HeapSnapshotLoadingProgressEvent(this));
76 }
77
78 void reuse() {
79 _onProgress =
80 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast();
81 (() async {
82 _triggerOnProgress();
83 _onProgress.close();
84 }());
85 }
86 }
87
88 class HeapSnapshotRepository
89 implements M.HeapSnapshotRepository {
90
91 Stream<HeapSnapshotLoadingProgressEvent> get(M.IsolateRef i,
92 {bool gc: false}) {
93 S.Isolate isolate = i as S.Isolate;
94 assert(isolate != null);
95 assert(gc != null);
96 return new HeapSnapshotLoadingProgress(isolate, gc).onProgress;
97 }
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698