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

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: Removed debug code Created 4 years, 3 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 String _stepDescription = '';
24 double _progress = 0.0;
25 final Stopwatch _fetchingTime = new Stopwatch();
26 final Stopwatch _loadingTime = new Stopwatch();
27 HeapSnapshot _snapshot;
28
29 M.HeapSnapshotLoadingStatus get status => _status;
30 String get stepDescription => _stepDescription;
31 double get progress => _progress;
32 Duration get fetchingTime => _fetchingTime.elapsed;
33 Duration get loadingTime => _loadingTime.elapsed;
34 HeapSnapshot get snapshot => _snapshot;
35
36 HeapSnapshotLoadingProgress(this.isolate, this.gc) {
37 _run();
38 }
39
40 Future _run() async {
41 _fetchingTime.start();
42 try {
43 _status = M.HeapSnapshotLoadingStatus.fetching;
44 _triggerOnProgress();
45
46 await isolate.getClassRefs();
47
48 final stream = isolate.fetchHeapSnapshot(gc);
49
50 stream.listen((status) {
51 if (status is List) {
52 _progress = status[0] * 100.0 / status[1];
53 _stepDescription = 'Receiving snapshot chunk ${status[0] + 1}'
54 ' of ${status[1]}...';
55 _triggerOnProgress();
56 }
57 });
58
59 final response = await stream.last;
60
61 _fetchingTime.stop();
62 _loadingTime.start();
63 _status = M.HeapSnapshotLoadingStatus.loading;
64 _stepDescription = '';
65 _triggerOnProgress();
66
67 HeapSnapshot snapshot = new HeapSnapshot();
68
69 Stream<List> progress = snapshot.loadProgress(isolate, response);
70 progress.listen((value) {
71 _stepDescription = value[0];
72 _progress = value[1];
73 _triggerOnProgress();
74 });
75
76 await progress.drain();
77
78 _snapshot = snapshot;
79
80 _loadingTime.stop();
81 _status = M.HeapSnapshotLoadingStatus.loaded;
82 _triggerOnProgress();
83 } finally {
84 _onProgress.close();
85 }
86 }
87
88 void _triggerOnProgress() {
89 _onProgress.add(new HeapSnapshotLoadingProgressEvent(this));
90 }
91
92 void reuse() {
93 _onProgress =
94 new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast();
95 (() async {
96 _triggerOnProgress();
97 _onProgress.close();
98 }());
99 }
100 }
101
102 class HeapSnapshotRepository
103 implements M.HeapSnapshotRepository {
104
105 Stream<HeapSnapshotLoadingProgressEvent> get(M.IsolateRef i,
106 {bool gc: false}) {
107 S.Isolate isolate = i as S.Isolate;
108 assert(isolate != null);
109 assert(gc != null);
110 return new HeapSnapshotLoadingProgress(isolate, gc).onProgress;
111 }
112 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/models/repositories/heap_snapshot.dart ('k') | runtime/observatory/lib/src/service/object.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698