11var fs = require ( "fs" ) ,
22 path = require ( "path" ) ;
3- var protobuf = require ( ".." ) ;
43
5- // A profiling stub to measure just raw encoding / decoding performance using benchmark data.
4+ // A profiling stub to measure encoding / decoding performance using benchmark data.
5+
6+ var commands = [ "encode" , "decode" , "encode-browser" , "decode-browser" ] ;
7+ if ( commands . indexOf ( process . argv [ 2 ] ) < 0 ) { // 0: node, 1: prof.js
8+ console . error ( "usage: " + path . basename ( process . argv [ 1 ] ) + " <" + commands . join ( '|' ) + "> [iterations=10000000]" ) ;
9+ process . exit ( 0 ) ;
10+ }
11+
12+ // Spin up a node process with profiling enabled and process the generated log
13+ if ( process . execArgv . indexOf ( "--prof" ) < 0 ) {
14+ console . log ( "cleaning up old logs ..." ) ;
15+ var child_process = require ( "child_process" ) ;
16+ var logRe = / ^ i s o l a t e \- [ 0 - 9 A - F ] + \- v 8 \. l o g $ / ;
17+ fs . readdirSync ( process . cwd ( ) ) . forEach ( function ( file ) {
18+ if ( logRe . test ( file ) )
19+ fs . unlink ( file ) ;
20+ } ) ;
21+ console . log ( "generating profile (may take a while) ..." ) ;
22+ child_process . execSync ( "node --prof --trace-deopt " + process . argv . slice ( 1 ) . join ( ' ' ) , {
23+ cwd : process . cwd ( ) ,
24+ stdio : 'inherit'
25+ } ) ;
26+ console . log ( "processing profile ..." ) ;
27+ fs . readdirSync ( process . cwd ( ) ) . forEach ( function ( file ) {
28+ if ( logRe . test ( file ) ) {
29+ child_process . execSync ( "node --prof-process " + file , {
30+ cwd : process . cwd ( ) ,
31+ stdio : 'inherit'
32+ } ) ;
33+ fs . unlink ( file ) ;
34+ }
35+ } ) ;
36+ console . log ( "done." ) ;
37+ process . exit ( 0 ) ;
38+ }
39+
40+ // Actual profiling code
41+ var protobuf = require ( ".." ) ;
642
743var root = protobuf . parse ( fs . readFileSync ( require . resolve ( "../bench/bench.proto" ) ) . toString ( "utf8" ) ) . root ;
844var Test = root . lookup ( "Test" ) ;
@@ -16,10 +52,6 @@ function setupBrowser() {
1652}
1753
1854switch ( process . argv [ 2 ] ) {
19- default :
20- console . error ( "usage: " + path . basename ( process . argv [ 1 ] ) + " <encode|decode|encode-browser|decode-browser> [iterations=10000000]" ) ;
21- process . exit ( 1 ) ;
22- return ;
2355 case "encode-browser" :
2456 setupBrowser ( ) ;
2557 case "encode" :
0 commit comments