Skip to content

Instantly share code, notes, and snippets.

@fernandog
Created October 17, 2016 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandog/d330f87b19c2ace350110cb697504fc2 to your computer and use it in GitHub Desktop.
Save fernandog/d330f87b19c2ace350110cb697504fc2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Authork: http://github.com/fernandog
import os
# Read value from vcgencmd
_throttled = os.popen('vcgencmd get_throttled').read()
# Turn into list at return
_throttled = _throttled.split("\n")
# Filter empty strings
_throttled = filter(len, _throttled)
# Split into key/value dict
_throttled = dict(item.split("=") for item in _throttled)
throttled = int(_throttled.get('throttled'), 16)
print "Throttled: {}".format(_throttled.get('throttled'))
"""
18: throttling has occurred
17: arm frequency capped has occurred
16: under-voltage has occurred
2: currently throttled
1: arm frequency capped
0: under-voltage
1000000000000000000 = 0x40000
0100000000000000000 = 0x20000
0010000000000000000 = 0x10000
0000000000000000100 = 0x4
0000000000000000010 = 0x2
0000000000000000001 = 0x1
"""
throttling_occurred = (throttled & 0x40000) >> 18
arm_frequency_capped_occurred = (throttled & 0x20000) >> 17
under_voltage_occurred = (throttled & 0x10000) >> 16
currently_throttled = (throttled & 0x4) >> 2
arm_frequency_capped = (throttled & 0x2) >> 1
under_voltage = (throttled & 0x1)
results = {
'throttling_occurred': throttling_occurred,
'arm_frequency_capped_occurred': arm_frequency_capped_occurred,
'under_voltage_occurred': under_voltage_occurred,
'currently_throttled': currently_throttled,
'arm_frequency_capped': arm_frequency_capped,
'under_voltage': under_voltage,
}
print results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment