From 17b3e10bab5fd0c057b3ab88c2ebd9818d737cc0 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Fri, 31 Aug 2018 08:34:19 +0100 Subject: [PATCH] gem5-stat ported --- common.py | 1 + gem5-stat | 45 ++++++++++++++++++++------------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/common.py b/common.py index b515b89..611cf66 100644 --- a/common.py +++ b/common.py @@ -236,6 +236,7 @@ def setup(parser, **extra_args): this.target_dir = os.path.join(this.buildroot_out_dir, 'target') this.gem5_run_dir = os.path.join(this.out_arch_dir, 'gem5', str(args.run_id)) this.m5out_dir = os.path.join(this.gem5_run_dir, 'm5out') + this.stats_file = os.path.join(this.m5out_dir, 'stats.txt') this.trace_txt_file = os.path.join(this.m5out_dir, 'trace.txt') this.gem5_termout_file = os.path.join(this.gem5_run_dir, 'termout.txt') this.qemu_run_dir = os.path.join(this.out_arch_dir, 'qemu', str(args.run_id)) diff --git a/gem5-stat b/gem5-stat index 6ed64f3..a3ec8a0 100755 --- a/gem5-stat +++ b/gem5-stat @@ -1,25 +1,20 @@ -#!/usr/bin/env bash -. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" -common_gem5=true -while getopts "h${common_getopts_flags}" OPT; do - case "$OPT" in - h) - printf "\ -usage: $0 [-a arch] [stat=system.cpu.numCycles] -Get the value for a gem5 stat from the stats.txt file. -" 1>&2 - exit - ;; - ?) - common_getopts_case "$OPT" - ;; - esac -done -shift "$(($OPTIND - 1))" -if [ $# -gt 0 ]; then - stat="$1" -else - stat=system.cpu[0-9]*.numCycles -fi -common_setup -awk "/^$stat /{ print \$2 }" "${common_m5out_dir}/stats.txt" +#!/usr/bin/env python3 +import re +import common +parser = common.get_argparse( + argparse_args={'description':'Get the value of a gem5 stat from the stats.txt file.'} +) +parser.add_argument( + 'stat', + default='^system.cpu[0-9]*.numCycles$', + help='Python regexp matching the full stat name of interest', + nargs='?', +) +args = common.setup(parser) +stat_re = re.compile(args.stat) +with open(common.stats_file, 'r') as statfile: + for line in statfile: + if line[0] != '-': + cols = line.split() + if len(cols) > 1 and stat_re.search(cols[0]): + print(cols[1])