[Bf-blender-cvs] [b90b1af25c8] master: Event Simulate: and a --time-actions command line argument

Campbell Barton noreply at git.blender.org
Tue Jul 13 06:51:22 CEST 2021


Commit: b90b1af25c8eeb243a748c61af7879eb89ef9d4b
Author: Campbell Barton
Date:   Tue Jul 13 14:32:41 2021 +1000
Branches: master
https://developer.blender.org/rBb90b1af25c8eeb243a748c61af7879eb89ef9d4b

Event Simulate: and a --time-actions command line argument

When enabled, print the time taken between running actions.

===================================================================

M	tests/python/bl_run_operators_event_simulate.py

===================================================================

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,
     )



More information about the Bf-blender-cvs mailing list