@@ -239,6 +239,8 @@ const fileLoader = (function() {
239
239
class Driver {
240
240
constructor ( ) {
241
241
this . isReady = false ;
242
+ this . isDone = false ;
243
+ this . errors = [ ] ;
242
244
this . benchmarks = [ ] ;
243
245
this . blobDataCache = { } ;
244
246
this . loadCache = { } ;
@@ -274,11 +276,12 @@ class Driver {
274
276
try {
275
277
await benchmark . run ( ) ;
276
278
} catch ( e ) {
277
- JetStream . reportError ( benchmark ) ;
279
+ this . reportError ( benchmark , e ) ;
278
280
throw e ;
279
281
}
280
282
281
283
benchmark . updateUIAfterRun ( ) ;
284
+ console . log ( benchmark . name )
282
285
283
286
if ( isInBrowser ) {
284
287
const cache = JetStream . blobDataCache ;
@@ -334,6 +337,8 @@ class Driver {
334
337
335
338
this . reportScoreToRunBenchmarkRunner ( ) ;
336
339
this . dumpJSONResultsIfNeeded ( ) ;
340
+ this . isDone = true ;
341
+
337
342
if ( isInBrowser ) {
338
343
globalThis . dispatchEvent ( new CustomEvent ( "JetStreamDone" , {
339
344
detail : this . resultsObject ( )
@@ -438,16 +443,32 @@ class Driver {
438
443
} ) ;
439
444
}
440
445
441
- reportError ( benchmark )
446
+ reportError ( benchmark , error )
442
447
{
448
+ this . pushError ( benchmark . name , error ) ;
449
+
443
450
if ( ! isInBrowser )
444
451
return ;
445
452
446
- for ( const id of benchmark . scoreIdentifiers ( ) )
453
+ for ( const id of benchmark . scoreIdentifiers ( ) ) {
447
454
document . getElementById ( id ) . innerHTML = "error" ;
455
+ const benchmarkResultsUI = document . getElementById ( `benchmark-${ benchmark . name } ` ) ;
456
+ benchmarkResultsUI . classList . remove ( "benchmark-running" ) ;
457
+ benchmarkResultsUI . classList . add ( "benchmark-error" ) ;
458
+ }
459
+ }
460
+
461
+ pushError ( name , error ) {
462
+ this . errors . push ( {
463
+ benchmark : name ,
464
+ error : error . toString ( ) ,
465
+ stack : error . stack
466
+ } ) ;
448
467
}
449
468
450
469
async initialize ( ) {
470
+ if ( isInBrowser )
471
+ window . addEventListener ( "error" , ( e ) => this . pushError ( "driver startup" , e . error ) ) ;
451
472
await this . prefetchResourcesForBrowser ( ) ;
452
473
await this . fetchResources ( ) ;
453
474
this . prepareToRun ( ) ;
@@ -508,7 +529,18 @@ class Driver {
508
529
}
509
530
}
510
531
511
- resultsObject ( )
532
+ resultsObject ( format = "run-benchmark" ) {
533
+ switch ( format ) {
534
+ case "run-benchmark" :
535
+ return this . runBenchmarkResultsObject ( ) ;
536
+ case "simple" :
537
+ return this . simpleResultsObject ( ) ;
538
+ default :
539
+ throw Error ( `Unknown result format '${ format } '` ) ;
540
+ }
541
+ }
542
+
543
+ runBenchmarkResultsObject ( )
512
544
{
513
545
let results = { } ;
514
546
for ( const benchmark of this . benchmarks ) {
@@ -528,12 +560,29 @@ class Driver {
528
560
529
561
results = { "JetStream3.0" : { "metrics" : { "Score" : [ "Geometric" ] } , "tests" : results } } ;
530
562
return results ;
563
+ }
531
564
565
+ simpleResultsObject ( ) {
566
+ const results = { __proto__ : null } ;
567
+ for ( const benchmark of this . benchmarks ) {
568
+ if ( ! benchmark . isDone )
569
+ continue ;
570
+ if ( ! benchmark . isSuccess ) {
571
+ results [ benchmark . name ] = "FAILED" ;
572
+ } else {
573
+ results [ benchmark . name ] = {
574
+ Score : benchmark . score ,
575
+ ...benchmark . subScores ( ) ,
576
+
577
+ } ;
578
+ }
579
+ }
580
+ return results ;
532
581
}
533
582
534
- resultsJSON ( )
583
+ resultsJSON ( format = "run-benchmark" )
535
584
{
536
- return JSON . stringify ( this . resultsObject ( ) ) ;
585
+ return JSON . stringify ( this . resultsObject ( format ) ) ;
537
586
}
538
587
539
588
dumpJSONResultsIfNeeded ( )
@@ -566,6 +615,15 @@ class Driver {
566
615
}
567
616
} ;
568
617
618
+ const BenchmarkState = Object . freeze ( {
619
+ READY : "READY" ,
620
+ SETUP : "SETUP" ,
621
+ RUNNING : "RUNNING" ,
622
+ FINALIZE : "FINALIZE" ,
623
+ ERROR : "ERROR" ,
624
+ DONE : "DONE"
625
+ } )
626
+
569
627
class Benchmark {
570
628
constructor ( plan )
571
629
{
@@ -575,10 +633,16 @@ class Benchmark {
575
633
this . isAsync = ! ! plan . isAsync ;
576
634
this . scripts = null ;
577
635
this . _resourcesPromise = null ;
636
+ this . _state = BenchmarkState . READY ;
578
637
}
579
638
580
639
get name ( ) { return this . plan . name ; }
581
640
641
+ get isDone ( ) {
642
+ return this . _state == BenchmarkState . DONE || this . _state == BenchmarkState . ERROR ;
643
+ }
644
+ get isSuccess ( ) { return this . _state = BenchmarkState . DONE ; }
645
+
582
646
get runnerCode ( ) {
583
647
return `
584
648
let __benchmark = new Benchmark(${ this . iterations } );
@@ -640,6 +704,9 @@ class Benchmark {
640
704
}
641
705
642
706
async run ( ) {
707
+ if ( this . isDone )
708
+ throw new Error ( `Cannot run Benchmark ${ this . name } twice` ) ;
709
+ this . _state = BenchmarkState . PREPARE ;
643
710
let code ;
644
711
if ( isInBrowser )
645
712
code = "" ;
@@ -748,11 +815,15 @@ class Benchmark {
748
815
749
816
let magicFrame ;
750
817
try {
818
+ this . _state = BenchmarkState . RUNNING ;
751
819
magicFrame = JetStream . runCode ( code ) ;
752
820
} catch ( e ) {
821
+ this . _state = BenchmarkState . ERROR ;
753
822
console . log ( "Error in runCode: " , e ) ;
754
823
console . log ( e . stack )
755
824
throw e ;
825
+ } finally {
826
+ this . _state = BenchmarkState . FINALIZE ;
756
827
}
757
828
const results = await promise ;
758
829
@@ -765,6 +836,8 @@ class Benchmark {
765
836
}
766
837
767
838
this . processResults ( results ) ;
839
+ this . _state = BenchmarkState . DONE ;
840
+
768
841
if ( isInBrowser )
769
842
magicFrame . contentDocument . close ( ) ;
770
843
else if ( isD8 )
0 commit comments