diff --git a/jitlog/__main__.py b/jitlog/__main__.py index 5a72ec4e..2d1bcbc2 100644 --- a/jitlog/__main__.py +++ b/jitlog/__main__.py @@ -81,15 +81,9 @@ def main(): sys.exit(0) if args.upload: - # parse_jitlog will append source code to the binary - forest = parse_jitlog(args.program) - if forest.exception_raised(): - print("ERROR:", forest.exception_raised()) - sys.exit(1) - if forest.extract_source_code_lines(): - # only copy the tags if the jitlog has no source code yet! - forest.copy_and_add_source_code_tags() - jitlog_upload(forest.filepath, get_url(args.web_url, "api/jitlog//")) + host, auth = args.web_url, args.web_auth + service = Service(host, auth) + service.post({ Service.File_JIT_PROFILE: args.program }) sys.exit(0) if not _jitlog: diff --git a/vmprof/__main__.py b/vmprof/__main__.py index 89a3c5a7..436003d1 100644 --- a/vmprof/__main__.py +++ b/vmprof/__main__.py @@ -2,44 +2,29 @@ import sys, os import tempfile import vmprof -from vmprof.upload import upload as upload_vmprofile -from jitlog.parser import parse_jitlog +from vmshare.service import Service try: import _jitlog except ImportError: _jitlog = None - OUTPUT_CLI = 'cli' OUTPUT_WEB = 'web' OUTPUT_FILE = 'file' - def show_stats(filename, output_mode, args): if output_mode == OUTPUT_FILE: return - - stats = vmprof.read_profile(filename) - forest = None - jitlog_filename = filename + '.jitlog' - - if output_mode == OUTPUT_CLI: + elif output_mode == OUTPUT_CLI: + stats = vmprof.read_profile(filename) vmprof.cli.show(stats) elif output_mode == OUTPUT_WEB: - if os.path.exists(jitlog_filename): - forest = parse_jitlog(jitlog_filename) - upload_stats(stats, forest, args) - - -def upload_stats(stats, forest, args): - name = args.program - argv = " ".join(args.args) - host = args.web_url - auth = args.web_auth - # - sys.stderr.write("Compiling and uploading to %s...\n" % (args.web_url,)) - upload_vmprofile(stats, name, argv, host, auth, forest) - + host, auth = args.web_url, args.web_auth + service = Service(host, auth) + service.post({ Service.FILE_CPU_PROFILE: filename, + Service.FILE_MEM_PROFILE: filename + '.mem', + Service.File_JIT_PROFILE: filename + '.jit', + 'argv': ' '.join(args.args)}) def main(): args = vmprof.cli.parse_args(sys.argv[1:]) @@ -61,7 +46,7 @@ def main(): vmprof.enable(prof_file.fileno(), args.period, args.mem, args.lines) if args.jitlog and _jitlog: - fd = os.open(prof_name + '.jitlog', os.O_WRONLY | os.O_TRUNC | os.O_CREAT) + fd = os.open(prof_name + '.jit', os.O_WRONLY | os.O_TRUNC | os.O_CREAT) _jitlog.enable(fd) # invoke the user program: try: @@ -81,5 +66,4 @@ def main(): if output_mode != OUTPUT_FILE: os.unlink(prof_name) - main() diff --git a/vmprof/upload.py b/vmprof/upload.py index d1eb9f84..de63d96d 100644 --- a/vmprof/upload.py +++ b/vmprof/upload.py @@ -1,56 +1,6 @@ import sys -import json import argparse -import os -import requests -import vmprof -from jitlog.parser import read_jitlog_data, parse_jitlog -from vmprof.stats import Stats -from vmprof.stats import EmptyProfileFile -from vmshare import get_url -import jitlog - -PY3 = sys.version_info[0] >= 3 - -def upload(stats, name, argv, host, auth, forest=None): - - try: - profiles = stats.get_tree()._serialize() - except EmptyProfileFile: - # yes an empty profile is possible. - # i.e. if we only want to upload the jitlog - profiles = [] - - data = { - "VM": stats.interp, - "profiles": profiles, - "argv": "%s %s" % (name, argv), - "version": 2, - } - data = json.dumps(data).encode('utf-8') - - base_headers = {} - if auth: - base_headers = {'AUTHORIZATION': "Token %s" % auth} - - # XXX http only for now - # upload the json profile - headers = base_headers.copy() - headers['Content-Type'] = 'application/json' - url = get_url(host, "api/profile/") - r = requests.post(url, data=data, headers=headers) - if r.status_code != 200: - sys.stderr.write("VMProf log: Server rejected profile. status: %d, msg: '%s'\n" % \ - (r.status_code,r.text)) - profile_checksum = '' - else: - profile_checksum = r.text[1:-1] - sys.stderr.write("VMProf log: %s/#/%s\n" % (host.rstrip("/"), profile_checksum)) - - if forest: - url = get_url(host, "api/jitlog/%s/" % profile_checksum) - jitlog.upload(forest.filepath, url) - forest.unlink_jitlog() +from vmshare.service import Service def main(): parser = argparse.ArgumentParser() @@ -59,15 +9,11 @@ def main(): parser.add_argument("--web-auth", default=None, help='Authtoken for your acount on the server') args = parser.parse_args() - stats = vmprof.read_profile(args.profile) - jitlog_path = args.profile + ".jitlog" - if os.path.exists(jitlog_path): - jitlog.upload(jitlog_path, args) - sys.stderr.write("Compiling and uploading to %s...\n" % args.web_url) - - upload(stats, args.profile, [], args.web_url, - args.web_auth, None) - + host, auth = args.web_url, args.web_auth + service = Service(host, auth) + service.post({ Service.FILE_CPU_PROFILE: filename, + Service.FILE_MEM_PROFILE: filename + '.mem', + Service.File_JIT_PROFILE: filename + '.jit' }) if __name__ == '__main__': main() diff --git a/vmshare/__init__.py b/vmshare/__init__.py index 91a5579d..8b137891 100644 --- a/vmshare/__init__.py +++ b/vmshare/__init__.py @@ -1,7 +1 @@ -def get_url(host, path): - if host.startswith("http"): - url = '%s/%s' % (host.rstrip("/"), path) - else: - url = 'http://%s/%s' % (host.rstrip("/"), path) - return url