@@ -375,7 +375,10 @@ exports.main = function main(argv, options, callback) {
375375 let transform = transforms [ i ] ;
376376 if ( typeof transform [ name ] === "function" ) {
377377 try {
378- transform [ name ] ( ...args ) ;
378+ stats . transformCount ++ ;
379+ stats . transfromTime += measure ( ( ) => {
380+ transform [ name ] ( ...args ) ;
381+ } ) ;
379382 } catch ( e ) {
380383 return e ;
381384 }
@@ -605,29 +608,11 @@ exports.main = function main(argv, options, callback) {
605608 return callback ( null ) ;
606609 }
607610
608- // Set up optimization levels
609- var optimizeLevel = 0 ;
610- var shrinkLevel = 0 ;
611- if ( args . optimize ) {
612- optimizeLevel = exports . defaultOptimizeLevel ;
613- shrinkLevel = exports . defaultShrinkLevel ;
614- }
615- if ( typeof args . optimizeLevel === "number" ) {
616- optimizeLevel = args . optimizeLevel ;
617- }
618- if ( typeof args . shrinkLevel === "number" ) {
619- shrinkLevel = args . shrinkLevel ;
620- }
621- optimizeLevel = Math . min ( Math . max ( optimizeLevel , 0 ) , 3 ) ;
622- shrinkLevel = Math . min ( Math . max ( shrinkLevel , 0 ) , 2 ) ;
623-
624- try {
625- stats . compileTime += measure ( ( ) => {
626- assemblyscript . initializeProgram ( program , compilerOptions ) ;
627- } ) ;
628- } catch ( e ) {
629- return callback ( e ) ;
630- }
611+ // Pre-emptively initialize the program
612+ stats . initializeCount ++ ;
613+ stats . initializeTime += measure ( ( ) => {
614+ assemblyscript . initializeProgram ( program ) ;
615+ } ) ;
631616
632617 // Call afterInitialize transform hook
633618 {
@@ -637,13 +622,9 @@ exports.main = function main(argv, options, callback) {
637622
638623 var module ;
639624 stats . compileCount ++ ;
640- try {
641- stats . compileTime += measure ( ( ) => {
642- module = assemblyscript . compile ( program ) ;
643- } ) ;
644- } catch ( e ) {
645- return callback ( e ) ;
646- }
625+ stats . compileTime += measure ( ( ) => {
626+ module = assemblyscript . compile ( program ) ;
627+ } ) ;
647628 var numErrors = checkDiagnostics ( program , stderr ) ;
648629 if ( numErrors ) {
649630 if ( module ) module . dispose ( ) ;
@@ -907,6 +888,7 @@ exports.main = function main(argv, options, callback) {
907888 function listFilesNode ( dirname , baseDir ) {
908889 var files ;
909890 try {
891+ stats . readCount ++ ;
910892 stats . readTime += measure ( ( ) => {
911893 files = fs . readdirSync ( path . join ( baseDir , dirname ) ) . filter ( file => extension . re_except_d . test ( file ) )
912894 } ) ;
@@ -958,14 +940,18 @@ function createStats() {
958940 writeCount : 0 ,
959941 parseTime : 0 ,
960942 parseCount : 0 ,
943+ initializeTime : 0 ,
944+ initializeCount : 0 ,
961945 compileTime : 0 ,
962946 compileCount : 0 ,
963947 emitTime : 0 ,
964948 emitCount : 0 ,
965949 validateTime : 0 ,
966950 validateCount : 0 ,
967951 optimizeTime : 0 ,
968- optimizeCount : 0
952+ optimizeCount : 0 ,
953+ transformTime : 0 ,
954+ transformCount : 0
969955 } ;
970956}
971957
@@ -983,26 +969,33 @@ function measure(fn) {
983969
984970exports . measure = measure ;
985971
972+ function pad ( str , len ) {
973+ while ( str . length < len ) str = " " + str ;
974+ return str ;
975+ }
976+
986977/** Formats a high resolution time to a human readable string. */
987978function formatTime ( time ) {
988- return time ? ( time / 1e6 ) . toFixed ( 3 ) + " ms" : "N/A " ;
979+ return time ? ( time / 1e6 ) . toFixed ( 3 ) + " ms" : "n/a " ;
989980}
990981
991982exports . formatTime = formatTime ;
992983
993984/** Formats and prints out the contents of a set of stats. */
994985function printStats ( stats , output ) {
995986 function format ( time , count ) {
996- return formatTime ( time ) ;
987+ return pad ( formatTime ( time ) , 12 ) + " n=" + count ;
997988 }
998989 ( output || process . stdout ) . write ( [
999- "I/O Read : " + format ( stats . readTime , stats . readCount ) ,
1000- "I/O Write : " + format ( stats . writeTime , stats . writeCount ) ,
1001- "Parse : " + format ( stats . parseTime , stats . parseCount ) ,
1002- "Compile : " + format ( stats . compileTime , stats . compileCount ) ,
1003- "Emit : " + format ( stats . emitTime , stats . emitCount ) ,
1004- "Validate : " + format ( stats . validateTime , stats . validateCount ) ,
1005- "Optimize : " + format ( stats . optimizeTime , stats . optimizeCount )
990+ "I/O Read : " + format ( stats . readTime , stats . readCount ) ,
991+ "I/O Write : " + format ( stats . writeTime , stats . writeCount ) ,
992+ "Parse : " + format ( stats . parseTime , stats . parseCount ) ,
993+ "Initialize : " + format ( stats . initializeTime , stats . initializeCount ) ,
994+ "Compile : " + format ( stats . compileTime , stats . compileCount ) ,
995+ "Emit : " + format ( stats . emitTime , stats . emitCount ) ,
996+ "Validate : " + format ( stats . validateTime , stats . validateCount ) ,
997+ "Optimize : " + format ( stats . optimizeTime , stats . optimizeCount ) ,
998+ "Transform : " + format ( stats . transformTime , stats . transformCount )
1006999 ] . join ( EOL ) + EOL ) ;
10071000}
10081001
0 commit comments