@@ -9,15 +9,23 @@ const hdiffpatch = require('..');
99if ( process . env . HDIFF_MT_CHILD === '1' ) {
1010 const [ oldPath , newPath , outPath , rawThreads ] = process . argv . slice ( 2 ) ;
1111 const compressionThreads = Number ( rawThreads ) ;
12+ const cpuStartedAt = process . cpuUsage ( ) ;
1213 const startedAt = performance . now ( ) ;
1314 hdiffpatch . diffWindow ( oldPath , newPath , outPath , {
1415 windowSize : 8 * 1024 * 1024 ,
1516 compressionThreads,
1617 } ) ;
18+ const durationMs = performance . now ( ) - startedAt ;
19+ const cpuUsage = process . cpuUsage ( cpuStartedAt ) ;
20+ const cpuTotalMs = ( cpuUsage . user + cpuUsage . system ) / 1000 ;
1721 const patch = fs . readFileSync ( outPath ) ;
1822 console . log ( JSON . stringify ( {
1923 compressionThreads,
20- durationMs : performance . now ( ) - startedAt ,
24+ cpuPercent : ( cpuTotalMs / durationMs ) * 100 ,
25+ cpuSystemMs : cpuUsage . system / 1000 ,
26+ cpuTotalMs,
27+ cpuUserMs : cpuUsage . user / 1000 ,
28+ durationMs,
2129 maxRSSKiB : process . resourceUsage ( ) . maxRSS ,
2230 patchBytes : patch . length ,
2331 patchSha256 : crypto . createHash ( 'sha256' ) . update ( patch ) . digest ( 'hex' ) ,
@@ -93,6 +101,10 @@ try {
93101 ) ;
94102 return {
95103 compressionThreads,
104+ cpuPercent : samples . reduce ( ( sum , sample ) => sum + sample . cpuPercent , 0 ) /
105+ samples . length ,
106+ cpuTotalMs : samples . reduce ( ( sum , sample ) => sum + sample . cpuTotalMs , 0 ) /
107+ samples . length ,
96108 durationMs : samples . reduce ( ( sum , sample ) => sum + sample . durationMs , 0 ) /
97109 samples . length ,
98110 maxRSSKiB : Math . max ( ...samples . map ( ( sample ) => sample . maxRSSKiB ) ) ,
0 commit comments