diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-07-13 07:32:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-07-13 07:50:52 +0300 |
commit | b90b1af25c8eeb243a748c61af7879eb89ef9d4b (patch) | |
tree | d74267e11885b4726e76c6d6be64f8ec3a18a0a3 /tests/python | |
parent | 5098678308319e9ac2de98928aacffc54c7a9761 (diff) |
Event Simulate: and a --time-actions command line argument
When enabled, print the time taken between running actions.
Diffstat (limited to 'tests/python')
-rw-r--r-- | tests/python/bl_run_operators_event_simulate.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/tests/python/bl_run_operators_event_simulate.py b/tests/python/bl_run_operators_event_simulate.py index 92315d3e853..1cc621b9684 100644 --- a/tests/python/bl_run_operators_event_simulate.py +++ b/tests/python/bl_run_operators_event_simulate.py @@ -165,6 +165,16 @@ def gen_events_type_text(text): yield dict(type=type, value='RELEASE', **kw_extra) +def repr_action(name, args, kwargs): + return "%s(%s)" % ( + name, + ", ".join( + [repr(value) for value in args] + + [("%s=%r" % (key, value)) for key, value in kwargs.items()] + ) + ) + + # ----------------------------------------------------------------------------- # Simulate Events @@ -505,6 +515,18 @@ def argparse_create(): required=False, ) + parser.add_argument( + "--time-actions", + dest="time_actions", + default=False, + action="store_true", + help=( + "Display the time each action takes\n" + "(useful for measuring delay between key-presses)." + ), + required=False, + ) + # Collect doc-strings from static methods in `actions`. actions_docstring = [] for action_key in ACTION_DIR: @@ -554,7 +576,7 @@ def setup_default_preferences(prefs): # Main Function -def main_event_iter(*, action_list): +def main_event_iter(*, action_list, time_actions): """ Yield all events from action handlers. """ @@ -565,9 +587,18 @@ def main_event_iter(*, action_list): yield dict(type='MOUSEMOVE', value='NOTHING', x=x_init, y=y_init) + if time_actions: + import time + t_prev = time.time() + for (op, args, kwargs) in action_list: yield from handle_action(op, args, kwargs) + if time_actions: + t = time.time() + print("%.4f: %s" % ((t - t_prev), repr_action(op, args, kwargs))) + t_prev = t + def main(): from sys import argv @@ -588,7 +619,7 @@ def main(): bpy.app.use_event_simulate = False run_event_simulate( - event_iter=main_event_iter(action_list=args.actions), + event_iter=main_event_iter(action_list=args.actions, time_actions=args.time_actions), exit_fn=exit_fn, ) |