8 font-family:
"Courier New";
16 border-bottom:
1px dashed black;
17 background-color: #F0F0F0;
33 background-color: #FFFFCC;
35 font-family:
"Courier New";
38 border:
1px solid #CCCC88;
47 border:
1px solid silver;
49 background-color: #f0f0f0;
64 background-color: #FFFFCC;
79 border:
1px solid red;
83 background-color: green;
87 background-color: blue;
91 background-color: black;
95 background-color: orange;
100 <script src='trace_data.js'
></script>
104 var trace_initial_time
= 0;
105 var trace_threads
= {};
107 var trace_total_time
= 0;
109 function process_raw_events() {
110 trace_initial_time
= raw_trace_events
[0].usec_begin
;
113 for (var i
in raw_trace_events
) {
114 e
= raw_trace_events
[i
];
115 var trace_events
= trace_threads
["e.tid"];
118 trace_threads
["e.tid"] = trace_events
;
120 if (e
.name
.indexOf("heartbeat.") == 0) {
122 } else if (e
.type
== "BEGIN") {
123 trace_events
.push(e
);
125 } else if (e
.type
== "END") {
126 for (var s
in stack
) {
127 var begin
= stack
[s
];
128 if ((begin
.id
== e
.id
) && (begin
.name
== e
.name
) &&
129 (begin
.pid
== e
.pid
) && (begin
.tid
== e
.tid
)) {
130 begin
.usec_end
= e
.usec_begin
;
131 begin
.duration
= begin
.usec_end
- begin
.usec_begin
;
136 } else if (e
.type
== "INSTANT") {
137 trace_events
.push(e
);
142 trace_total_time
= e
.usec_end
- trace_initial_time
;
144 trace_total_time
= e
.usec_begin
- trace_initial_time
;
147 function compute_scale() {
148 var outer
= document
.getElementById("outer");
149 scale
= Math
.floor(trace_total_time
/ (outer
.offsetWidth
- (row_height
* 2)));
152 function show_details(tid
, i
, event
) {
153 var trace_events
= trace_threads
["e.tid"];
154 var inner
= trace_events
[i
].name
+ " " +
155 trace_events
[i
].duration
/ 1000 + "ms<br />" +
156 trace_events
[i
].id
+ "<br />" +
157 trace_events
[i
].extra
+ "<br />";
158 var tooltip
= document
.getElementById("tooltip");
159 tooltip
.innerHTML
= inner
;
161 event
= window
.event
;
162 tooltip
.style
.top
= event
.pageY
+ 3;
163 tooltip
.style
.left
= event
.pageX
+ 3;
164 tooltip
.style
.display
= "block";
167 function generate_time_scale() {
168 var view_size
= window
.clientWidth
;
169 var body_size
= document
.body
.scrollWidth
;
172 var step_ms
= Math
.floor(scale
/ 10); // ms per 100px
173 var pow10
= Math
.pow(10, Math
.floor(Math
.log(step_ms
) / Math
.log(10)));
174 var round
= .5 * pow10
;
175 step_ms
= round
* (Math
.floor(step_ms
/ round
)); // round to a multiple of round
176 for (var i
= step_ms
; i
< trace_total_time
/ 1000; i
+= step_ms
) {
177 var x
= Math
.floor(i
* 1000 / scale
);
178 inner
+= "<li class='time_tick' style='left: " + x
+ "px'>" + i
+ "</li>";
180 var time_scale
= document
.getElementById("time_scale");
181 time_scale
.innerHTML
= inner
;
182 time_scale
.style
.width
= document
.body
.scrollWidth
;
185 function generate_subchart(trace_events
, top
) {
187 var last_max_time
= 0;
189 for (var i
in trace_events
) {
190 var e
= trace_events
[i
];
191 var start_time
= e
.usec_begin
- trace_initial_time
;
192 var left
= row_height
+ Math
.floor(start_time
/ scale
);
193 var width
= Math
.floor(e
.duration
/ scale
);
196 if (start_time
< last_max_time
)
198 var style
= "top: " + top
+ "px; left: " + left
+ "px; width: " + width
+ "px;";
199 var js
= 'javascript:show_details("' + e
.tid
+ '", ' + i
+ ', event);';
200 var cls
= e
.name
.split('.')[0];
201 inner
+= "<li class='" + cls
+ "' onmouseover='" + js
+ "' id='li-" + i
+ "' style='" + style
+ "'></li>\n";
202 last_max_time
= start_time
+ e
.duration
;
203 last_max_x
= left
+ width
;
205 var subchart
= document
.createElement('div');
206 subchart
.setAttribute("class", "subchart");
207 subchart
.setAttribute("id", trace_events
[0].tid
);
208 subchart
.innerHTML
= inner
;
209 subchart
.style
.height
= top
+ row_height
;
210 subchart
.style
.width
= row_height
+ last_max_x
;
211 var chart
= document
.getElementById("chart");
212 chart
.appendChild(subchart
);
217 function generate_chart() {
218 var chart
= document
.getElementById("chart");
219 chart
.innerHTML
= "";
221 for (var t
in trace_threads
) {
222 top
= generate_subchart(trace_threads
[t
], top
);
224 generate_time_scale();
227 function change_scale(event
) {
229 event
= window
.event
;
233 if (event
.wheelDelta
) {
234 delta
= event
.wheelDelta
/ 120;
235 } else if (event
.detail
) {
236 delta
= - event
.detail
/ 3;
239 var tooltip
= document
.getElementById("tooltip");
240 tooltip
.style
.display
= "none";
243 scale
= Math
.floor(scale
* factor
);
245 scale
= Math
.floor(scale
/ factor
);
249 if (event
.preventDefault
)
250 event
.preventDefault();
252 event
.returnValue
= false;
255 function initial_load() {
256 if (window
.addEventListener
)
257 window
.addEventListener('DOMMouseScroll', change_scale
, false);
258 window
.onmousewheel
= document
.onmousewheel
= change_scale
;
260 process_raw_events();
267 <body onload='initial_load();'
>
269 <h2>Trace Events
</h2>
270 <div id=
"instructions">
271 Use shift+mouse-wheel to zoom in and out.
273 <div id=
"time_scale"></div>
276 <span class=
"url"> </span> URL
<br />
277 <span class=
"http"> </span> HTTP
<br />
278 <span class=
"socket"> </span> Socket
<br />
279 <span class=
"v8"> </span> V8
<br />
285 <div id=
"tooltip" ondblclick=
"this.style.display = 'none';"></div>