Skip to content

Commit

Permalink
Override indenting depth, see phetsims/chipper#1350
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 10, 2022
1 parent 24decc6 commit d08dca2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions js/common/phetTimingLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let depth = -1;

const indent = depth => ' '.repeat( depth );

const push = taskName => {
const push = ( taskName, options = null ) => {
assert( !taskName.includes( ':' ), 'task name cannot include :, it was ' + taskName );

depth++;
Expand All @@ -61,16 +61,16 @@ const push = taskName => {
const time = new Date().toLocaleString( 'en-US', { timeZone: 'America/Denver' } );
stream.write( `<!-- ${time} -->\n` );
}
stream.write( `${indent( depth )}<${taskName}>\n` );
stream.write( `${indent( options && options.hasOwnProperty( 'depth' ) ? options.depth : depth )}<${taskName}>\n` );

const startTime = Date.now();
return startTime;
};

const pop = ( taskName, startTime ) => {
const pop = ( taskName, startTime, options = null ) => {
const endTime = Date.now();

stream.write( `${indent( depth )}</${taskName}> <!-- ${endTime - startTime}ms -->\n` );
stream.write( `${indent( options && options.hasOwnProperty( 'depth' ) ? options.depth : depth )}</${taskName}> <!-- ${endTime - startTime}ms -->\n` );

if ( depth === 0 ) {
stream.write( '\n', () => {
Expand Down Expand Up @@ -108,10 +108,10 @@ const phetTimingLog = {
* @param {()=>Promise<T>} task
* @returns {Promise<T>}
*/
async startAsync( taskName, task ) {
const startTime = push( taskName );
async startAsync( taskName, task, options ) {
const startTime = push( taskName, options );
const result = await task();
pop( taskName, startTime );
pop( taskName, startTime, options );
return result;
},

Expand Down

0 comments on commit d08dca2

Please sign in to comment.