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

Side by Side Diff: runtime/observatory/lib/src/elements/script_inset.dart

Issue 977283002: Display call site data for functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | 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 script_inset_element; 5 library script_inset_element;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'observatory_element.dart'; 9 import 'observatory_element.dart';
10 import 'package:observatory/service.dart'; 10 import 'package:observatory/service.dart';
11 import 'package:polymer/polymer.dart'; 11 import 'package:polymer/polymer.dart';
12 12
13 const nbsp = "\u00A0"; 13 const nbsp = "\u00A0";
14 14
15 class Annotation { 15 abstract class Annotation {
16 int line; 16 int line;
17 int columnStart; 17 int columnStart;
18 int columnStop; 18 int columnStop;
19 String title;
20 19
20 void applyStyleTo(element);
21 }
22
23 class CurrentExecutionAnnotation extends Annotation {
21 void applyStyleTo(element) { 24 void applyStyleTo(element) {
25 if (element == null) {
26 return; // TODO(rmacnak): Handling overlapping annotations.
27 }
22 element.classes.add("currentCol"); 28 element.classes.add("currentCol");
23 element.title = title; 29 element.title = "Current execution";
24 } 30 }
25 } 31 }
26 32
33 class CallSiteAnnotation extends Annotation {
34 CallSite callSite;
35
36 void applyStyleTo(element) {
37 if (element == null) {
38 return; // TODO(rmacnak): Handling overlapping annotations.
39 }
40 element.style.textDecoration = "underline";
41 element.style.color = "blue";
42
43 StringBuffer sb = new StringBuffer();
44 sb.write("Call site: ");
45 sb.write(callSite.name);
46 sb.write("\n");
47 for (var entry in callSite.entries) {
48 sb.write("Class: ");
49 // TODO(rmacnak): Make this a link.
50 sb.write(entry.receiverContainer.name);
51 sb.write(" Count: ");
52 sb.write(entry.count);
53 sb.write("\n");
54 }
55 element.title = sb.toString();
56 }
57 }
58
27 /// Box with script source code in it. 59 /// Box with script source code in it.
28 @CustomTag('script-inset') 60 @CustomTag('script-inset')
29 class ScriptInsetElement extends ObservatoryElement { 61 class ScriptInsetElement extends ObservatoryElement {
30 @published Script script; 62 @published Script script;
31 63
32 /// Set the height to make the script inset scroll. Otherwise it 64 /// Set the height to make the script inset scroll. Otherwise it
33 /// will show from startPos to endPos. 65 /// will show from startPos to endPos.
34 @published String height = null; 66 @published String height = null;
35 67
36 @published int currentPos; 68 @published int currentPos;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 : null); 175 : null);
144 currentCol = (currentPos != null 176 currentCol = (currentPos != null
145 ? (script.tokenToCol(currentPos) - 1) // make this 0-based. 177 ? (script.tokenToCol(currentPos) - 1) // make this 0-based.
146 : null); 178 : null);
147 endLine = (endPos != null 179 endLine = (endPos != null
148 ? script.tokenToLine(endPos) 180 ? script.tokenToLine(endPos)
149 : script.lines.length); 181 : script.lines.length);
150 182
151 annotations.clear(); 183 annotations.clear();
152 if (currentLine != null) { 184 if (currentLine != null) {
153 var a = new Annotation(); 185 var a = new CurrentExecutionAnnotation();
154 a.line = currentLine; 186 a.line = currentLine;
155 a.columnStart = currentCol; 187 a.columnStart = currentCol;
156 a.columnStop = currentCol + 1; 188 a.columnStop = currentCol + 1;
157 a.title = "Point of interest";
158 annotations.add(a); 189 annotations.add(a);
159 } 190 }
160 191
161 // TODO(rmacnak): Call site data. 192 for (var callSite in script.callSites) {
193 var a = new CallSiteAnnotation();
194 a.line = callSite.line;
195 a.columnStart = callSite.column - 1; // Call site is 1-origin.
196 var tokenLength = callSite.name.length; // Approximate.
197 a.columnStop = a.columnStart + tokenLength;
198 a.callSite = callSite;
199 annotations.add(a);
200 }
201
202 annotations.sort((a, b) {
203 if (a.line == b.line) {
204 return a.columnStart.compareTo(b.columnStart);
205 }
206 return a.line.compareTo(b.line);
207 });
162 } 208 }
163 209
164 Element linesTable() { 210 Element linesTable() {
165 var table = new DivElement(); 211 var table = new DivElement();
166 table.classes.add("sourceTable"); 212 table.classes.add("sourceTable");
167 213
168 annotationsCursor = 0; 214 annotationsCursor = 0;
169 215
170 int blankLineCount = 0; 216 int blankLineCount = 0;
171 for (int i = (startLine - 1); i <= (endLine - 1); i++) { 217 for (int i = (startLine - 1); i <= (endLine - 1); i++) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (line != null) { 289 if (line != null) {
244 if (line.line == currentLine) { 290 if (line.line == currentLine) {
245 e.classes.add("currentLine"); 291 e.classes.add("currentLine");
246 } 292 }
247 293
248 e.id = makeLineId(line.line); 294 e.id = makeLineId(line.line);
249 295
250 var position = 0; 296 var position = 0;
251 consumeUntil(var stop) { 297 consumeUntil(var stop) {
252 if (stop <= position) { 298 if (stop <= position) {
253 return; // Empty gap between annotations/boundries. 299 return null; // Empty gap between annotations/boundries.
254 } 300 }
301 if (stop > line.text.length) {
302 // Approximated token length can run past the end of the line.
303 stop = line.text.length;
304 }
305
255 var chunk = line.text.substring(position, stop); 306 var chunk = line.text.substring(position, stop);
256 var chunkNode = span(chunk); 307 var chunkNode = span(chunk);
257 e.append(chunkNode); 308 e.append(chunkNode);
258 position = stop; 309 position = stop;
259 return chunkNode; 310 return chunkNode;
260 } 311 }
261 312
262 // TODO(rmacnak): Tolerate overlapping annotations. 313 // TODO(rmacnak): Tolerate overlapping annotations.
263 var annotation; 314 var annotation;
264 while ((annotation = nextAnnotationOnLine(line.line)) != null) { 315 while ((annotation = nextAnnotationOnLine(line.line)) != null) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 pending.add(line.script.isolate.removeBreakpoint(bpt)); 347 pending.add(line.script.isolate.removeBreakpoint(bpt));
297 } 348 }
298 Future.wait(pending).then((_) { 349 Future.wait(pending).then((_) {
299 busy = false; 350 busy = false;
300 }); 351 });
301 } 352 }
302 } 353 }
303 354
304 BreakpointToggleElement.created() : super.created(); 355 BreakpointToggleElement.created() : super.created();
305 } 356 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/function_view.dart ('k') | runtime/observatory/lib/src/service/object.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698