Skip to content

Commit 3693059

Browse files
authored
Log exec times of each stage of the ui test (microsoft#6430)
* Add logging to see perf times of tests * Run all tests * Revert
1 parent c9ea1ff commit 3693059

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

uitests/uitests/environment.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def f_restore_context(*args, **kwargs):
5151

5252
return deco_context
5353

54-
54+
@uitests.tools.trace
5555
@uitests.tools.retry((TimeoutError, WebDriverException), tries=5, delay=5)
5656
@uitests.tools.log_exceptions()
5757
def before_all(context):
@@ -61,10 +61,12 @@ def before_all(context):
6161
_start_and_clear(context, options)
6262

6363

64+
@uitests.tools.trace
6465
def after_all(context):
6566
_exit(context)
6667

6768

69+
@uitests.tools.trace
6870
def before_feature(context, feature):
6971
for scenario in feature.scenarios:
7072
# If we're working on a scenario, then don't retry.
@@ -86,6 +88,7 @@ def before_feature(context, feature):
8688
patch_scenario_with_autoretry(scenario, max_attempts=2)
8789

8890

91+
@uitests.tools.trace
8992
@uitests.tools.retry((PermissionError, FileNotFoundError), tries=2)
9093
@uitests.tools.log_exceptions()
9194
@restore_context()
@@ -141,6 +144,7 @@ def before_scenario(context, scenario):
141144
_dismiss_one_time_messages(context, retry_count=2)
142145

143146

147+
@uitests.tools.trace
144148
@uitests.tools.log_exceptions()
145149
@restore_context()
146150
def after_scenario(context, scenario):
@@ -195,12 +199,14 @@ def after_scenario(context, scenario):
195199
os.makedirs(context.options.logfiles_dir, exist_ok=True)
196200

197201

202+
@uitests.tools.trace
198203
@uitests.tools.log_exceptions()
199204
@restore_context()
200205
def before_step(context, step):
201206
logging.info("Before step")
202207

203208

209+
@uitests.tools.trace
204210
@uitests.tools.log_exceptions()
205211
@restore_context()
206212
def after_step(context, step):
@@ -253,12 +259,14 @@ def after_step(context, step):
253259
pass
254260

255261

262+
@uitests.tools.trace
256263
@restore_context()
257264
def _exit(context):
258265
uitests.vscode.application.exit(context)
259266
uitests.vscode.application.CONTEXT["driver"] = None
260267

261268

269+
@uitests.tools.trace
262270
def _start_and_clear(context, options):
263271
# Clear VS Code folders (do not let VSC save state).
264272
# During tests, this can be done as a step `When I load VSC for the first time`.
@@ -287,6 +295,7 @@ def _start_and_clear(context, options):
287295
raise
288296

289297

298+
@uitests.tools.trace
290299
def _dismiss_one_time_messages(context, retry_count=100, retry_interval=0.1):
291300
# Dismiss one time VSC messages.
292301
# Dismiss one time extension messages.

uitests/uitests/tools.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ def wrapper(*args, **kwargs):
8383
return deco_log_exceptions
8484

8585

86+
def trace(f):
87+
"""Decorator to just log before and after execution of a function."""
88+
@wraps(f)
89+
def wrapper(*args, **kwargs):
90+
start_time = time.time()
91+
try:
92+
logging.info(f"Before {f.__name__}")
93+
return f(*args, **kwargs)
94+
finally:
95+
elapsed_time = time.time() - start_time
96+
elapsed_time = time.strftime("%H:%M:%S", time.gmtime(elapsed_time))
97+
logging.info(f"After {f.__name__} ({elapsed_time})")
98+
return wrapper
99+
100+
86101
def run_command(command, *, cwd=None, silent=False, progress_message=None, env=None):
87102
"""Run the specified command in a subprocess shell with the following options:
88103
- Pipe output from subprocess into current console.

0 commit comments

Comments
 (0)