def read_cpu_temp(): global thermalzone res = 0 if thermalzone == -1: thermalzone = 0 for i in range(20): try: if os.path.exists("/sys/class/thermal/thermal_zone" + str(i) + "/type"): with open('/sys/class/thermal/thermal_zone' + str(i) + '/type') as fp: tstr = fp.readline() if (tstr.find("cpu") >= 0) or (tstr.find("x86") >= 0) or ( tstr.find("bcm") >= 0): thermalzone = i break except: pass elif thermalzone == -2: res = read_cpu_temp_sensor() return res try: with open('/sys/devices/virtual/thermal/thermal_zone' + str(thermalzone) + '/temp') as fp: res = fp.readline() except: res = 0 thermalzone = -2 therm2 = misc.str2num2(res) # print("D:",therm2,thermalzone) if therm2 > 300: therm2 = misc.str2num2(therm2 / 1000) return therm2
def read_cpu_usage(): try: cpu_a_prev = round( float( os.popen( '''grep 'cpu ' /proc/stat | awk '{usage=($1+$2+$3+$7+$8)} END {print usage }' ''' ).readline()), 2) cpu_t_prev = round( float( os.popen( '''grep 'cpu ' /proc/stat | awk '{usage=($1+$2+$3+$7+$8+$4+$5)} END {print usage }' ''' ).readline()), 2) except: cpu_a_prev = 0 cpu_t_prev = 0 time.sleep(0.2) try: cpu_a_cur = round( float( os.popen( '''grep 'cpu ' /proc/stat | awk '{usage=($1+$2+$3+$7+$8)} END {print usage }' ''' ).readline()), 2) cpu_t_cur = round( float( os.popen( '''grep 'cpu ' /proc/stat | awk '{usage=($1+$2+$3+$7+$8+$4+$5)} END {print usage }' ''' ).readline()), 2) except: cpu_a_cur = 0 cpu_t_cur = 1 cpu_util = misc.str2num2(100 * (cpu_a_cur - cpu_a_prev) / (cpu_t_cur - cpu_t_prev)) return cpu_util
def read_cpu_temp(): global thermalzone if thermalzone == -1: thermalzone = 0 for i in range(20): if os.path.exists("/sys/class/thermal/thermal_zone"+str(i)+"/type"): tstr = os.popen('/bin/cat /sys/class/thermal/thermal_zone'+str(i)+'/type').read() if (tstr.find("cpu")>=0) or (tstr.find("x86")>=0) or (tstr.find("bcm") >= 0): thermalzone = i break try: res = os.popen('cat /sys/devices/virtual/thermal/thermal_zone'+str(thermalzone)+'/temp').readline() except: res = "0" therm2 = misc.str2num2(res) if therm2 > 300: therm2 = misc.str2num2(therm2 /1000) return therm2