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

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

Issue 2748403002: Added page to Observatory to display native memory allocation information. (Closed)
Patch Set: Added page to Observatory to display native memory allocation information. Created 3 years, 9 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
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 String _tagToString(M.SampleProfileTag tag) { 7 String _tagToString(M.SampleProfileTag tag) {
8 switch (tag) { 8 switch (tag) {
9 case M.SampleProfileTag.userVM: 9 case M.SampleProfileTag.userVM:
10 return 'UserVM'; 10 return 'UserVM';
(...skipping 14 matching lines...) Expand all
25 final SampleProfileLoadingProgress progress; 25 final SampleProfileLoadingProgress progress;
26 SampleProfileLoadingProgressEvent(this.progress); 26 SampleProfileLoadingProgressEvent(this.progress);
27 } 27 }
28 28
29 class SampleProfileLoadingProgress extends M.SampleProfileLoadingProgress { 29 class SampleProfileLoadingProgress extends M.SampleProfileLoadingProgress {
30 StreamController<SampleProfileLoadingProgressEvent> _onProgress = 30 StreamController<SampleProfileLoadingProgressEvent> _onProgress =
31 new StreamController<SampleProfileLoadingProgressEvent>.broadcast(); 31 new StreamController<SampleProfileLoadingProgressEvent>.broadcast();
32 Stream<SampleProfileLoadingProgressEvent> get onProgress => 32 Stream<SampleProfileLoadingProgressEvent> get onProgress =>
33 _onProgress.stream; 33 _onProgress.stream;
34 34
35 final S.Isolate isolate; 35 final Object owner;
Cutch 2017/03/21 20:27:11 Use the type ServiceObjectOwner instead of Object
bkonyi 2017/03/22 21:25:21 Done.
36 final S.Class cls; 36 final S.Class cls;
37 final M.SampleProfileTag tag; 37 final M.SampleProfileTag tag;
38 final bool clear; 38 final bool clear;
39 final bool isCpuProfile;
Cutch 2017/03/21 20:27:11 isn't there an enum for the profile type? Use that
bkonyi 2017/03/22 21:25:21 Done.
39 40
40 M.SampleProfileLoadingStatus _status = M.SampleProfileLoadingStatus.fetching; 41 M.SampleProfileLoadingStatus _status = M.SampleProfileLoadingStatus.fetching;
41 double _progress = 0.0; 42 double _progress = 0.0;
42 final Stopwatch _fetchingTime = new Stopwatch(); 43 final Stopwatch _fetchingTime = new Stopwatch();
43 final Stopwatch _loadingTime = new Stopwatch(); 44 final Stopwatch _loadingTime = new Stopwatch();
44 CpuProfile _profile; 45 CpuProfile _profile;
45 46
46 M.SampleProfileLoadingStatus get status => _status; 47 M.SampleProfileLoadingStatus get status => _status;
47 double get progress => _progress; 48 double get progress => _progress;
48 Duration get fetchingTime => _fetchingTime.elapsed; 49 Duration get fetchingTime => _fetchingTime.elapsed;
49 Duration get loadingTime => _loadingTime.elapsed; 50 Duration get loadingTime => _loadingTime.elapsed;
50 CpuProfile get profile => _profile; 51 CpuProfile get profile => _profile;
51 52
52 SampleProfileLoadingProgress(this.isolate, this.tag, this.clear, {this.cls}) { 53 SampleProfileLoadingProgress(this.owner, this.tag, this.clear,
54 {this.isCpuProfile: true, this.cls}) {
53 _run(); 55 _run();
54 } 56 }
55 57
56 Future _run() async { 58 Future _run() async {
57 _fetchingTime.start(); 59 _fetchingTime.start();
58 try { 60 try {
59 if (clear) { 61 if (clear && isCpuProfile) {
60 await isolate.invokeRpc('_clearCpuProfile', {}); 62 await owner.invokeRpc('_clearCpuProfile', {});
61 } 63 }
62 64
63 final response = cls != null 65 var response;
66 if (isCpuProfile) {
67 response = cls != null
64 ? await cls.getAllocationSamples(_tagToString(tag)) 68 ? await cls.getAllocationSamples(_tagToString(tag))
65 : await isolate 69 : await owner
66 .invokeRpc('_getCpuProfile', {'tags': _tagToString(tag)}); 70 .invokeRpc('_getCpuProfile', {'tags': _tagToString(tag)});
71 } else {
72 assert(owner is M.VM);
73 M.VM vm = owner as M.VM;
74 response = await owner.invokeRpc('_getNativeAllocationSamples', {'tags':
75 _tagToString(tag)});
76 }
67 77
68 _fetchingTime.stop(); 78 _fetchingTime.stop();
69 _loadingTime.start(); 79 _loadingTime.start();
70 _status = M.SampleProfileLoadingStatus.loading; 80 _status = M.SampleProfileLoadingStatus.loading;
71 _triggerOnProgress(); 81 _triggerOnProgress();
72 82
73 CpuProfile profile = new CpuProfile(); 83 CpuProfile profile = new CpuProfile();
74 84
75 Stream<double> progress = profile.loadProgress(isolate, response); 85 Stream<double> progress = profile.loadProgress(owner, response);
76 progress.listen((value) { 86 progress.listen((value) {
77 _progress = value; 87 _progress = value;
78 _triggerOnProgress(); 88 _triggerOnProgress();
79 }); 89 });
80 90
81 await progress.drain(); 91 await progress.drain();
82 92
83 profile.buildFunctionCallerAndCallees(); 93 profile.buildFunctionCallerAndCallees();
84 _profile = profile; 94 _profile = profile;
85 95
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 implements M.IsolateSampleProfileRepository { 127 implements M.IsolateSampleProfileRepository {
118 SampleProfileLoadingProgress _last; 128 SampleProfileLoadingProgress _last;
119 129
120 Stream<SampleProfileLoadingProgressEvent> get( 130 Stream<SampleProfileLoadingProgressEvent> get(
121 M.IsolateRef i, M.SampleProfileTag t, 131 M.IsolateRef i, M.SampleProfileTag t,
122 {bool clear: false, bool forceFetch: false}) { 132 {bool clear: false, bool forceFetch: false}) {
123 assert(clear != null); 133 assert(clear != null);
124 assert(forceFetch != null); 134 assert(forceFetch != null);
125 S.Isolate isolate = i as S.Isolate; 135 S.Isolate isolate = i as S.Isolate;
126 assert(isolate != null); 136 assert(isolate != null);
127 if (_last != null && !clear && !forceFetch && _last.isolate == isolate) { 137 if (_last != null && !clear && !forceFetch && _last.owner == isolate) {
128 _last.reuse(); 138 _last.reuse();
129 } else { 139 } else {
130 _last = new SampleProfileLoadingProgress(isolate, t, clear); 140 _last = new SampleProfileLoadingProgress(isolate, t, clear);
131 } 141 }
132 return _last.onProgress; 142 return _last.onProgress;
133 } 143 }
134 } 144 }
135 145
136 class ClassSampleProfileRepository implements M.ClassSampleProfileRepository { 146 class ClassSampleProfileRepository implements M.ClassSampleProfileRepository {
137 Stream<SampleProfileLoadingProgressEvent> get( 147 Stream<SampleProfileLoadingProgressEvent> get(
(...skipping 11 matching lines...) Expand all
149 assert(cls != null); 159 assert(cls != null);
150 return cls.setTraceAllocations(true); 160 return cls.setTraceAllocations(true);
151 } 161 }
152 162
153 Future disable(M.IsolateRef i, M.ClassRef c) { 163 Future disable(M.IsolateRef i, M.ClassRef c) {
154 S.Class cls = c as S.Class; 164 S.Class cls = c as S.Class;
155 assert(cls != null); 165 assert(cls != null);
156 return cls.setTraceAllocations(false); 166 return cls.setTraceAllocations(false);
157 } 167 }
158 } 168 }
169
170 class NativeMemorySampleProfileRepository
171 implements M.NativeMemorySampleProfileRepository {
172 SampleProfileLoadingProgress _last;
173
174 Stream<SampleProfileLoadingProgressEvent> get(
175 M.VM vm, M.SampleProfileTag t, {bool forceFetch: false}) {
176 assert(forceFetch != null);
177 if (_last != null && !clear && !forceFetch) {
178 _last.reuse();
179 } else {
180 _last = new SampleProfileLoadingProgress(vm, t, false, isCpuProfile: false
181 );
182 }
183 return _last.onProgress;
184 }
185 }
186
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698