blob: 64d92511cc86605aac2febb3936f7e7212945c99 [file] [log] [blame]
Raef Coles8cbeed52024-03-11 16:24:57 +00001#!/usr/bin/python3
2# -----------------------------------------------------------------------------
3# Copyright (c) 2024, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# -----------------------------------------------------------------------------
8
9import argparse
10import logging
11import re
12import elftools
13
14def parse_line(line: str) -> str:
15 split = line.split(" ")
16 addr = split[5]
17 size = len(split[6]) // 2
18 logging.debug("Instruction at {} of size {}".format(addr, size))
19 return (addr, size)
20
21parser = argparse.ArgumentParser()
22parser.add_argument("--input_file", help="tarmac file to input", required=True)
23parser.add_argument("--log_level", help="Log level", choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], default="ERROR")
24parser.add_argument("--output_file", help="output file, in qa-tools format", required=True)
25args = parser.parse_args()
26
27# logging setup
28logging.basicConfig(level=args.log_level)
29
30with open(args.input_file, "rt") as input_file:
31 trace = input_file.read()
32
33instructions = re.findall("[0-9]* [a-z]{2} [a-z\.]* IT .*", trace)
34
35hit_counts = {}
36
37for i in instructions:
38 addr = parse_line(i)
39 if addr in hit_counts.keys():
40 hit_counts[addr] += 1
41 else:
42 hit_counts[addr] = 1
43
44with open(args.output_file, "w+") as output_file:
45 output_file.writelines(["{} {} {}\n".format(x[0], hit_counts[x], x[1]) for x in hit_counts.keys()])