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,23 @@ 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+ if args .gzip :
59+ cmd = ['/usr/bin/gzip' , "-" + str (args .gzip )]
60+ proc = subprocess .Popen (cmd , bufsize = - 1 ,
61+ stdin = subprocess .PIPE ,
62+ stdout = prof_file .fileno (),
63+ close_fds = True )
64+ fileno = proc .stdin .fileno ()
5465 else :
5566 prof_file = tempfile .NamedTemporaryFile (delete = False )
5667 prof_name = prof_file .name
68+ fileno = prof_file .fileno ()
5769
5870 if args .jitlog :
5971 assert hasattr (vmprof , 'enable_jitlog' ), "note: jitlog is only available on pypy"
6072
61- vmprof .enable (prof_file . fileno () , args .period , args .mem )
73+ vmprof .enable (fileno , args .period , args .mem )
6274 if args .jitlog :
6375 # note that this file descr is then handled by jitlog
6476 fd = os .open (prof_name + '.jitlog' , os .O_WRONLY | os .O_TRUNC | os .O_CREAT )
@@ -74,6 +86,9 @@ def main():
7486 vmprof .disable ()
7587 if args .jitlog and hasattr (vmprof , 'disable_jitlog' ):
7688 vmprof .disable_jitlog (fd )
89+ if proc :
90+ proc .stdin .close ()
91+ proc .wait ()
7792 prof_file .close ()
7893 show_stats (prof_name , output_mode , args )
7994 if output_mode != OUTPUT_FILE :
0 commit comments