1+ import os
12import runpy
2- import sys , os
3+ import subprocess
4+ import sys
35import tempfile
46
57import vmprof
@@ -40,6 +42,7 @@ def upload_stats(stats, forest, args):
4042
4143def main ():
4244 args = vmprof .cli .parse_args (sys .argv [1 :])
45+ proc = None
4346
4447 if args .web :
4548 output_mode = OUTPUT_WEB
@@ -51,14 +54,24 @@ def main():
5154 if output_mode == OUTPUT_FILE :
5255 prof_file = args .output
5356 prof_name = prof_file .name
57+ fileno = prof_file .fileno ()
58+ print ("gzip: " , args )
59+ if args .gzip :
60+ cmd = ['/usr/bin/gzip' , "-" + str (args .gzip )]
61+ proc = subprocess .Popen (cmd , bufsize = - 1 ,
62+ stdin = subprocess .PIPE ,
63+ stdout = prof_file .fileno (),
64+ close_fds = True )
65+ fileno = proc .stdin .fileno ()
5466 else :
5567 prof_file = tempfile .NamedTemporaryFile (delete = False )
5668 prof_name = prof_file .name
69+ fileno = prof_file .fileno ()
5770
5871 if args .jitlog :
5972 assert hasattr (vmprof , 'enable_jitlog' ), "note: jitlog is only available on pypy"
6073
61- vmprof .enable (prof_file . fileno () , args .period , args .mem )
74+ vmprof .enable (fileno , args .period , args .mem )
6275 if args .jitlog :
6376 # note that this file descr is then handled by jitlog
6477 fd = os .open (prof_name + '.jitlog' , os .O_WRONLY | os .O_TRUNC | os .O_CREAT )
@@ -74,6 +87,9 @@ def main():
7487 vmprof .disable ()
7588 if args .jitlog and hasattr (vmprof , 'disable_jitlog' ):
7689 vmprof .disable_jitlog (fd )
90+ if proc :
91+ proc .stdin .close ()
92+ proc .wait ()
7793 prof_file .close ()
7894 show_stats (prof_name , output_mode , args )
7995 if output_mode != OUTPUT_FILE :
0 commit comments