Skip to content

Commit

Permalink
lscpu command added as a function
Browse files Browse the repository at this point in the history
Added lscpu command to get values of core, physical sockets, physical
chips and chips, this can be extended to get other values related to
lscpu.

Signed-off-by: Krishan Gopal Saraswat <[email protected]>
  • Loading branch information
Krishan-Saraswat committed Oct 9, 2023
1 parent cfce417 commit 6207769
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 6207769

Please sign in to comment.