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

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

Issue 168833005: Add callers and callees to profiler output (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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:html'; 7 import 'dart:html';
8 import 'package:logging/logging.dart'; 8 import 'package:logging/logging.dart';
9 import 'package:observatory/observatory.dart';
9 import 'package:polymer/polymer.dart'; 10 import 'package:polymer/polymer.dart';
10 import 'observatory_element.dart'; 11 import 'observatory_element.dart';
11 12
13 class ProfileCallerTreeRow extends TableTreeRow {
14 final Isolate isolate;
15 final Code code;
16
17 static String formatPercent(num a, num total) {
18 var percent = 100.0 * (a / total);
19 return '${percent.toStringAsFixed(2)}%';
20 }
21
22 ProfileCallerTreeRow(this.isolate, this.code, ProfileCallerTreeRow parent) :
23 super(parent) {
24 // When the row is created, fill out the columns.
25 columns.add(
26 formatPercent(code.exclusiveTicks, isolate.profile.totalSamples));
27 if (parent == null) {
28 // Fill with dummy data.
29 columns.add('');
30 } else {
31 var totalAttributedCalls = parent.code.callersCount(code);
32 var totalParentCalls = parent.code.sumCallersCount();
33 columns.add(formatPercent(totalAttributedCalls, totalParentCalls));
34 }
35 columns.add(
36 formatPercent(code.inclusiveTicks, isolate.profile.totalSamples));
37 }
38
39 void onShow() {
40 if (children.length > 0) {
41 // Child rows already created.
42 return;
43 }
44 // Create child rows on demand.
45 code.callers.forEach((CodeCallCount codeCaller) {
46 var row =
47 new ProfileCallerTreeRow(isolate, codeCaller.code, this);
48 children.add(row);
49 });
50 }
51
52 void onHide() {
53 }
54 }
55
12 /// Displays an IsolateProfile 56 /// Displays an IsolateProfile
13 @CustomTag('isolate-profile') 57 @CustomTag('isolate-profile')
14 class IsolateProfileElement extends ObservatoryElement { 58 class IsolateProfileElement extends ObservatoryElement {
15 IsolateProfileElement.created() : super.created(); 59 IsolateProfileElement.created() : super.created();
16 @observable int methodCountSelected = 0; 60 @observable int methodCountSelected = 0;
17 final List methodCounts = [10, 20, 50]; 61 final List methodCounts = [10, 20, 50];
18 @observable List topInclusiveCodes = toObservable([]);
19 @observable List topExclusiveCodes = toObservable([]); 62 @observable List topExclusiveCodes = toObservable([]);
63 final _id = '#tableTree';
64 TableTree tree;
20 65
21 void enteredView() { 66 void enteredView() {
22 var isolateId = app.locationManager.currentIsolateId(); 67 var isolateId = app.locationManager.currentIsolateId();
23 var isolate = app.isolateManager.getIsolate(isolateId); 68 var isolate = app.isolateManager.getIsolate(isolateId);
24 if (isolate == null) { 69 if (isolate == null) {
25 return; 70 return;
26 } 71 }
27 _refreshTopMethods(isolate); 72 tree = new TableTree(['Method', 'Exclusive', 'Caller', 'Inclusive']);
73 _refresh(isolate);
28 } 74 }
29 75
30 void _startRequest() { 76 void _startRequest() {
31 // TODO(johnmccutchan): Indicate visually. 77 // TODO(johnmccutchan): Indicate visually.
32 } 78 }
33 79
34 void _endRequest() { 80 void _endRequest() {
35 // TODO(johnmccutchan): Indicate visually. 81 // TODO(johnmccutchan): Indicate visually.
36 } 82 }
37 83
38 methodCountSelectedChanged(oldValue) {; 84 methodCountSelectedChanged(oldValue) {
39 var isolateId = app.locationManager.currentIsolateId(); 85 var isolateId = app.locationManager.currentIsolateId();
40 var isolate = app.isolateManager.getIsolate(isolateId); 86 var isolate = app.isolateManager.getIsolate(isolateId);
41 if (isolate == null) { 87 if (isolate == null) {
42 return; 88 return;
43 } 89 }
44 _refreshTopMethods(isolate); 90 _refresh(isolate);
45 } 91 }
46 92
47 void refreshData(Event e, var detail, Node target) { 93 void refreshData(Event e, var detail, Node target) {
48 var isolateId = app.locationManager.currentIsolateId(); 94 var isolateId = app.locationManager.currentIsolateId();
49 var isolate = app.isolateManager.getIsolate(isolateId); 95 var isolate = app.isolateManager.getIsolate(isolateId);
50 if (isolate == null) { 96 if (isolate == null) {
51 Logger.root.info('No isolate found.'); 97 Logger.root.info('No isolate found.');
52 return; 98 return;
53 } 99 }
54 var request = '/$isolateId/profile'; 100 var request = '/$isolateId/profile';
55 _startRequest(); 101 _startRequest();
56 app.requestManager.requestMap(request).then((Map profile) { 102 app.requestManager.requestMap(request).then((Map profile) {
57 assert(profile['type'] == 'Profile'); 103 assert(profile['type'] == 'Profile');
58 var samples = profile['samples']; 104 var samples = profile['samples'];
59 Logger.root.info('Profile contains ${samples} samples.'); 105 Logger.root.info('Profile contains ${samples} samples.');
60 _loadProfileData(isolate, samples, profile); 106 _loadProfileData(isolate, samples, profile);
61 _endRequest(); 107 _endRequest();
62 }).catchError((e) { 108 }).catchError((e) {
63 _endRequest(); 109 _endRequest();
64 }); 110 });
65 } 111 }
66 112
67 void _loadProfileData(Isolate isolate, int totalSamples, Map response) { 113 void _loadProfileData(Isolate isolate, int totalSamples, Map response) {
68 isolate.profile = new Profile.fromMap(isolate, response); 114 isolate.profile = new Profile.fromMap(isolate, response);
115 _refresh(isolate);
116 }
117
118 void _refresh(Isolate isolate) {
69 _refreshTopMethods(isolate); 119 _refreshTopMethods(isolate);
120 _refreshTree(isolate);
70 } 121 }
71 122
123 void _refreshTree(Isolate isolate) {
124 var rootChildren = [];
125 for (var code in topExclusiveCodes) {
126 var row = new ProfileCallerTreeRow(isolate, code, null);
127 rootChildren.add(row);
128 }
129 tree.initialize(rootChildren);
130 notifyPropertyChange(#tree, null, tree);
131 }
132
133
72 void _refreshTopMethods(Isolate isolate) { 134 void _refreshTopMethods(Isolate isolate) {
73 topExclusiveCodes.clear(); 135 topExclusiveCodes.clear();
74 topInclusiveCodes.clear();
75 if ((isolate == null) || (isolate.profile == null)) { 136 if ((isolate == null) || (isolate.profile == null)) {
76 return; 137 return;
77 } 138 }
78 var count = methodCounts[methodCountSelected]; 139 var count = methodCounts[methodCountSelected];
79 var topExclusive = isolate.profile.topExclusive(count); 140 var topExclusive = isolate.profile.topExclusive(count);
80 topExclusiveCodes.addAll(topExclusive); 141 topExclusiveCodes.addAll(topExclusive);
81 var topInclusive = isolate.profile.topInclusive(count);
82 topInclusiveCodes.addAll(topInclusive);
83
84 } 142 }
85 143
86 String codeTicks(Code code, bool inclusive) { 144 String padding(TableTreeRow row) {
87 if (code == null) { 145 return 'padding-left: ${row.depth * 16}px;';
88 return '';
89 }
90 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}';
91 } 146 }
92 147
93 String codePercent(Code code, bool inclusive) { 148 String coloring(TableTreeRow row) {
94 if (code == null) { 149 const colors = const ['active', 'success', 'warning', 'danger', 'info'];
95 return ''; 150 var index = row.depth % colors.length;
96 } 151 return colors[index];
97 var isolateId = app.locationManager.currentIsolateId();
98 var isolate = app.isolateManager.getIsolate(isolateId);
99 if (isolate == null) {
100 return '';
101 }
102 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks;
103 var total = ticks / isolate.profile.totalSamples;
104 return (total * 100.0).toStringAsFixed(2);
105 } 152 }
106 153
107 String codeName(Code code) { 154 void toggleExpanded(Event e, var detail, Element target) {
108 if ((code == null) || (code.name == null)) { 155 TableElement table = shadowRoot.querySelector(_id);
109 return ''; 156 var index = table.tBodies[0].children.indexOf(target.parent) - 1;
110 } 157 assert(index >= 0);
111 return code.name; 158 assert(index < tree.rows.length);
159 tree.toggle(index);
112 } 160 }
113 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698