44import os
55import requests
66import vmprof
7+ import tempfile
78from jitlog .parser import read_jitlog_data , parse_jitlog
89from vmprof .stats import Stats
910from vmprof .stats import EmptyProfileFile
1011import jitlog
12+ import gzip
1113
1214PY3 = sys .version_info [0 ] >= 3
1315
@@ -80,7 +82,7 @@ def post_new_entry(self, data={}):
8082
8183 def post_file (self , rid , filename , filetype , compress = False ):
8284 if not os .path .exists (filename ):
83- return False
85+ return None
8486 if compress :
8587 filename = compress_file (filename )
8688 with open (filename , 'rb' ) as fd :
@@ -91,7 +93,7 @@ def post_file(self, rid, filename, filetype, compress=False):
9193 del headers ['Content-Type' ]
9294 response = requests .post (url , headers = headers , files = files )
9395 self .stop_if_error_occured (response )
94- return True
96+ return response
9597
9698 def post (self , kwargs ):
9799 sys .stderr .write ("Uploading to %s...\n " % self .host )
@@ -109,30 +111,30 @@ def post(self, kwargs):
109111 sys .stderr .write (" => Uploading the cpu profile...\n " )
110112 self .post_file (rid , filename ,
111113 Service .FILE_CPU_PROFILE , compress = False )
112- elif Service .FILE_MEM_PROFILE in kwargs :
113- filename = kwargs [Service .FILE_MEM_PROFILE ]
114- if os .path .exists (filename ):
115- sys .stderr .write (" => uploading the mem profile...\n " )
116- self .post_file (rid , filename ,
117- Service .FILE_MEM_PROFILE , compress = False )
118- elif Service .FILE_JIT_PROFILE in kwargs :
114+ sys .stderr .write (' ' + self .get_url ('#/%s' % rid ) + "\n " )
115+ if Service .FILE_JIT_PROFILE in kwargs :
119116 filename = kwargs [Service .FILE_JIT_PROFILE ]
120117 if os .path .exists (filename ):
121- sys .stderr .write (" => uploading the jit log...\n " )
118+ sys .stderr .write (" => Uploading the jit log...\n " )
122119 forest = parse_jitlog (filename )
123120 if forest .exception_raised ():
124121 sys .stderr .write (" error: %s\n " % forest .exception_raised ())
125122 # append source code to the binary
126123 forest .extract_source_code_lines ()
127124 forest .copy_and_add_source_code_tags ()
128- filename = self .filepath
129- self .post_file (rid , filename ,
130- Service .FILE_JIT_PROFILE , compress = False )
125+ filename = forest .filepath
126+ response = self .post_file (rid , filename ,
127+ Service .FILE_JIT_PROFILE , compress = True )
131128 forest .unlink_jitlog ()
129+ json = response .json ()
130+ if 'jid' in json :
131+ url = self .get_url ('#/%s/traces' % json ['jid' ])
132+ else :
133+ url = self .get_url ('#/%s' % rid )
134+ sys .stderr .write (' ' + url + "\n " )
132135
133136 self .finalize_entry (rid )
134137
135- sys .stderr .write (self .get_url ('#' + rid ) + "\n " )
136138
137139 def finalize_entry (self , rid , data = b"" ):
138140 url = self .get_url ('/api/runtime/%s/freeze/' % rid )
0 commit comments