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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/observatory/lib/src/repositories/heap_snapshot.dart
diff --git a/runtime/observatory/lib/src/repositories/heap_snapshot.dart b/runtime/observatory/lib/src/repositories/heap_snapshot.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b7fc514f6f95c8e64d403e5c7f7c370fab0cb717
--- /dev/null
+++ b/runtime/observatory/lib/src/repositories/heap_snapshot.dart
@@ -0,0 +1,98 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file
+
+part of repositories;
+
+class HeapSnapshotLoadingProgressEvent
+ implements M.HeapSnapshotLoadingProgressEvent {
+ final HeapSnapshotLoadingProgress progress;
+ HeapSnapshotLoadingProgressEvent(this.progress);
+}
+
+class HeapSnapshotLoadingProgress extends M.HeapSnapshotLoadingProgress {
+ StreamController<HeapSnapshotLoadingProgressEvent> _onProgress =
+ new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast();
+ Stream<HeapSnapshotLoadingProgressEvent> get onProgress =>
+ _onProgress.stream;
+
+ final S.Isolate isolate;
+ final bool gc;
+
+ M.HeapSnapshotLoadingStatus _status = M.HeapSnapshotLoadingStatus.fetching;
+ double _progress = 0.0;
+ final Stopwatch _fetchingTime = new Stopwatch();
+ final Stopwatch _loadingTime = new Stopwatch();
+ HeapSnapshot _snapshot;
+
+ M.HeapSnapshotLoadingStatus get status => _status;
+ double get progress => _progress;
+ Duration get fetchingTime => _fetchingTime.elapsed;
+ Duration get loadingTime => _loadingTime.elapsed;
+ HeapSnapshot get snapshot => _snapshot;
+
+ HeapSnapshotLoadingProgress(this.isolate, this.gc) {
+ _run();
+ }
+
+ Future _run() async {
+ _fetchingTime.start();
+ try {
+ await isolate.getClassRefs();
+ final response = await isolate.fetchHeapSnapshot(gc).last;
+
+ _fetchingTime.stop();
+ _loadingTime.start();
+ _status = M.HeapSnapshotLoadingStatus.loading;
+ _triggerOnProgress();
+
+ HeapSnapshot snapshot = new HeapSnapshot();
+
+ Stream<double> progress = snapshot.loadProgress(isolate, response);
+ progress.listen((value) { _progress = value; _triggerOnProgress(); });
+
+ await progress.drain();
+
+ _snapshot = snapshot;
+
+ _loadingTime.stop();
+ _status = M.HeapSnapshotLoadingStatus.loaded;
+ _triggerOnProgress();
+ } catch (e) {
+ if (e is S.ServerRpcException) {
+ if (e.code == S.ServerRpcException.kFeatureDisabled) {
+ _status = M.HeapSnapshotLoadingStatus.disabled;
+ _triggerOnProgress();
+ }
+ }
+ rethrow;
+ } finally {
+ _onProgress.close();
+ }
+ }
+
+ void _triggerOnProgress() {
+ _onProgress.add(new HeapSnapshotLoadingProgressEvent(this));
+ }
+
+ void reuse() {
+ _onProgress =
+ new StreamController<HeapSnapshotLoadingProgressEvent>.broadcast();
+ (() async {
+ _triggerOnProgress();
+ _onProgress.close();
+ }());
+ }
+}
+
+class HeapSnapshotRepository
+ implements M.HeapSnapshotRepository {
+
+ Stream<HeapSnapshotLoadingProgressEvent> get(M.IsolateRef i,
+ {bool gc: false}) {
+ S.Isolate isolate = i as S.Isolate;
+ assert(isolate != null);
+ assert(gc != null);
+ return new HeapSnapshotLoadingProgress(isolate, gc).onProgress;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698