MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / gather_cpu_info

Function gather_cpu_info

tensorflow/tools/test/system_info_lib.py:76–119  ·  view source on GitHub ↗

Gather CPU Information. Assumes all CPUs are the same.

()

Source from the content-addressed store, hash-verified

74
75
76def gather_cpu_info():
77 """Gather CPU Information. Assumes all CPUs are the same."""
78 cpu_info = test_log_pb2.CPUInfo()
79 cpu_info.num_cores = multiprocessing.cpu_count()
80
81 # Gather num_cores_allowed
82 try:
83 with gfile.GFile('/proc/self/status', 'rb') as fh:
84 nc = re.search(r'(?m)^Cpus_allowed:\s*(.*)$', fh.read())
85 if nc: # e.g. 'ff' => 8, 'fff' => 12
86 cpu_info.num_cores_allowed = (
87 bin(int(nc.group(1).replace(',', ''), 16)).count('1'))
88 except errors.OpError:
89 pass
90 finally:
91 if cpu_info.num_cores_allowed == 0:
92 cpu_info.num_cores_allowed = cpu_info.num_cores
93
94 # Gather the rest
95 info = cpuinfo.get_cpu_info()
96 cpu_info.cpu_info = info['brand']
97 cpu_info.num_cores = info['count']
98 cpu_info.mhz_per_cpu = info['hz_advertised_raw'][0] / 1.0e6
99 l2_cache_size = re.match(r'(\d+)', str(info.get('l2_cache_size', '')))
100 if l2_cache_size:
101 # If a value is returned, it's in KB
102 cpu_info.cache_size['L2'] = int(l2_cache_size.group(0)) * 1024
103
104 # Try to get the CPU governor
105 try:
106 cpu_governors = set([
107 gfile.GFile(f, 'r').readline().rstrip()
108 for f in glob.glob(
109 '/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor')
110 ])
111 if cpu_governors:
112 if len(cpu_governors) > 1:
113 cpu_info.cpu_governor = 'mixed'
114 else:
115 cpu_info.cpu_governor = list(cpu_governors)[0]
116 except errors.OpError:
117 pass
118
119 return cpu_info
120
121
122def gather_available_device_info():

Callers 1

Calls 7

replaceMethod · 0.80
readlineMethod · 0.80
readMethod · 0.45
countMethod · 0.45
groupMethod · 0.45
matchMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected