Skip to content

Commit

Permalink
Merge pull request #5772 from Krishan-Saraswat/lscpu
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja committed Oct 10, 2023
2 parents d8227a9 + 6207769 commit 925fdb4
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion avocado/utils/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import re
import warnings

from avocado.utils import genio
from avocado.utils import genio, process

#: Map vendor's name with expected string in /proc/cpuinfo.
VENDORS_MAP = {
Expand Down Expand Up @@ -550,6 +550,31 @@ def wrap(*args, **kwargs):
return wrap


def lscpu():
"""
Get Cores per socket, Physical sockets and Physical chips
by executing 'lscpu' command.
:rtype: `dict_obj` with the following details
:cores per socket:
:physical sockets:
:physical chips:
:chips: physical sockets * physical chips
"""
output = process.run("lscpu")
res = {}
for line in output.stdout.decode("utf-8").split("\n"):
if "Core(s) per socket:" in line:
res["cores"] = int(line.split(":")[1].strip())
if "Physical sockets:" in line:
res["physical_sockets"] = int(line.split(":")[1].strip())
if "Physical chips:" in line:
res["physical_chips"] = int(line.split(":")[1].strip())
if "physical_sockets" in res and "physical_chips" in res:
res["chips"] = res["physical_sockets"] * res["physical_chips"]
return res


total_cpus_count = _deprecated(total_count, "total_cpus_count")
_get_cpu_info = _deprecated(_get_info, "_get_cpu_info")
_get_cpu_status = _deprecated(_get_status, "_get_cpu_status")
Expand Down

0 comments on commit 925fdb4

Please sign in to comment.