From 9477c7e66cb653cf40cf228131d7c47386e27f1b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 5 Apr 2022 09:18:19 -0400 Subject: [PATCH] Allow passing "ms slower then" value on cli to `--profile` --- piker/_profile.py | 2 +- piker/ui/cli.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/piker/_profile.py b/piker/_profile.py index 2e726e80..697c3c3b 100644 --- a/piker/_profile.py +++ b/piker/_profile.py @@ -24,7 +24,7 @@ from functools import wraps # NOTE: you can pass a flag to enable this: # ``piker chart --profile``. _pg_profile: bool = False -ms_slower_then: float = 10 +ms_slower_then: float = 0 def pg_profile_enabled() -> bool: diff --git a/piker/ui/cli.py b/piker/ui/cli.py index a8bd8e9f..02515fc0 100644 --- a/piker/ui/cli.py +++ b/piker/ui/cli.py @@ -122,7 +122,8 @@ def optschain(config, symbol, date, rate, test): @cli.command() @click.option( '--profile', - is_flag=True, + '-p', + default=None, help='Enable pyqtgraph profiling' ) @click.option( @@ -133,9 +134,16 @@ def optschain(config, symbol, date, rate, test): @click.argument('symbol', required=True) @click.pass_obj def chart(config, symbol, profile, pdb): - """Start a real-time chartng UI - """ - from .. import _profile + ''' + Start a real-time chartng UI + + ''' + # eg. ``--profile 3`` reports profiling for anything slower then 3 ms. + if profile is not None: + from .. import _profile + _profile._pg_profile = True + _profile.ms_slower_then = float(profile) + from ._app import _main if '.' not in symbol: @@ -145,8 +153,6 @@ def chart(config, symbol, profile, pdb): )) return - # toggle to enable profiling - _profile._pg_profile = profile # global opts brokernames = config['brokers']