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

Side by Side Diff: tools/traceline/svgui/traceline.js

Issue 118377: Some improvements and bug fixes to traceline. (Closed)
Patch Set: for in file Created 11 years, 6 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
« no previous file with comments | « no previous file | tools/traceline/traceline/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO 5 // TODO
6 // - spacial partitioning of the data so that we don't have to scan the 6 // - spacial partitioning of the data so that we don't have to scan the
7 // entire scene every time we render. 7 // entire scene every time we render.
8 // - properly clip the SVG elements when they render, right now we are just 8 // - properly clip the SVG elements when they render, right now we are just
9 // letting them go negative or off the screen. This might give us a little 9 // letting them go negative or off the screen. This might give us a little
10 // bit better performance? 10 // bit better performance?
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 " parent: " + this.parent; 69 " parent: " + this.parent;
70 return res; 70 return res;
71 }; 71 };
72 72
73 // A TLEvent represents a single logged event that happened on a thread. 73 // A TLEvent represents a single logged event that happened on a thread.
74 function TLEvent(e) { 74 function TLEvent(e) {
75 this.eventtype = e['eventtype']; 75 this.eventtype = e['eventtype'];
76 this.thread = toHex(e['thread']); 76 this.thread = toHex(e['thread']);
77 this.cpu = toHex(e['cpu']); 77 this.cpu = toHex(e['cpu']);
78 this.ms = e['ms']; 78 this.ms = e['ms'];
79 this.done = e['done'];
79 this.e = e; 80 this.e = e;
80 } 81 }
81 82
82 function HTMLEscape(str) { 83 function HTMLEscape(str) {
83 return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); 84 return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
84 } 85 }
85 86
86 TLEvent.prototype.toString = 87 TLEvent.prototype.toString =
87 function() { 88 function() {
88 var res = "<b>ms:</b> " + this.ms + " " + 89 var res = "<b>ms:</b> " + this.ms + " " +
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 var e = new TLEvent(json_data[i]); 234 var e = new TLEvent(json_data[i]);
234 235
235 // Create a unique identifier for a thread by using the id of this data 236 // Create a unique identifier for a thread by using the id of this data
236 // set, so that they are isolated from other sets of data with the same 237 // set, so that they are isolated from other sets of data with the same
237 // thread id, etc. TODO don't overwrite the original... 238 // thread id, etc. TODO don't overwrite the original...
238 e.thread = set_id + '_' + e.thread; 239 e.thread = set_id + '_' + e.thread;
239 240
240 // If this is the first event ever seen on this thread, create a new 241 // If this is the first event ever seen on this thread, create a new
241 // thread object and add it to our lists of threads. 242 // thread object and add it to our lists of threads.
242 if (!(e.thread in this.threads_by_id)) { 243 if (!(e.thread in this.threads_by_id)) {
243 var new_thread = new TLThread(e.thread, e.ms, e.ms); 244 var end_ms = e.done ? e.done : e.ms;
245 var new_thread = new TLThread(e.thread, e.ms, end_ms);
244 this.threads_by_id[new_thread.id] = this.threads.length; 246 this.threads_by_id[new_thread.id] = this.threads.length;
245 this.threads.push(new_thread); 247 this.threads.push(new_thread);
246 } 248 }
247 249
248 var thread = this.threads[this.threads_by_id[e.thread]]; 250 var thread = this.threads[this.threads_by_id[e.thread]];
249 thread.AddEvent(e); 251 thread.AddEvent(e);
250 252
251 // Keep trace of the time of the last event seen. 253 // Keep trace of the time of the last event seen.
252 if (e.ms > this.endms) this.endms = e.ms; 254 var end_ms = e.done ? e.done : e.ms;
253 if (e.ms > thread.endms) thread.endms = e.ms; 255 if (end_ms > this.endms) this.endms = end_ms;
256 if (end_ms > thread.endms) thread.endms = end_ms;
254 257
255 switch(e.eventtype) { 258 switch(e.eventtype) {
256 case 'EVENT_TYPE_THREADNAME': 259 case 'EVENT_TYPE_THREADNAME':
257 thread.name = e.e['threadname']; 260 thread.name = e.e['threadname'];
258 break; 261 break;
259 case 'EVENT_TYPE_CREATETHREAD': 262 case 'EVENT_TYPE_CREATETHREAD':
260 tiez[e.e['eventid']] = e; 263 tiez[e.e['eventid']] = e;
261 break; 264 break;
262 case 'EVENT_TYPE_THREADBEGIN': 265 case 'EVENT_TYPE_THREADBEGIN':
263 var pei = e.e['parenteventid']; 266 var pei = e.e['parenteventid'];
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // Remove everything from the DOM. 636 // Remove everything from the DOM.
634 while (svg.firstChild) 637 while (svg.firstChild)
635 svg.removeChild(svg.firstChild); 638 svg.removeChild(svg.firstChild);
636 639
637 // Don't actually need this, but you can't transform on an svg element, 640 // Don't actually need this, but you can't transform on an svg element,
638 // so it's nice to have a <g> around for transforms... 641 // so it's nice to have a <g> around for transforms...
639 var svgg = document.createElementNS(svgNS, 'g'); 642 var svgg = document.createElementNS(svgNS, 'g');
640 643
641 var dur = this.kTimelineWidthPx / curzoom; 644 var dur = this.kTimelineWidthPx / curzoom;
642 645
646 function min(a, b) {
647 return a < b ? a : b;
648 }
649
650 function max(a, b) {
651 return a > b ? a : b;
652 }
653
643 function timeToPixel(x) { 654 function timeToPixel(x) {
644 var x = Math.floor(x*curzoom); 655 // TODO(deanm): This clip is a bit shady.
656 var x = min(max(Math.floor(x*curzoom), -100), 2000);
645 return (x == 0 ? 1 : x); 657 return (x == 0 ? 1 : x);
646 } 658 }
647 659
648 for (var i = 0, il = stuff.length; i < il; ++i) { 660 for (var i = 0, il = stuff.length; i < il; ++i) {
649 var thing = stuff[i]; 661 var thing = stuff[i];
650 if (!thing.hittest(startms, startms+dur)) 662 if (!thing.hittest(startms, startms+dur))
651 continue; 663 continue;
652 664
653 665
654 if (thing.type == SVGSceneRect) { 666 if (thing.type == SVGSceneRect) {
655 var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect'); 667 var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
656 rect.setAttributeNS(null, 'class', thing.klass) 668 rect.setAttributeNS(null, 'class', thing.klass)
657 // TODO timeToPixel could be negative, clamp it at 0
658 rect.setAttributeNS(null, 'x', timeToPixel(thing.x - startms)); 669 rect.setAttributeNS(null, 'x', timeToPixel(thing.x - startms));
659 rect.setAttributeNS(null, 'y', thing.y); 670 rect.setAttributeNS(null, 'y', thing.y);
660 // TODO thing.width can be larger than our current view, clamp it.
661 rect.setAttributeNS(null, 'width', timeToPixel(thing.width)); 671 rect.setAttributeNS(null, 'width', timeToPixel(thing.width));
662 rect.setAttributeNS(null, 'height', thing.height); 672 rect.setAttributeNS(null, 'height', thing.height);
663 rect.msg = thing.msg; 673 rect.msg = thing.msg;
664 svgg.appendChild(rect); 674 svgg.appendChild(rect);
665 } else if (thing.type == SVGSceneLine) { 675 } else if (thing.type == SVGSceneLine) {
666 var line = document.createElementNS('http://www.w3.org/2000/svg', 'line'); 676 var line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
667 line.setAttributeNS(null, 'class', thing.klass) 677 line.setAttributeNS(null, 'class', thing.klass)
668 // TODO timeToPixel could be negative, clamp it at 0
669 line.setAttributeNS(null, 'x1', timeToPixel(thing.x1 - startms)); 678 line.setAttributeNS(null, 'x1', timeToPixel(thing.x1 - startms));
670 line.setAttributeNS(null, 'y1', thing.y1); 679 line.setAttributeNS(null, 'y1', thing.y1);
671 line.setAttributeNS(null, 'x2', timeToPixel(thing.x2 - startms)); 680 line.setAttributeNS(null, 'x2', timeToPixel(thing.x2 - startms));
672 line.setAttributeNS(null, 'y2', thing.y2); 681 line.setAttributeNS(null, 'y2', thing.y2);
673 line.msg = thing.msg; 682 line.msg = thing.msg;
674 svgg.appendChild(line); 683 svgg.appendChild(line);
675 } 684 }
676 685
677 ++count; 686 ++count;
678 } 687 }
679 688
680 // Append the 'g' element on after we've build it. 689 // Append the 'g' element on after we've build it.
681 svg.appendChild(svgg); 690 svg.appendChild(svgg);
682 691
683 return count; 692 return count;
684 }; 693 };
OLDNEW
« no previous file with comments | « no previous file | tools/traceline/traceline/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698