Skip to content

Commit 62c7774

Browse files
PerMacnashif
authored andcommitted
twister: footprints: Move footprint calculation
Adds operation "gather_footprint" after the build stage with minor refactoring. Before footprints were collected only at the very end of the twister workflow and there were situations were elf files were not available any more (for qemu and --runtime-artifact-cleanup used). Signed-off-by: Maciej Perkowski <[email protected]>
1 parent 6c261f2 commit 62c7774

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

scripts/pylib/twister/twisterlib.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
import shlex
1616
import signal
1717
import threading
18-
import concurrent.futures
1918
from collections import OrderedDict
2019
import queue
2120
import time
2221
import csv
2322
import glob
24-
import concurrent
2523
import xml.etree.ElementTree as ET
2624
import logging
2725
from pathlib import Path
@@ -2494,14 +2492,18 @@ def process(self, pipeline, done, message, lock, results):
24942492
inst = res.get("instance", None)
24952493
if inst and inst.status == "skipped":
24962494
results.skipped_runtime += 1
2497-
24982495
if res.get('returncode', 1) > 0:
24992496
pipeline.put({"op": "report", "test": self.instance})
25002497
else:
2501-
if self.instance.run and self.instance.handler:
2502-
pipeline.put({"op": "run", "test": self.instance})
2503-
else:
2504-
pipeline.put({"op": "report", "test": self.instance})
2498+
pipeline.put({"op": "gather_metrics", "test": self.instance})
2499+
2500+
elif op == "gather_metrics":
2501+
self.gather_metrics(self.instance)
2502+
if self.instance.run and self.instance.handler:
2503+
pipeline.put({"op": "run", "test": self.instance})
2504+
else:
2505+
pipeline.put({"op": "report", "test": self.instance})
2506+
25052507
# Run the generated binary using one of the supported handlers
25062508
elif op == "run":
25072509
logger.debug("run test: %s" % self.instance.name)
@@ -2719,6 +2721,29 @@ def run(self):
27192721

27202722
sys.stdout.flush()
27212723

2724+
def gather_metrics(self, instance):
2725+
if self.suite.enable_size_report and not self.suite.cmake_only:
2726+
self.calc_one_elf_size(instance)
2727+
else:
2728+
instance.metrics["ram_size"] = 0
2729+
instance.metrics["rom_size"] = 0
2730+
instance.metrics["unrecognized"] = []
2731+
2732+
@staticmethod
2733+
def calc_one_elf_size(instance):
2734+
if instance.status not in ["error", "failed", "skipped"]:
2735+
if instance.platform.type != "native":
2736+
size_calc = instance.calculate_sizes()
2737+
instance.metrics["ram_size"] = size_calc.get_ram_size()
2738+
instance.metrics["rom_size"] = size_calc.get_rom_size()
2739+
instance.metrics["unrecognized"] = size_calc.unrecognized_sections()
2740+
else:
2741+
instance.metrics["ram_size"] = 0
2742+
instance.metrics["rom_size"] = 0
2743+
instance.metrics["unrecognized"] = []
2744+
2745+
instance.metrics["handler_time"] = instance.handler.duration if instance.handler else 0
2746+
27222747
class TestSuite(DisablePyTestCollectionMixin):
27232748
config_re = re.compile('(CONFIG_[A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$')
27242749
dt_re = re.compile('([A-Za-z0-9_]+)[=]\"?([^\"]*)\"?$')
@@ -3471,21 +3496,6 @@ def add_instances(self, instance_list):
34713496
for instance in instance_list:
34723497
self.instances[instance.name] = instance
34733498

3474-
@staticmethod
3475-
def calc_one_elf_size(instance):
3476-
if instance.status not in ["error", "failed", "skipped"]:
3477-
if instance.platform.type != "native":
3478-
size_calc = instance.calculate_sizes()
3479-
instance.metrics["ram_size"] = size_calc.get_ram_size()
3480-
instance.metrics["rom_size"] = size_calc.get_rom_size()
3481-
instance.metrics["unrecognized"] = size_calc.unrecognized_sections()
3482-
else:
3483-
instance.metrics["ram_size"] = 0
3484-
instance.metrics["rom_size"] = 0
3485-
instance.metrics["unrecognized"] = []
3486-
3487-
instance.metrics["handler_time"] = instance.handler.duration if instance.handler else 0
3488-
34893499
def add_tasks_to_queue(self, pipeline, build_only=False, test_only=False):
34903500
for instance in self.instances.values():
34913501
if build_only:
@@ -3553,20 +3563,6 @@ def execute(self, pipeline, done, results):
35533563
for p in processes:
35543564
p.terminate()
35553565

3556-
# FIXME: This needs to move out.
3557-
if self.enable_size_report and not self.cmake_only:
3558-
# Parallelize size calculation
3559-
executor = concurrent.futures.ThreadPoolExecutor(self.jobs)
3560-
futures = [executor.submit(self.calc_one_elf_size, instance)
3561-
for instance in self.instances.values()]
3562-
concurrent.futures.wait(futures)
3563-
else:
3564-
for instance in self.instances.values():
3565-
instance.metrics["ram_size"] = 0
3566-
instance.metrics["rom_size"] = 0
3567-
instance.metrics["handler_time"] = instance.handler.duration if instance.handler else 0
3568-
instance.metrics["unrecognized"] = []
3569-
35703566
return results
35713567

35723568
def discard_report(self, filename):

0 commit comments

Comments
 (0)