Skip to content

Commit

Permalink
add run.profile_stages config
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Oct 30, 2024
1 parent f984b43 commit 65454d1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mlonmcu/session/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
"""Definition of a MLonMCU Run which represents a single benchmark instance for a given set of options."""
import itertools
import time
import os
import copy
import tempfile
Expand Down Expand Up @@ -83,6 +84,7 @@ class Run:
"target_optimized_layouts": False,
"target_optimized_schedules": False,
"stage_subdirs": False,
"profile_stages": False,
}

REQUIRED = set()
Expand Down Expand Up @@ -135,6 +137,7 @@ def __init__(
self.sub_names = []
self.sub_parents = {}
self.result = None
self.times = {}
self.failing = False # -> RunStatus
self.reason = None
self.failed_stage = None
Expand Down Expand Up @@ -190,6 +193,11 @@ def stage_subdirs(self):
value = self.run_config["stage_subdirs"]
return str2bool(value)

@property
def profile_stages(self):
value = self.run_config["profile_stages"]
return str2bool(value)

@property
def build_platform(self):
"""Get platform for build stage."""
Expand Down Expand Up @@ -1087,7 +1095,12 @@ def process(self, until=RunStage.RUN, skip=None, export=False):
if func:
self.failing = False
try:
if self.profile_stages:
start = time.time()
func()
if self.profile_stages:
end = time.time()
self.times[stage] = (start, end)

Check failure on line 1103 in mlonmcu/session/run.py

View workflow job for this annotation

GitHub Actions / Flake8

mlonmcu/session/run.py#L1103

Trailing whitespace (W291)
except Exception as e:
self.failing = True
self.reason = e
Expand Down Expand Up @@ -1303,6 +1316,12 @@ def metrics_helper(stage, subs):
main = metrics_by_sub[sub].get_data(include_optional=self.export_optional)
else:
main = {}
if self.profile_stages:
for stage, stage_times in self.times.items():
assert len(stage_times) == 2
start, end = stage_times
main[f"{RunStage(stage).name.capitalize()} Stage Start Time [s]"] = start
main[f"{RunStage(stage).name.capitalize()} Stage End Time [s]"] = end
mains.append(main if len(main) > 0 else {"Incomplete": True})
posts.append(post) # TODO: omit for subs?
report.set(pre=pres, main=mains, post=posts)
Expand Down

0 comments on commit 65454d1

Please sign in to comment.