From: ogawa.yasufumi@lab.ntt.co.jp
To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Subject: [spp] [PATCH] tools/helpers: refactor cpu_layout script
Date: Wed, 8 May 2019 10:57:51 +0900 [thread overview]
Message-ID: <1557280671-7416-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> (raw)
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
Update cpu_layout.py to comply with pep3.
Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
---
tools/helpers/cpu_layout.py | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/tools/helpers/cpu_layout.py b/tools/helpers/cpu_layout.py
index 58a2bd6..bf86583 100755
--- a/tools/helpers/cpu_layout.py
+++ b/tools/helpers/cpu_layout.py
@@ -7,41 +7,40 @@
from __future__ import print_function
import argparse
import json
-import sys
+
try:
xrange # Python 2
except NameError:
xrange = range # Python 3
-base_path = "/sys/devices/system/cpu"
+BASE_PATH = "/sys/devices/system/cpu"
def parse_args():
parser = argparse.ArgumentParser(
description="Show CPU layout")
-
parser.add_argument(
- "--json", action="store_true",
- help="Output in JSON format")
+ "--json", action="store_true",
+ help="Output in JSON format")
return parser.parse_args()
def get_max_cpus():
- fd = open("{}/kernel_max".format(base_path))
+ fd = open("{}/kernel_max".format(BASE_PATH))
max_cpus = int(fd.read())
fd.close()
return max_cpus
def get_resource_info(max_cpus):
- """Return a set of sockets, cores and core_map as a tuple."""
+ """Return a set of sockets, cores and core_map as tuple."""
sockets = []
cores = []
core_map = {}
for cpu in xrange(max_cpus + 1):
try:
- topo_path = "{}/cpu{}/topology".format(base_path, cpu)
+ topo_path = "{}/cpu{}/topology".format(BASE_PATH, cpu)
# Get physical core ID.
fd = open("{}/core_id".format(topo_path))
@@ -72,10 +71,10 @@ def get_resource_info(max_cpus):
def print_header(cores, sockets):
- print(format("=" * (47 + len(base_path))))
+ print(format("=" * (47 + len(BASE_PATH))))
print("Core and Socket Information (as reported by '{}')".format(
- base_path))
- print("{}\n".format("=" * (47 + len(base_path))))
+ BASE_PATH))
+ print("{}\n".format("=" * (47 + len(BASE_PATH))))
print("cores = ", cores)
print("sockets = ", sockets)
print("")
@@ -92,7 +91,7 @@ def print_body(cores, sockets, core_map):
output = " ".ljust(max_core_id_len + len('Core '))
for s in sockets:
output += " Socket %s" % str(s).ljust(
- max_core_map_len - len('Socket '))
+ max_core_map_len - len('Socket '))
print(output)
output = " ".ljust(max_core_id_len + len('Core '))
@@ -115,10 +114,10 @@ def core_map_to_json(core_map):
cpu_layout = []
cpu_sockets = {}
for (s, c), cpus in core_map.items():
- if not (s in cpu_sockets):
+ if not s in cpu_sockets:
cpu_sockets[s] = {}
cpu_sockets[s]["cores"] = []
- cpu_sockets[s]["cores"].append({"core_id": c, "cpus": cpus})
+ cpu_sockets[s]["cores"].append({"core_id": c, "lcores": cpus})
for sid, val in cpu_sockets.items():
cpu_layout.append({"socket_id": sid, "cores": val["cores"]})
--
2.17.1
reply other threads:[~2019-05-08 2:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1557280671-7416-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp \
--to=ogawa.yasufumi@lab.ntt.co.jp \
--cc=ferruh.yigit@intel.com \
--cc=spp@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).