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

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

Issue 2204563003: Converted Observatory cpu-profile element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Removed tmp files 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 String _tagToString(M.SampleProfileTag tag) {
8 switch (tag) {
9 case M.SampleProfileTag.UserVM : return 'UserVM';
10 case M.SampleProfileTag.UserOnly : return 'UserOnly';
11 case M.SampleProfileTag.VMUser : return 'VMUser';
12 case M.SampleProfileTag.VMOnly : return 'VMOnly';
13 case M.SampleProfileTag.None : return 'None';
14 }
15 throw new Exception('Unknown SampleProfileTag');
16 }
17
18 class SampleProfileLoadingProgressEvent
19 implements M.SampleProfileLoadingProgressEvent {
20 final SampleProfileLoadingProgress progress;
21 SampleProfileLoadingProgressEvent(this.progress);
22 }
23
24 class SampleProfileLoadingProgress extends M.SampleProfileLoadingProgress {
25 StreamController<SampleProfileLoadingProgressEvent> _onProgress =
26 new StreamController<SampleProfileLoadingProgressEvent>.broadcast();
27 Stream<SampleProfileLoadingProgressEvent> get onProgress =>
28 _onProgress.stream;
29
30 final S.Isolate isolate;
31 final S.Class cls;
32 final M.SampleProfileTag tag;
33 final bool clear;
34
35 M.SampleProfileLoadingStatus _status = M.SampleProfileLoadingStatus.Fetching;
36 double _progress = 0.0;
37 final Stopwatch _fetchingTime = new Stopwatch();
38 final Stopwatch _loadingTime = new Stopwatch();
39 CpuProfile _profile;
40
41 M.SampleProfileLoadingStatus get status => _status;
42 double get progress => _progress;
43 Duration get fetchingTime => _fetchingTime.elapsed;
44 Duration get loadingTime => _loadingTime.elapsed;
45 CpuProfile get profile => _profile;
46
47 SampleProfileLoadingProgress(this.isolate, this.tag,
48 this.clear, {this.cls}) {
49 _run();
50 }
51
52 Future _run() async {
53 _fetchingTime.start();
54 try {
55 if (clear) {
56 await isolate.invokeRpc('_clearCpuProfile', { });
57 }
58
59 final response = cls != null
60 ? await cls.getAllocationSamples(_tagToString(tag))
61 : await isolate.invokeRpc('_getCpuProfile',
62 { 'tags': _tagToString(tag) });
63
64 _fetchingTime.stop();
65 _loadingTime.start();
66 _status = M.SampleProfileLoadingStatus.Loading;
67 _triggerOnProgress();
68
69 CpuProfile profile = new CpuProfile();
70
71 Stream<double> progress = profile.loadProgress(isolate, response);
72 progress.listen((value) { _progress = value; _triggerOnProgress(); });
73
74 await progress.drain();
75
76 profile.buildFunctionCallerAndCallees();
77 _profile = profile;
78
79 _loadingTime.stop();
80 _status = M.SampleProfileLoadingStatus.Loaded;
81 _triggerOnProgress();
82 } catch (e) {
83 if (e is S.ServerRpcException) {
84 if (e.code == S.ServerRpcException.kFeatureDisabled) {
85 _status = M.SampleProfileLoadingStatus.Disabled;
86 _triggerOnProgress();
87 }
88 }
89 rethrow;
90 } finally {
91 _onProgress.close();
92 }
93 }
94
95 void _triggerOnProgress() {
96 _onProgress.add(new SampleProfileLoadingProgressEvent(this));
97 }
98
99 void reuse() {
100 _onProgress =
101 new StreamController<SampleProfileLoadingProgressEvent>.broadcast();
102 (() async {
Cutch 2016/08/02 15:52:20 is this invoked?
cbernaschina 2016/08/02 17:40:24 Done.
103 _triggerOnProgress();
104 _onProgress.close();
105 });
106 }
107 }
108
109 class IsolateSampleProfileRepository
110 implements M.IsolateSampleProfileRepository {
111 SampleProfileLoadingProgress _last;
112
113 SampleProfileLoadingProgress get(M.IsolateRef i, M.SampleProfileTag t,
114 {bool clear: false, bool forceFetch: false}) {
115 assert(clear != null);
116 assert(forceFetch != null);
117 S.Isolate isolate = i as S.Isolate;
118 assert(isolate != null);
119 if (_last != null && !clear && !forceFetch && _last.isolate == isolate) {
120 return _last..reuse();
121 }
122 return _last = new SampleProfileLoadingProgress(isolate, t, clear);
123 }
124 }
125
126 class ClassSampleProfileRepository
127 implements M.ClassSampleProfileRepository {
128 SampleProfileLoadingProgress get(M.ClassRef c, M.SampleProfileTag t,
129 {bool clear: false}) {
130 S.Class cls = c as S.Class;
131 assert(cls != null);
132 return new SampleProfileLoadingProgress(cls.isolate, t, clear, cls: cls);
133 }
134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698