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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/observatory_elements/isolate_profile.dart

Issue 135843006: Improve Code object support in service and observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library isolate_profile_element; 5 library isolate_profile_element;
6 6
7 import 'dart:convert';
8 import 'dart:html'; 7 import 'dart:html';
9 import 'package:dprof/model.dart' as dprof; 8 import 'package:logging/logging.dart';
10 import 'package:polymer/polymer.dart'; 9 import 'package:polymer/polymer.dart';
11 import 'observatory_element.dart'; 10 import 'observatory_element.dart';
12 11
13 /// Displays an IsolateProfile 12 /// Displays an IsolateProfile
14 @CustomTag('isolate-profile') 13 @CustomTag('isolate-profile')
15 class IsolateProfileElement extends ObservatoryElement { 14 class IsolateProfileElement extends ObservatoryElement {
16 IsolateProfileElement.created() : super.created(); 15 IsolateProfileElement.created() : super.created();
17 @observable int methodCountSelected = 0; 16 @observable int methodCountSelected = 0;
18 final List methodCounts = [10, 20, 50]; 17 final List methodCounts = [10, 20, 50];
19 @observable List topInclusiveCodes = toObservable([]); 18 @observable List topInclusiveCodes = toObservable([]);
20 @observable List topExclusiveCodes = toObservable([]); 19 @observable List topExclusiveCodes = toObservable([]);
21 @observable bool disassemble = false; 20
21 void enteredView() {
22 var isolateId = app.locationManager.currentIsolateId();
23 var isolate = app.isolateManager.getIsolate(isolateId);
24 if (isolate == null) {
25 return;
26 }
27 _refreshTopMethods(isolate);
28 }
29
22 void _startRequest() { 30 void _startRequest() {
23 // TODO(johnmccutchan): Indicate visually. 31 // TODO(johnmccutchan): Indicate visually.
24 print('Request sent.');
25 } 32 }
26 33
27 void _endRequest() { 34 void _endRequest() {
28 // TODO(johnmccutchan): Indicate visually. 35 // TODO(johnmccutchan): Indicate visually.
29 print('Request finished.');
30 } 36 }
31 37
32 methodCountSelectedChanged(oldValue) { 38 methodCountSelectedChanged(oldValue) {;
33 print('Refresh top');
34 var isolateId = app.locationManager.currentIsolateId(); 39 var isolateId = app.locationManager.currentIsolateId();
35 var isolate = app.isolateManager.getIsolate(isolateId); 40 var isolate = app.isolateManager.getIsolate(isolateId);
36 if (isolate == null) { 41 if (isolate == null) {
37 print('No isolate found.'); 42 return;
38 } 43 }
39 _refreshTopMethods(isolate); 44 _refreshTopMethods(isolate);
40 } 45 }
41 46
42 void toggleDisassemble(Event e, var detail, CheckboxInputElement target) {
43 disassemble = target.checked;
44 print(disassemble);
45 }
46
47 void refreshData(Event e, var detail, Node target) { 47 void refreshData(Event e, var detail, Node target) {
48 var isolateId = app.locationManager.currentIsolateId(); 48 var isolateId = app.locationManager.currentIsolateId();
49 var isolate = app.isolateManager.getIsolate(isolateId); 49 var isolate = app.isolateManager.getIsolate(isolateId);
50 if (isolate == null) { 50 if (isolate == null) {
51 print('No isolate found.'); 51 Logger.root.info('No isolate found.');
52 return;
52 } 53 }
53 var request = '/$isolateId/profile'; 54 var request = '/$isolateId/profile';
54 _startRequest(); 55 _startRequest();
55 app.requestManager.request(request).then((response) { 56 app.requestManager.requestMap(request).then((Map profile) {
56 var profile; 57 assert(profile['type'] == 'Profile');
57 try { 58 var samples = profile['samples'];
58 profile = JSON.decode(response); 59 Logger.root.info('Profile contains ${samples} samples.');
59 } catch (e) { print(e); } 60 _loadProfileData(isolate, samples, profile);
60 if ((profile is Map) && (profile['type'] == 'Profile')) {
61 var codes = profile['codes'];
62 var samples = profile['samples'];
63 _loadProfileData(isolate, samples, codes);
64 }
65 _endRequest(); 61 _endRequest();
66 }).catchError((e) { 62 }).catchError((e) {
67 _endRequest(); 63 _endRequest();
68 }); 64 });
69 } 65 }
70 66
71 void _loadProfileData(Isolate isolate, int totalSamples, List codes) { 67 void _loadProfileData(Isolate isolate, int totalSamples, Map response) {
72 isolate.profiler = new dprof.Isolate(0, 0); 68 isolate.profile = new Profile.fromMap(isolate, response);
73 var loader = new dprof.Loader(isolate.profiler);
74 loader.load(totalSamples, codes);
75 _refreshTopMethods(isolate); 69 _refreshTopMethods(isolate);
76 } 70 }
77 71
78 void _refreshTopMethods(Isolate isolate) { 72 void _refreshTopMethods(Isolate isolate) {
79 topExclusiveCodes.clear(); 73 topExclusiveCodes.clear();
80 topInclusiveCodes.clear(); 74 topInclusiveCodes.clear();
81 if ((isolate == null) || (isolate.profiler == null)) { 75 if ((isolate == null) || (isolate.profile == null)) {
82 return; 76 return;
83 } 77 }
84 var count = methodCounts[methodCountSelected]; 78 var count = methodCounts[methodCountSelected];
85 var topExclusive = isolate.profiler.topExclusive(count); 79 var topExclusive = isolate.profile.topExclusive(count);
86 topExclusiveCodes.addAll(topExclusive); 80 topExclusiveCodes.addAll(topExclusive);
87 var topInclusive = isolate.profiler.topInclusive(count); 81 var topInclusive = isolate.profile.topInclusive(count);
88 topInclusiveCodes.addAll(topInclusive); 82 topInclusiveCodes.addAll(topInclusive);
89 83
90 } 84 }
91 85
92 String codeTicks(dprof.Code code, bool inclusive) { 86 String codeTicks(Code code, bool inclusive) {
93 if (code == null) { 87 if (code == null) {
94 return ''; 88 return '';
95 } 89 }
96 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}'; 90 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}';
97 } 91 }
98 92
99 String codePercent(dprof.Code code, bool inclusive) { 93 String codePercent(Code code, bool inclusive) {
100 if (code == null) { 94 if (code == null) {
101 return ''; 95 return '';
102 } 96 }
103 var isolateId = app.locationManager.currentIsolateId(); 97 var isolateId = app.locationManager.currentIsolateId();
104 var isolate = app.isolateManager.getIsolate(isolateId); 98 var isolate = app.isolateManager.getIsolate(isolateId);
105 if (isolate == null) { 99 if (isolate == null) {
106 return ''; 100 return '';
107 } 101 }
108 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks; 102 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks;
109 var total = ticks / isolate.profiler.totalSamples; 103 var total = ticks / isolate.profile.totalSamples;
110 return (total * 100.0).toStringAsFixed(2); 104 return (total * 100.0).toStringAsFixed(2);
111 } 105 }
112 106
113 String codeName(dprof.Code code) { 107 String codeName(Code code) {
114 if ((code == null) || (code.method == null)) { 108 if ((code == null) || (code.name == null)) {
115 return ''; 109 return '';
116 } 110 }
117 return code.method.name; 111 return code.name;
118 }
119
120 String instructionTicks(dprof.Instruction instruction) {
121 if (instruction == null) {
122 return '';
123 }
124 if (instruction.ticks == 0) {
125 return '';
126 }
127 return '${instruction.ticks}';
128 }
129
130 String instructionPercent(dprof.Instruction instruction,
131 dprof.Code code) {
132 if ((instruction == null) || (code == null)) {
133 return '';
134 }
135 if (instruction.ticks == 0) {
136 return '';
137 }
138 var ticks = instruction.ticks;
139 var total = ticks / code.inclusiveTicks;
140 return (total * 100.0).toStringAsFixed(2);
141 }
142
143 String instructionDisplay(dprof.Instruction instruction) {
144 if (instruction == null) {
145 return '';
146 }
147 return instruction.human;
148 } 112 }
149 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698