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

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

Issue 100103011: Changes to support dprof and Observatory profiler UIs (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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library isolate_profile_element;
6
7 import 'dart:convert';
8 import 'dart:html';
9 import 'package:dprof/model.dart' as dprof;
10 import 'package:polymer/polymer.dart';
11 import 'observatory_element.dart';
12
13 /// Displays an IsolateProfile
14 @CustomTag('isolate-profile')
15 class IsolateProfileElement extends ObservatoryElement {
16 IsolateProfileElement.created() : super.created();
17 @observable int methodCountSelected = 0;
18 final List methodCounts = [10, 20, 50];
19 @observable List topInclusiveCodes = toObservable([]);
20 @observable List topExclusiveCodes = toObservable([]);
21 @observable bool disassemble = false;
22 void _startRequest() {
23 // TODO(johnmccutchan): Indicate visually.
24 print('Request sent.');
25 }
26
27 void _endRequest() {
28 // TODO(johnmccutchan): Indicate visually.
29 print('Request finished.');
30 }
31
32 methodCountSelectedChanged(oldValue) {
33 print('Refresh top');
34 var isolateId = app.locationManager.currentIsolateId();
35 var isolate = app.isolateManager.getIsolate(isolateId);
36 if (isolate == null) {
37 print('No isolate found.');
38 }
39 _refreshTopMethods(isolate);
40 }
41
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) {
48 var isolateId = app.locationManager.currentIsolateId();
49 var isolate = app.isolateManager.getIsolate(isolateId);
50 if (isolate == null) {
51 print('No isolate found.');
52 }
53 var request = '/$isolateId/profile';
54 _startRequest();
55 app.requestManager.request(request).then((response) {
56 var profile;
57 try {
58 profile = JSON.decode(response);
59 } catch (e) { print(e); }
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();
66 }).catchError((e) {
67 _endRequest();
68 });
69 }
70
71 void _loadProfileData(Isolate isolate, int totalSamples, List codes) {
72 isolate.profiler = new dprof.Isolate(0, 0);
73 var loader = new dprof.Loader(isolate.profiler);
74 loader.load(totalSamples, codes);
75 _refreshTopMethods(isolate);
76 }
77
78 void _refreshTopMethods(Isolate isolate) {
79 topExclusiveCodes.clear();
80 topInclusiveCodes.clear();
81 if ((isolate == null) || (isolate.profiler == null)) {
82 return;
83 }
84 var count = methodCounts[methodCountSelected];
85 var topExclusive = isolate.profiler.topExclusive(count);
86 topExclusiveCodes.addAll(topExclusive);
87 var topInclusive = isolate.profiler.topInclusive(count);
88 topInclusiveCodes.addAll(topInclusive);
89
90 }
91
92 String codeTicks(dprof.Code code, bool inclusive) {
93 if (code == null) {
94 return '';
95 }
96 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}';
97 }
98
99 String codePercent(dprof.Code code, bool inclusive) {
100 if (code == null) {
101 return '';
102 }
103 var isolateId = app.locationManager.currentIsolateId();
104 var isolate = app.isolateManager.getIsolate(isolateId);
105 if (isolate == null) {
106 return '';
107 }
108 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks;
109 var total = ticks / isolate.profiler.totalSamples;
110 return (total * 100.0).toStringAsFixed(2);
111 }
112
113 String codeName(dprof.Code code) {
114 if ((code == null) || (code.method == null)) {
115 return '';
116 }
117 return code.method.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 }
149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698