From 3a84ecfa0e1c089bb4042b5e379d81254b861776 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Mon, 4 Dec 2023 20:03:48 -0800 Subject: [PATCH] Fix toplev and genretlat for python 2 --- genretlat.py | 8 +++++--- toplev.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/genretlat.py b/genretlat.py index 9801a94c..760f5f29 100755 --- a/genretlat.py +++ b/genretlat.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# -*- coding: utf-8 # generate return latencies to tune toplev model # Copyright (c) 2023, Intel Corporation # Author: Andi Kleen @@ -11,6 +12,7 @@ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. +from __future__ import print_function import subprocess as subp import os import sys @@ -138,14 +140,14 @@ def gen_stat(samples): def human_output(data): d = data["Data"] for ev in sorted(d.keys()): - print(f"{ev}: ", end="") + print("%s: " % ev, end="") for m in sorted(d[ev].keys()): if m.startswith("SPARK"): l = [int(x) for x in d[ev][m].split(",")] s = gen_spark(l, d[ev]["MIN"], d[ev]["F_NZ" if m.endswith("_NZ") else "F"]) - print(f"{m.lower()} {s} ", end="") + print("%s %s " % (m.lower(), s), end="") else: - print(f"{m.lower()} {d[ev][m]} ", end="") + print("%s %s " % (m.lower(), d[ev][m]), end="") print() def find_model(): diff --git a/toplev.py b/toplev.py index 203a784a..73f6ba54 100755 --- a/toplev.py +++ b/toplev.py @@ -1021,7 +1021,7 @@ def setup_retlatency(args): try: l = args.ret_latency.split(":") ret_latency = json.load(open(l[0]))["Data"] - except FileNotFoundError: + except IOError: sys.exit("Cannot open %s" % l[0]) except KeyError: sys.exit("retlat file has unparseable format") @@ -3969,7 +3969,7 @@ def load_default_retlat(): fn = os.path.dirname(os.path.realpath(__file__)) + ("/%s-retlat.json" % name) try: ret_latency = json.load(open(fn))["Data"] - except FileNotFoundError: + except IOError: sys.exit("Cannot find default ret latency file %s\n" % fn + "Please generate with representative workload using genretlat -o %s workload" % fn)