From 8bcc0bae0cf015be6d712a164ee5715d444e8839 Mon Sep 17 00:00:00 2001 From: r3da Date: Fri, 25 Sep 2020 23:58:20 +0200 Subject: [PATCH] configure vprof server by setting env vars --- README.md | 6 ++++++ vprof/__main__.py | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a363fdb..d690b29 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,12 @@ where `cmhp` is profiling mode, `host` and `port` are hostname and port of `vprof` server launched in remote mode. Obtained stats will be rendered in new tab of default web browser, opened by `vprof -r` command. + +On the other hand, you can also configure `vprof` server by setting these following environment variables: + +* `VPROF__REMOTE_SERVER_HOST` +* `VPROF__REMOTE_SERVER_PORT` + `vprof` can save profile stats to file and render visualizations from previously saved file. diff --git a/vprof/__main__.py b/vprof/__main__.py index 8d1e329..383f487 100644 --- a/vprof/__main__.py +++ b/vprof/__main__.py @@ -18,7 +18,10 @@ _PROGRAN_NAME = 'vprof' _MODULE_DESC = 'Visual profiler for Python' -_HOST, _PORT = 'localhost', 8000 +_HOST, _PORT = ( + os.getenv('VPROF__REMOTE_SERVER_HOST','localhost'), + os.getenv('VPROF__REMOTE_SERVER_PORT', 8000) +) _CONFIG_DESC = ( """profile program SRC with configuration CONFIG available CONFIG options @@ -70,11 +73,11 @@ def main(): print('Incorrect profiler version - %s. %s is required.' % ( saved_stats['version'], __version__)) sys.exit(_ERR_CODES['input_file_error']) - stats_server.start(args.host, args.port, saved_stats, + stats_server.start(args.host, int(args.port), saved_stats, args.dont_start_browser, args.debug_mode) # Launch in remote mode. elif args.remote: - stats_server.start(args.host, args.port, {}, + stats_server.start(args.host, int(args.port), {}, args.dont_start_browser, args.debug_mode) # Profiler mode. else: @@ -95,7 +98,7 @@ def main(): outfile.write(json.dumps(program_stats, indent=2)) else: stats_server.start( - args.host, args.port, program_stats, + args.host, int(args.port), program_stats, args.dont_start_browser, args.debug_mode) if __name__ == "__main__":