forked from embench/embench-iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_native.py
72 lines (53 loc) · 2.06 KB
/
run_native.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# Python module to run programs natively.
# Copyright (C) 2019 Clemson University
#
# Contributor: Ola Jeppsson <[email protected]>
#
# This file is part of Embench.
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Embench module to run benchmark programs.
This version is suitable for running programs natively.
"""
__all__ = [
'get_target_args',
'build_benchmark_cmd',
'decode_results',
]
import argparse
import re
from embench_core import log
def get_target_args(remnant):
"""Parse left over arguments"""
parser = argparse.ArgumentParser(description='Get target specific args')
# No target arguments
return parser.parse_args(remnant)
def build_benchmark_cmd(bench, args):
"""Construct the command to run the benchmark. "args" is a
namespace with target specific arguments"""
# Due to way the target interface currently works we need to construct
# a command that records both the return value and execution time to
# stdin/stdout. Obviously using time will not be very precise.
return ['sh', '-c', 'time -p ./' + bench + '; echo RET=$?']
def decode_results(stdout_str, stderr_str):
"""Extract the results from the output string of the run. Return the
elapsed time in milliseconds or zero if the run failed."""
# See above in build_benchmark_cmd how we record the return value and
# execution time. Return code is in standard output. Execution time is in
# standard error.
# Match "RET=rc"
rcstr = re.search('^RET=(\d+)', stdout_str, re.S | re.M)
if not rcstr:
log.debug('Warning: Failed to find return code')
return 0.0
# Match "real s.mm?m?"
time = re.search('^real (\d+)[.](\d+)', stderr_str, re.S)
if time:
ms_elapsed = int(time.group(1)) * 1000 + \
int(time.group(2).ljust(3,'0')) # 0-pad
# Return value cannot be zero (will be interpreted as error)
return max(float(ms_elapsed), 0.001)
# We must have failed to find a time
log.debug('Warning: Failed to find timing')
return 0.0