Skip to content

Instantly share code, notes, and snippets.

@JustinAzoff
Created April 21, 2014 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinAzoff/11143883 to your computer and use it in GitHub Desktop.
Save JustinAzoff/11143883 to your computer and use it in GitHub Desktop.
def parse_cpu_info():
cpu = {}
for line in open("/proc/cpuinfo"):
if ':' in line:
k, v = line.split(":", 1)
k = k.strip()
v = v.strip()
cpu[k] = v
if not line.strip():
yield cpu
cpu = {}
def cpu_report():
cpus = list(parse_cpu_info())
print "processor physical id core id unique"
seen=set()
for cpu in cpus:
tup = (cpu['physical id'], cpu['core id'])
cpu['unique'] = tup not in seen
seen.add(tup)
print "%(processor)9s %(physical id)11s %(core id)6s %(unique)s" % cpu
if __name__ == "__main__":
cpu_report()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment