1
1
import uPlot , { TypedArray } from "uplot" ;
2
- import { GraphData , GraphsSelector } from "./data" ;
2
+ import { CompileGraphData , GraphsSelector , RuntimeGraphData } from "./data" ;
3
3
4
4
const commonCacheStateColors = {
5
5
full : "#7cb5ec" ,
@@ -374,7 +374,7 @@ function genPlotOpts({
374
374
} ;
375
375
}
376
376
377
- function normalizeData ( data : GraphData ) {
377
+ function normalizeData ( data : CompileGraphData ) {
378
378
function optInterpolated ( profile ) {
379
379
for ( const scenario in profile ) {
380
380
profile [ scenario ] . interpolated_indices = new Set (
@@ -409,7 +409,7 @@ export type GraphRenderOpts = {
409
409
// Renders the plots data with the given parameters from the `selector` into
410
410
// the passed DOM element.
411
411
export function renderPlots (
412
- data : GraphData ,
412
+ data : CompileGraphData ,
413
413
selector : GraphsSelector ,
414
414
plotElement : HTMLElement ,
415
415
opts : GraphRenderOpts
@@ -420,41 +420,50 @@ export function renderPlots(
420
420
421
421
normalizeData ( data ) ;
422
422
423
- const names = Object . keys ( data . benchmarks ) . sort ( ) ;
423
+ const benchNames = Object . keys ( data . benchmarks ) . sort ( ) ;
424
424
425
- for ( const benchName of names ) {
426
- let benchKinds = data . benchmarks [ benchName ] ;
425
+ for ( const benchName of benchNames ) {
426
+ let profiles = data . benchmarks [ benchName ] ;
427
427
428
428
let i = 0 ;
429
429
430
- for ( let benchKind in benchKinds ) {
431
- let cacheStates = benchKinds [ benchKind ] ;
432
- let cacheStateNames = Object . keys ( cacheStates ) ;
433
- cacheStateNames . sort ( ) ;
430
+ for ( let profile in profiles ) {
431
+ let scenarios = profiles [ profile ] ;
432
+ let scenarioNames = Object . keys ( scenarios ) ;
433
+ scenarioNames . sort ( ) ;
434
434
435
435
let yAxis = selector . stat ;
436
436
let yAxisUnit = null ;
437
- if ( selector . stat == "instructions:u" ) {
438
- yAxis = "CPU instructions" ;
439
- yAxisUnit = "count" ;
440
- } else if ( selector . stat == "cycles:u" ) {
441
- yAxis = "CPU cycles" ;
442
- yAxisUnit = "count" ;
443
- } else if ( selector . stat == "cpu-clock" ) {
444
- yAxis = "CPU clock" ;
445
- yAxisUnit = "seconds" ;
446
- } else if ( selector . stat == "task-clock" ) {
447
- yAxis = "Task clock" ;
448
- yAxisUnit = "seconds" ;
449
- } else if ( selector . stat == "wall-time" ) {
450
- yAxis = "Wall time" ;
451
- yAxisUnit = "seconds" ;
452
- } else if ( selector . stat == "max-rss" ) {
453
- yAxis = "Maximum resident set size" ;
454
- yAxisUnit = "kB" ;
455
- } else if ( selector . stat == "faults" ) {
456
- yAxis = "Faults" ;
457
- yAxisUnit = "count" ;
437
+
438
+ switch ( selector . stat ) {
439
+ case "instructions:u" :
440
+ yAxis = "CPU instructions" ;
441
+ yAxisUnit = "count" ;
442
+ break ;
443
+ case "cycles:u" :
444
+ yAxis = "CPU cycles" ;
445
+ yAxisUnit = "count" ;
446
+ break ;
447
+ case "cpu-clock" :
448
+ yAxis = "CPU clock" ;
449
+ yAxisUnit = "seconds" ;
450
+ break ;
451
+ case "task-clock" :
452
+ yAxis = "Task clock" ;
453
+ yAxisUnit = "seconds" ;
454
+ break ;
455
+ case "wall-time" :
456
+ yAxis = "Wall time" ;
457
+ yAxisUnit = "seconds" ;
458
+ break ;
459
+ case "max-rss" :
460
+ yAxis = "Maximum resident set size" ;
461
+ yAxisUnit = "kB" ;
462
+ break ;
463
+ case "faults" :
464
+ yAxis = "Faults" ;
465
+ yAxisUnit = "count" ;
466
+ break ;
458
467
}
459
468
460
469
if ( selector . kind == "raw" && benchName == "Summary" ) {
@@ -476,23 +485,22 @@ export function renderPlots(
476
485
477
486
let otherColorIdx = 0 ;
478
487
479
- for ( let cacheState of cacheStateNames ) {
480
- let yVals = cacheStates [ cacheState ] . points ;
488
+ for ( let scenarioName of scenarioNames ) {
489
+ let yVals = scenarios [ scenarioName ] . points ;
481
490
let color =
482
- commonCacheStateColors [ cacheState ] ||
491
+ commonCacheStateColors [ scenarioName ] ||
483
492
otherCacheStateColors [ otherColorIdx ++ ] ;
484
493
485
494
plotData . push ( yVals ) ;
486
495
487
496
seriesOpts . push ( {
488
- label : cacheState ,
497
+ label : scenarioName ,
489
498
width : devicePixelRatio ,
490
499
stroke : color ,
491
500
} ) ;
492
501
}
493
502
494
- let indices =
495
- cacheStates [ Object . keys ( cacheStates ) [ 0 ] ] . interpolated_indices ;
503
+ let indices = scenarios [ Object . keys ( scenarios ) [ 0 ] ] . interpolated_indices ;
496
504
497
505
let plotOpts = genPlotOpts ( {
498
506
width,
@@ -501,14 +509,14 @@ export function renderPlots(
501
509
series : seriesOpts ,
502
510
commits : data . commits ,
503
511
stat : selector . stat ,
504
- isInterpolated ( dataIdx ) {
512
+ isInterpolated ( dataIdx : number ) {
505
513
return indices . has ( dataIdx ) ;
506
514
} ,
507
515
absoluteMode : selector . kind == "raw" ,
508
516
hooks,
509
517
} ) ;
510
518
if ( renderTitle ) {
511
- plotOpts [ "title" ] = `${ benchName } -${ benchKind } ` ;
519
+ plotOpts [ "title" ] = `${ benchName } -${ profile } ` ;
512
520
}
513
521
514
522
new uPlot ( plotOpts , plotData as any as TypedArray [ ] , plotElement ) ;
@@ -517,3 +525,108 @@ export function renderPlots(
517
525
}
518
526
}
519
527
}
528
+
529
+ export function renderRuntimePlots (
530
+ data : RuntimeGraphData ,
531
+ selector : GraphsSelector ,
532
+ plotElement : HTMLElement ,
533
+ opts : GraphRenderOpts
534
+ ) {
535
+ const renderTitle = opts . renderTitle ?? true ;
536
+ const hooks = opts . hooks ?? { } ;
537
+ const width = opts . width ;
538
+
539
+ const benchNames = Object . keys ( data . benchmarks ) . sort ( ) ;
540
+
541
+ for ( const benchName of benchNames ) {
542
+ const benchmark = data . benchmarks [ benchName ] ;
543
+ let i = 0 ;
544
+
545
+ let yAxis = selector . stat ;
546
+ let yAxisUnit = null ;
547
+
548
+ switch ( selector . stat ) {
549
+ case "instructions:u" :
550
+ yAxis = "CPU instructions" ;
551
+ yAxisUnit = "count" ;
552
+ break ;
553
+ case "cycles:u" :
554
+ yAxis = "CPU cycles" ;
555
+ yAxisUnit = "count" ;
556
+ break ;
557
+ case "cpu-clock" :
558
+ yAxis = "CPU clock" ;
559
+ yAxisUnit = "seconds" ;
560
+ break ;
561
+ case "task-clock" :
562
+ yAxis = "Task clock" ;
563
+ yAxisUnit = "seconds" ;
564
+ break ;
565
+ case "wall-time" :
566
+ yAxis = "Wall time" ;
567
+ yAxisUnit = "seconds" ;
568
+ break ;
569
+ case "max-rss" :
570
+ yAxis = "Maximum resident set size" ;
571
+ yAxisUnit = "kB" ;
572
+ break ;
573
+ case "faults" :
574
+ yAxis = "Faults" ;
575
+ yAxisUnit = "count" ;
576
+ break ;
577
+ }
578
+
579
+ if ( selector . kind == "raw" && benchName == "Summary" ) {
580
+ yAxisUnit = "relative" ;
581
+ } else if ( selector . kind == "percentfromfirst" ) {
582
+ yAxisUnit = "% change from first" ;
583
+ } else if ( selector . kind == "percentrelative" ) {
584
+ yAxisUnit = "% change from previous" ;
585
+ }
586
+
587
+ yAxis = yAxisUnit ? `${ yAxis } (${ yAxisUnit } )` : yAxis ;
588
+ let yAxisLabel = i == 0 ? yAxis : null ;
589
+
590
+ let seriesOpts = [ { } ] ;
591
+
592
+ let xVals = data . commits . map ( ( c ) => c [ 0 ] ) ;
593
+
594
+ let plotData = [ xVals ] ;
595
+
596
+ let otherColorIdx = 0 ;
597
+
598
+ let yVals = benchmark . points ;
599
+ let color = otherCacheStateColors [ otherColorIdx ++ ] ;
600
+
601
+ plotData . push ( yVals ) ;
602
+
603
+ seriesOpts . push ( {
604
+ label : benchName ,
605
+ width : devicePixelRatio ,
606
+ stroke : color ,
607
+ } ) ;
608
+
609
+ let indices = new Set ( benchmark . interpolated_indices ) ;
610
+
611
+ let plotOpts = genPlotOpts ( {
612
+ width,
613
+ height : 300 ,
614
+ yAxisLabel,
615
+ series : seriesOpts ,
616
+ commits : data . commits ,
617
+ stat : selector . stat ,
618
+ isInterpolated ( dataIdx : number ) {
619
+ return indices . has ( dataIdx ) ;
620
+ } ,
621
+ absoluteMode : selector . kind == "raw" ,
622
+ hooks,
623
+ } ) ;
624
+ if ( renderTitle ) {
625
+ plotOpts [ "title" ] = `${ benchName } ` ;
626
+ }
627
+
628
+ new uPlot ( plotOpts , plotData as any as TypedArray [ ] , plotElement ) ;
629
+
630
+ i ++ ;
631
+ }
632
+ }
0 commit comments