@@ -27,6 +27,7 @@ import handleExternalResources from './external-resources';
2727import { loadDependencies , NPMDependencies } from './npm' ;
2828import { resetScreen } from './status-screen' ;
2929import { showRunOnClick } from './status-screen/run-on-click' ;
30+ import * as metrics from './utils/metrics' ;
3031
3132let initializedResizeListener = false ;
3233let manager : Manager | null = null ;
@@ -78,6 +79,7 @@ let lastHeadHTML = null;
7879let lastBodyHTML = null ;
7980let lastHeight = 0 ;
8081let changedModuleCount = 0 ;
82+ let usedCache = false ;
8183
8284const DEPENDENCY_ALIASES = {
8385 '@vue/cli-plugin-babel' : '@vue/babel-preset-app' ,
@@ -419,6 +421,7 @@ async function compile({
419421 dispatch ( {
420422 type : 'start' ,
421423 } ) ;
424+ metrics . measure ( 'compilation' ) ;
422425
423426 const startTime = Date . now ( ) ;
424427 try {
@@ -513,10 +516,10 @@ async function compile({
513516 manager . setManifest ( manifest ) ;
514517 // We save the state of transpiled modules, and load it here again. Gives
515518 // faster initial loads.
516- await consumeCache ( manager ) ;
519+ usedCache = await consumeCache ( manager ) ;
517520 }
518521
519- const t = Date . now ( ) ;
522+ metrics . measure ( 'transpilation' ) ;
520523
521524 const updatedModules = ( await updateManager ( modules , configurations ) ) || [ ] ;
522525
@@ -541,7 +544,7 @@ async function compile({
541544 await manager . verifyTreeTranspiled ( ) ;
542545 await manager . transpileModules ( managerModuleToTranspile ) ;
543546
544- debug ( `Transpilation time ${ Date . now ( ) - t } ms` ) ;
547+ metrics . endMeasure ( 'transpilation' , 'Transpilation' ) ;
545548
546549 dispatch ( { type : 'status' , status : 'evaluating' } ) ;
547550 manager . setStage ( 'evaluation' ) ;
@@ -604,16 +607,17 @@ async function compile({
604607 lastHeadHTML = head ;
605608 }
606609
607- const extDate = Date . now ( ) ;
610+ metrics . measure ( 'external-resources' ) ;
608611 await handleExternalResources ( externalResources ) ;
609- debug ( 'Loaded external resources in ' + ( Date . now ( ) - extDate ) + 'ms ') ;
612+ metrics . endMeasure ( ' external- resources' , 'External Resources ') ;
610613
611- const tt = Date . now ( ) ;
612614 const oldHTML = document . body . innerHTML ;
615+ metrics . measure ( 'evaluation' ) ;
613616 const evalled = manager . evaluateModule ( managerModuleToTranspile , {
614617 force : isModuleView ,
615618 } ) ;
616- debug ( `Evaluation time: ${ Date . now ( ) - tt } ms` ) ;
619+ metrics . endMeasure ( 'evaluation' , 'Evaluation' ) ;
620+
617621 const domChanged =
618622 ! manager . preset . htmlDisabled && oldHTML !== document . body . innerHTML ;
619623
@@ -662,6 +666,8 @@ async function compile({
662666
663667 debug ( `Total time: ${ Date . now ( ) - startTime } ms` ) ;
664668
669+ metrics . endMeasure ( 'compilation' , 'Compilation' ) ;
670+ metrics . endMeasure ( 'total' , 'Total' , { lastTime : 0 } ) ;
665671 dispatch ( {
666672 type : 'success' ,
667673 } ) ;
@@ -731,6 +737,14 @@ async function compile({
731737 state : managerState ,
732738 } ) ;
733739 }
740+
741+ if ( firstLoad ) {
742+ metrics . persistMeasurements ( {
743+ sandboxId,
744+ usedCache,
745+ browser : navigator . userAgent ,
746+ } ) ;
747+ }
734748 }
735749 firstLoad = false ;
736750
0 commit comments