@@ -428,10 +428,29 @@ if (typeof(PhpDebugBar) == 'undefined') {
428
428
429
429
render : function ( ) {
430
430
this . bindAttr ( 'data' , function ( data ) {
431
+
432
+ // ported from php DataFormatter
433
+ var formatDuration = function ( seconds ) {
434
+ if ( seconds < 0.001 )
435
+ return ( seconds * 1000000 ) . toFixed ( ) + 'μs' ;
436
+ else if ( seconds < 1 )
437
+ return ( seconds * 1000 ) . toFixed ( 2 ) + 'ms' ;
438
+ return ( seconds ) . toFixed ( 2 ) + 's' ;
439
+ } ;
440
+
431
441
this . $el . empty ( ) ;
432
442
if ( data . measures ) {
443
+ var aggregate = { } ;
444
+
433
445
for ( var i = 0 ; i < data . measures . length ; i ++ ) {
434
446
var measure = data . measures [ i ] ;
447
+
448
+ if ( ! aggregate [ measure . label ] )
449
+ aggregate [ measure . label ] = { count : 0 , duration : 0 } ;
450
+
451
+ aggregate [ measure . label ] [ 'count' ] += 1 ;
452
+ aggregate [ measure . label ] [ 'duration' ] += measure . duration ;
453
+
435
454
var m = $ ( '<div />' ) . addClass ( csscls ( 'measure' ) ) ,
436
455
li = $ ( '<li />' ) ,
437
456
left = ( measure . relative_start * 100 / data . duration ) . toFixed ( 2 ) ,
@@ -468,6 +487,30 @@ if (typeof(PhpDebugBar) == 'undefined') {
468
487
} ) ;
469
488
}
470
489
}
490
+
491
+ // convert to array and sort by duration
492
+ aggregate = $ . map ( aggregate , function ( data , label ) {
493
+ return {
494
+ label : label ,
495
+ data : data
496
+ }
497
+ } ) . sort ( function ( a , b ) {
498
+ return b . data . duration - a . data . duration
499
+ } ) ;
500
+
501
+ // build table and add
502
+ var aggregateTable = $ ( '<table style="display: table; border: 0; width: 99%"></table>' ) . addClass ( csscls ( 'params' ) ) ;
503
+ $ . each ( aggregate , function ( i , aggregate ) {
504
+ width = Math . min ( ( aggregate . data . duration * 100 / data . duration ) . toFixed ( 2 ) , 100 ) ;
505
+
506
+ aggregateTable . append ( '<tr><td class="' + csscls ( 'name' ) + '">' + aggregate . data . count + ' x ' + aggregate . label + ' (' + width + '%)</td><td class="' + csscls ( 'value' ) + '">' +
507
+ '<div class="' + csscls ( 'measure' ) + '">' +
508
+ '<span class="' + csscls ( 'value' ) + '" style="width:' + width + '%"></span>' +
509
+ '<span class="' + csscls ( 'label' ) + '">' + formatDuration ( aggregate . data . duration ) + '</span>' +
510
+ '</div></td></tr>' ) ;
511
+ } ) ;
512
+
513
+ this . $el . append ( '<li/>' ) . find ( 'li:last' ) . append ( aggregateTable ) ;
471
514
}
472
515
} ) ;
473
516
}
0 commit comments