-
Notifications
You must be signed in to change notification settings - Fork 412
/
Copy pathindex.phtml
464 lines (424 loc) · 16.5 KB
/
index.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>webgrind</title>
<link rel="stylesheet" type="text/css" href="styles/style.css">
<link rel="stylesheet" type="text/css" href="styles/custom.css">
<link rel="shortcut icon" type="image/ico" href="favicon.ico">
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.blockUI.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.tablesorter.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.selectboxes.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sprintf.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var fileUrlFormat = '<?php echo Webgrind_Config::$fileUrlFormat?>';
var currentDataFile = null;
var callInfoLoaded = new Array();
var disableAjaxBlock = false;
function getOptions(specificFile) {
var options = new Object();
options.dataFile = specificFile || $("#dataFile").val();
options.costFormat = $('#costFormat').val();
options.showFraction = $("#showFraction").val();
options.hideInternals = $('#hideInternals').attr('checked') ? 1 : 0;
return options;
}
function update(specificFile) {
vars = getOptions(specificFile);
vars.op = 'function_list';
$.getJSON("index.php",
vars,
function(data) {
if (data.error) {
$("#hello_message").html(data.error);
$("#hello_message").show();
return;
}
callInfoLoaded = new Array();
$("#function_table tbody").empty();
for (i=0; i<data.functions.length; i++) {
callInfoLoaded[data.functions[i].nr] = false;
$("#function_table tbody").append(functionTableRow(data.functions[i], data.linkToFunctionLine));
}
currentDataFile = data.dataFile;
$("#data_file").html(data.dataFile);
$("#invoke_url").html(data.invokeUrl);
$(document).attr('title', 'webgrind of '+data.invokeUrl);
$("#mtime").html(data.mtime);
$("#shown_sum").html(data.functions.length);
$("#invocation_sum").html(data.summedInvocationCount);
$("#runtime_sum").html(data.summedRunTime);
$("#runs").html(data.runs);
var breakdown_sum = data.breakdown['internal']+data.breakdown['procedural']+data.breakdown['class']+data.breakdown['include'];
$("#breakdown").html(
'<img src="img/gradient_left.png" height="20" width="10">'+
'<img src="img/gradient_internal.png" title="internal functions" height="20" width="'+Math.floor(data.breakdown['internal']/breakdown_sum*300)+'">'+
'<img src="img/gradient_include.png" title="include/require" height="20" width="'+Math.floor(data.breakdown['include']/breakdown_sum*300)+'">'+
'<img src="img/gradient_class.png" title="class methods" height="20" width="'+Math.floor(data.breakdown['class']/breakdown_sum*300)+'">'+
'<img src="img/gradient_procedural.png" title="procedural functions" height="20" width="'+Math.floor(data.breakdown['procedural']/breakdown_sum*300)+'">'+
'<img src="img/gradient_right.png" height="20" width="10">'
);
$("#hello_message").hide();
$("#trace_view").show();
$("#function_table").trigger('update');
<?php
$sortCol = 0;
foreach (Webgrind_Config::$tableFields as $idx => $field) {
if (strpos($field, 'Cost') !== FALSE) {
$sortCol = 3 + $idx;
break;
}
}
$maxCol = 3 + count(Webgrind_Config::$tableFields);
?>
var sortCol = parseInt(document.cookie.split("=")[1]);
if ( isNaN(sortCol) || sortCol < 3 || sortCol > <?php echo $maxCol?> )
sortCol = <?php echo $sortCol?>;
$("#function_table").trigger("sorton",[[[sortCol,1]]]);
$('#callfilter').trigger('keyup');
if (window.location.hash.length > 2)
openCallInfo(window.location.hash.replace(/[^0-9]/g, ''));
}
);
}
function showCallGraph() {
vars = getOptions();
vars.op = 'function_graph';
delete vars.costFormat;
delete vars.hideInternals;
window.open('index.php?' + $.param(vars));
}
function downloadFile() {
$.getJSON('index.php',
{'op': 'download_link', 'file': currentDataFile},
function(data) {
if (data.error) {
$('#hello_message').html(data.error);
$('#hello_message').show();
return;
}
window.location = data.done;
}
);
}
function reloadFilelist() {
$.getJSON("index.php",
{'op':'file_list'},
function(data){
var options = new Object();
for (i=0; i<data.length; i++) {
options[data[i]['filename']] = data[i]['invokeUrl']+' ('+data[i]['filename']+')'+' ['+data[i]['filesize']+']';
}
$("#dataFile").removeOption(/[^0]/);
$("#dataFile").addOption(options, false);
}
);
}
function loadCallInfo(functionNr) {
$.getJSON("index.php",
{'op':'callinfo_list', 'file':currentDataFile, 'functionNr':functionNr, 'costFormat':$("#costFormat").val()},
function(data) {
if (data.error) {
$("#hello_message").html(data.error);
$("#hello_message").show();
return;
}
if (data.calledByHost)
$("#callinfo_area_"+functionNr).append('<b>Called from script host</b>');
insertCallInfo(functionNr, 'sub_calls_table_', 'Calls', data.subCalls);
insertCallInfo(functionNr, 'called_from_table_', 'Called From', data.calledFrom);
callInfoLoaded[functionNr] = true;
window.location.hash = "#callinfo_a_"+functionNr;
}
);
}
function insertCallInfo(functionNr, idPrefix, title, data) {
if (data.length==0)
return;
$("#callinfo_area_"+functionNr).append(callTable(functionNr,idPrefix, title));
for(i=0;i<data.length;i++){
$("#"+idPrefix+functionNr+" tbody").append(callTableRow(i, data[i]));
}
$("#"+idPrefix+functionNr).tablesorter({
widgets: ['zebra'],
headers: {
3: {
sorter: false
}
}
});
$("#"+idPrefix+functionNr).bind("sortStart",sortBlock).bind("sortEnd",$.unblockUI);
$("#"+idPrefix+functionNr).trigger("sorton",[[[2,1]]]);
}
function callTable(functionNr, idPrefix, title) {
return '<table class="tablesorter" id="'+idPrefix+functionNr+'" cellspacing="0"> \
<thead><tr><th><span>'+title+'</span></th><th><span>Count</span></th><th><span>Total Call Cost</span></th><th> </th></tr></thead> \
<tbody> \
</tbody> \
</table> \
';
}
function callTableRow(nr, data) {
return '<tr> \
<td>'
+($("#callinfo_area_"+data.functionNr).length ? '<img src="img/right.gif"> <a href="javascript:openCallInfo('+data.functionNr+')">'+data.callerFunctionName+'</a>' : '<img src="img/blank.gif"> '+data.callerFunctionName)
+ ' @ '+data.line+'</td> \
<td class="nr">'+data.callCount+'</td> \
<td class="nr">'+data.summedCallCost+'</td> \
<td><a title="Open file and show line" href="'+sprintf(fileUrlFormat,data.file,data.line)+'" target="_blank"><img src="img/file_line.png" alt="O"></a></td> \
</tr>';
}
function toggleCallInfo(functionNr) {
var $ciar = $("#callinfo_area_"+functionNr);
var fmimg = $("#fold_marker_"+functionNr).get(0);
var current = $("#fold_marker_"+functionNr).get(0).src;
if ($ciar.is(":visible")) {
$ciar.hide();
fmimg.src = 'img/right.gif';
} else {
if (!callInfoLoaded[functionNr]) {
loadCallInfo(functionNr);
} else {
window.location.hash = "#callinfo_a_"+functionNr;
}
$ciar.show();
fmimg.src = 'img/down.gif';
}
}
function openCallInfo(functionNr) {
var areaEl = $("#callinfo_area_"+functionNr);
if (areaEl.length) {
if (areaEl.is(":hidden")) {
toggleCallInfo(functionNr);
} else {
window.location.hash = "#callinfo_a_"+functionNr;
}
window.scrollTo(0, areaEl.parent().offset().top);
setTimeout(function(){areaEl.parent().parent().css({'background-color' : '#DFECE0'})}, 50);
setTimeout(function(){areaEl.parent().parent().css({'background-color' : ''})}, 600);
}
}
function functionTableRow(data, linkToFunctionLine) {
if (data.file=='php%3Ainternal') {
openLink = '<a title="Lookup function" href="http://php.net/'+data.functionName.substr(5).replace("->",".")+'" target="_blank"><img src="img/file.png" alt="O"></a>';
} else {
if (linkToFunctionLine) {
openLink = '<a title="Open file and show line" href="'+sprintf(fileUrlFormat, data.file, data.line)+'" target="_blank"><img src="img/file_line.png" alt="O"></a>';
} else {
openLink = '<a title="Open file" href="'+sprintf(fileUrlFormat, data.file, -1)+'" target="_blank"><img src="img/file.png" alt="O"></a>';
}
}
return '<tr> \
<td> \
<img src="img/call_'+data.humanKind+'.png" title="'+data.humanKind+'"> \
</td> \
<td> \
<a id="callinfo_a_'+data.nr+'" href="javascript:toggleCallInfo('+data.nr+')"> \
<img id="fold_marker_'+data.nr+'" src="img/right.gif"> '+data.functionName+' \
</a> \
<div class="callinfo_area" id="callinfo_area_'+data.nr+'"></div> \
</td> \
<td>'+openLink+'</td> \
<?php
$dataCodes = array(
'Invocation Count' => 'data.invocationCount',
'Total Self Cost' => 'data.summedSelfCost',
'Average Self Cost' => 'sprintf("%.2f", data.summedSelfCost/data.invocationCount)',
'Total Inclusive Cost' => 'data.summedInclusiveCost',
'Average Inclusive Cost' => 'sprintf("%.2f", data.summedInclusiveCost/data.invocationCount)',
);
foreach (Webgrind_Config::$tableFields as $field) {
echo "<td class=\"nr\">'+$dataCodes[$field]+'</td> \\\n\t\t\t\t\t\t";
}
?>
</tr> \
';
}
function sortBlock() {
$.blockUI('<div class="block_box"><h1>Sorting...</h1></div>');
document.cookie = "webgrind=" + this.config.sortList[0][0];
}
function loadBlock() {
if (!disableAjaxBlock)
$.blockUI();
disableAjaxBlock = false;
}
function checkVersion() {
disableAjaxBlock = true;
$.getJSON("index.php",
{'op':'version_info'},
function(data) {
if (isNewer('<?php echo Webgrind_Config::$webgrindVersion?>', data.latest_version)) {
$("#version_info").append('Version '+data.latest_version+' is available for <a href="'+data.download_url+'">download</a>.');
} else {
$("#version_info").append('You have the latest version.');
}
}
);
}
function parseVersion(version) {
return (version + '.0.0' ).split('.').slice(0, 3).map(x => parseInt(x, 10));
}
function isNewer(oldV, newV) {
var oldP = parseVersion(oldV);
var newP = parseVersion(newV);
for (var i = 0; i < 3; ++i) {
if (newP[i] !== oldP[i]) {
return newP[i] > oldP[i];
}
}
return false;
}
function clearFiles() {
$.getJSON("index.php",
{'op':'clear_files'},
function(data) {
if (data.error) {
$("#hello_message").html(data.error);
$("#hello_message").show();
return;
}
reloadFilelist();
}
);
}
$(document).ready(function() {
$.blockUI.defaults.pageMessage = '<div class="block_box"><h1>Loading...</h1><p>Loading information from server. If the callgrind file is large this may take some time.</p></div>';
$.blockUI.defaults.overlayCSS = { backgroundColor: '#fff', opacity: '0' };
$.blockUI.defaults.fadeIn = 0;
$.blockUI.defaults.fadeOut = 0;
$().ajaxStart(loadBlock).ajaxStop($.unblockUI);
$("#function_table").tablesorter({
widgets: ['zebra'],
sortInitialOrder: 'desc',
headers: {
1: {
sorter: false
},
2: {
sorter: false
}
}
});
$("#function_table").bind("sortStart",sortBlock).bind("sortEnd",$.unblockUI);
if (document.location.hash) {
update();
}
<?php if(Webgrind_Config::$checkVersion):?>
setTimeout(checkVersion,100);
<?php endif?>
$("#negateFilter").change(function(){
$('#callfilter').trigger('keyup');
});
$("#callfilter").keyup(function(){
var reg = new RegExp($(this).val(), 'i');
var negate = $("#negateFilter").is(':checked');
var row;
$('#function_table').children('tbody').children('tr').each(function(){
row = $(this);
if (!row.find('td:eq(1) a').text().match(reg) == negate)
row.css('display', 'table-row');
else
row.css('display', 'none');
});
});
if (typeof window.addEventListener == "function") {
window.addEventListener("hashchange", function(e) {
if (window.location.hash.length > 2)
openCallInfo(window.location.hash.replace(/[^0-9]/g, ''));
});
}
});
</script>
</head>
<body>
<div id="head">
<div id="logo">
<h1>webgrind<sup style="font-size:10px">v<?php echo Webgrind_Config::$webgrindVersion?></sup></h1>
<p>profiling in the browser</p>
</div>
<div id="options">
<form method="get" onsubmit="window.location.hash='';update();return false;">
<div style="float:right;margin-left:10px">
<input type="submit" value="update">
</div>
<div style="float:right;">
<label style="margin:0 5px">in</label>
<select id="costFormat" name="costFormat">
<option value="percent" <?php echo (Webgrind_Config::$defaultCostformat=='percent') ? 'selected' : ''?>>percent</option>
<option value="msec" <?php echo (Webgrind_Config::$defaultCostformat=='msec') ? 'selected' : ''?>>milliseconds</option>
<option value="usec" <?php echo (Webgrind_Config::$defaultCostformat=='usec') ? 'selected' : ''?>>microseconds</option>
</select>
</div>
<div style="float:right;">
<label style="margin:0 5px">of</label>
<select id="dataFile" name="dataFile" style="width:200px">
<option value="0">Auto (newest)</option>
<?php foreach(Webgrind_FileHandler::getInstance()->getTraceList() as $trace):?>
<!-- <option value="<?php echo $trace['filename']?>"><?php echo $trace['invokeUrl']?> (<?php echo $trace['filename']?>) [<?php echo $trace['filesize']?>]</option> -->
<option value="<?php echo $trace['filename']?>"><?php echo str_replace(array('%i','%f','%s','%m'),array($trace['invokeUrl'],$trace['filename'],$trace['filesize'],$trace['mtime']),Webgrind_Config::$traceFileListFormat); ?></option>
<?php endforeach;?>
</select>
<img class="list_reload" src="img/reload.png" onclick="reloadFilelist()">
</div>
<div style="float:right">
<label style="margin:0 5px">Show</label>
<select id="showFraction" name="showFraction">
<?php foreach(array(100, 99.7, 98, 95, 90, 82, 68, 50, 26) as $i):?>
<option value="<?php echo $i/100?>" <?php if ($i==Webgrind_Config::$defaultFunctionPercentage):?>selected="selected"<?php endif;?>><?php echo $i?>%</option>
<?php endforeach;?>
</select>
</div>
<div style="clear:both;"></div>
<div style="margin:0 70px">
<input type="checkbox" name="hideInternals" value="1" <?php echo (Webgrind_Config::$defaultHideInternalFunctions==1) ? 'checked' : ''?> id="hideInternals">
<label for="hideInternals">Hide PHP functions</label>
</div>
</form>
</div>
<div style="clear:both;"></div>
</div>
<div id="main">
<div id="trace_view">
<div style="float:left;">
<h2 id="invoke_url"></h2>
<a id="download_link" onclick="downloadFile()">
<span id="data_file"></span> @ <span id="mtime"></span>
</a>
</div>
<div style="float:right;">
<div id="breakdown" style="margin-bottom:5px;width:320px;height:20px"></div>
<span id="invocation_sum"></span> different functions called in <span id="runtime_sum"></span> milliseconds (<span id="runs"></span> runs, <span id="shown_sum"></span> shown)
<div><input type="button" name="graph" value="Show Call Graph" onclick="showCallGraph()"></div>
</div>
<div style="clear:both"></div>
Filter: <input type="text" style="width:150px" id="callfilter"> (regex too)
<input type="checkbox" name="negateFilter" value="0" id="negateFilter">
<label for="negateFilter">Invert filter</label>
<table class="tablesorter" id="function_table" cellspacing="0">
<thead>
<tr>
<th> </th>
<th><span>Function</span></th>
<th> </th>
<?php foreach(Webgrind_Config::$tableFields as $field):?>
<th><span><?php echo $field?></span></th>
<?php endforeach;?>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<h2 id="hello_message"><?php echo $welcome?></h2>
<div id="footer">
<input type="button" value="clear files" onclick="clearFiles()"><br><br>
<?php if(Webgrind_Config::$checkVersion):?>
<div id="version_info"> </div>
<?php endif?>
Copyright © 2008-2011 Jacob Oettinger & Joakim Nygård. <a href="http://github.com/jokkedk/webgrind/">webgrind homepage</a>
</div>
</div>
</body>
</html>