6 # Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in
17 # the documentation and/or other materials provided with the
19 # * Neither the name of Intel Corporation nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 from __future__ import print_function
42 fd = open("/proc/cpuinfo")
43 lines = fd.readlines()
49 if len(line.strip()) != 0:
50 name, value = line.split(":", 1)
51 core_lines[name.strip()] = value.strip()
53 core_details.append(core_lines)
56 for core in core_details:
57 for field in ["processor", "core id", "physical id"]:
59 print("Error getting '%s' value from /proc/cpuinfo" % field)
61 core[field] = int(core[field])
63 if core["core id"] not in cores:
64 cores.append(core["core id"])
65 if core["physical id"] not in sockets:
66 sockets.append(core["physical id"])
67 key = (core["physical id"], core["core id"])
68 if key not in core_map:
70 core_map[key].append(core["processor"])
72 print("============================================================")
73 print("Core and Socket Information (as reported by '/proc/cpuinfo')")
74 print("============================================================\n")
75 print("cores = ", cores)
76 print("sockets = ", sockets)
79 max_processor_len = len(str(len(cores) * len(sockets) * 2 - 1))
80 max_core_map_len = max_processor_len * 2 + len('[, ]') + len('Socket ')
81 max_core_id_len = len(str(max(cores)))
83 output = " ".ljust(max_core_id_len + len('Core '))
85 output += " Socket %s" % str(s).ljust(max_core_map_len - len('Socket '))
88 output = " ".ljust(max_core_id_len + len('Core '))
90 output += " --------".ljust(max_core_map_len)
95 output = "Core %s" % str(c).ljust(max_core_id_len)
97 output += " " + str(core_map[(s, c)]).ljust(max_core_map_len)