Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #!/usr/bin/python
  2. import glob
  3. import os
  4. import sys
  5.  
  6. SYS_CPU = '/sys/devices/system/cpu/cpu{}'
  7. SYS_CPU_SETTING = '/sys/devices/system/cpu/cpu{cpu}/{setting}'
  8.  
  9. SETTINGS = {
  10. 'Online': 'online',
  11. 'Min Freq.': 'cpufreq/cpuinfo_min_freq',
  12. 'Max Freq.': 'cpufreq/cpuinfo_max_freq',
  13. 'Scaling Driver': 'cpufreq/scaling_driver',
  14. 'Scaling Governor': 'cpufreq/scaling_governor',
  15. 'Scaling Governor': 'cpufreq/scaling_governor',
  16. }
  17.  
  18. if __name__ == '__main__':
  19. cpus = [int(path[len(SYS_CPU.format('')):]) for path in \
  20. glob.glob(SYS_CPU.format('[0-9]*'))]
  21.  
  22. for cpu in cpus:
  23. hdr = 'CPU {}'.format(cpu)
  24. divider = '-' * len(hdr)
  25. print(hdr)
  26. print(divider)
  27. for setting, path in SETTINGS.items():
  28. try:
  29. with open(SYS_CPU_SETTING.format(cpu=cpu, setting=path), 'r') as f:
  30. value = f.read().strip()
  31. except IOError:
  32. pass
  33. print('{}:\t{}'.format(setting, value))
  34. node = -1
  35. try:
  36. nodes = glob.glob(SYS_CPU_SETTING.format(cpu=cpu, setting='node*'))
  37. if len(nodes) is not 1:
  38. node = -1
  39. else:
  40. node = int(nodes[0]\
  41. [len(SYS_CPU_SETTING.format(cpu=cpu, setting='node')):])
  42. except IOError:
  43. node = -1
  44. print('NUMA Node: {}'.format(node))
  45. print('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement