87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
|
import argparse
|
||
|
import os
|
||
|
import re
|
||
|
from pathlib import Path
|
||
|
|
||
|
import plotly.express as px
|
||
|
import yaml
|
||
|
|
||
|
|
||
|
def parse_logs(log_dir):
|
||
|
results = []
|
||
|
for filename in os.listdir(log_dir):
|
||
|
if filename.endswith(".log"):
|
||
|
filepath = os.path.join(log_dir, filename)
|
||
|
with open(filepath, "r", encoding="utf8") as file:
|
||
|
for line in file:
|
||
|
if (
|
||
|
"Executed" in line
|
||
|
and "instructions" in line
|
||
|
and "during" in line
|
||
|
and "resulting in" in line
|
||
|
):
|
||
|
parts = line.split()
|
||
|
instructions = int(parts[3])
|
||
|
time_idx = parts.index("during") + 1
|
||
|
time = int(parts[time_idx].rstrip("ms"))
|
||
|
mips_idx = parts.index("resulting") + 2
|
||
|
mips = float(parts[mips_idx].rstrip("MIPS"))
|
||
|
backend, iterations, _ = re.split(r"[_.]", filename)
|
||
|
|
||
|
results.append(
|
||
|
{
|
||
|
"backend": backend,
|
||
|
"run_count": int(iterations),
|
||
|
"instructions": instructions,
|
||
|
"time": time,
|
||
|
"mips": mips,
|
||
|
}
|
||
|
)
|
||
|
return results
|
||
|
|
||
|
|
||
|
def write_yaml(results, output_file):
|
||
|
with open(output_file, "w", encoding="utf8") as file:
|
||
|
yaml.dump(results, file)
|
||
|
|
||
|
|
||
|
def visualize_mips_over_instructions(yaml_file):
|
||
|
# Read data from YAML file
|
||
|
with open(yaml_file, "r", encoding="utf8") as file:
|
||
|
data = yaml.safe_load(file)
|
||
|
|
||
|
# Extract instructions and MIPS values
|
||
|
run_count = [entry["run_count"] for entry in data]
|
||
|
mips = [entry["mips"] for entry in data]
|
||
|
backends = [entry["backend"] for entry in data]
|
||
|
# Create scatter plot using Plotly Express
|
||
|
fig = px.line(
|
||
|
x=run_count,
|
||
|
y=mips,
|
||
|
color=backends,
|
||
|
labels={"x": "Dhrystone Iterations", "y": "MIPS", "color": "Backend"},
|
||
|
title="MIPS over Amount of Dhrystone Iterations",
|
||
|
log_x=True,
|
||
|
)
|
||
|
fig.show()
|
||
|
|
||
|
|
||
|
def main():
|
||
|
parser = argparse.ArgumentParser(
|
||
|
description="""
|
||
|
Parse log files and extract relevant information. Create a 'results.yaml' file and visualize it.
|
||
|
Intended to be run after 'dhrystone_run_multiple.py'"""
|
||
|
)
|
||
|
parser.add_argument("log_dir", help="Path to the directory containing log files.")
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
result_file = Path(__file__).parent / "results.yaml"
|
||
|
if not result_file.is_file():
|
||
|
results = parse_logs(args.log_dir)
|
||
|
write_yaml(results, result_file)
|
||
|
visualize_mips_over_instructions(result_file)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|