Red de conocimiento informático - Problemas con los teléfonos móviles - ¿Existe algún Python que pueda obtener la tasa de inactividad de cada núcleo de CPU?

¿Existe algún Python que pueda obtener la tasa de inactividad de cada núcleo de CPU?

¿Necesito instalar la biblioteca psutil?

importar?sys

importar?os

importar?atexit

importar?time

importar?psutil

#print?"Bienvenido, el sistema actual es","os.name","Comenzó 3 segundos tarde","os.name","Comenzó a recibir datos 3 segundos tarde... . ..."

tiempo.sleep(3)

line_num?=?1

#función?de?Obtener?CPU?Estado;

p>

def?getCPUstate(intervalo=1): return?("??CPU:?") ?str(psutil.cpu_percent(intervalo)?"")

# función ?de?Obtener?Memoria

def?getMemorystate(): phymem?=?psutil.virtual_memory() línea?=?"Memoria: ?5s?6s/s"( phymem.percent, str( int (phymem.used/1024/1024)) "M", str(int(phymem.total/1024/1024)) "M" ) return?line

def?bytes2human(n): " " ""? gt;gt;gt;?bytes2human(10000)? '9.8?K'? gt;gt;gt;?bytes2human(100001221)? '95.4?M'? """ ¿Símbolo ('K', ?M',?M',?'G',?'P',?E',?Z',?Y') prefijo?=?{} para?i,?s?en?enumerar(símbolos): prefijo [s]? =?1?lt;lt;?(i 1)*10 para?/?prefijo[s] retorno?'.2f?s'?(valor,?s) retorno?(valor,?s ) Return?'.2f?B'?(n)

def?poll(interval): """¿Recuperar?raw?stats?dentro?de?un?interval?window."" tot_before?=? psutil .net_io_ counters() pnic_before?=?psutil.net_io_counters(pernic=True) #?dormir algún tiempo time.sleep(interval) tot_after?=?psutil.net_io_counters() pnic_after?=?psutil.net_io_counters(pernic=True) # ?Obtener memoria Memory_state?=?getMemorystate() return?(tot_before,?tot_after,?pnic_before,?pnic_after,cpu_state,memory_state)

def?refresh_window(tot_before,?tot_after,? pnic_antes

,?pnic_after,cpu_state,memory_state)

def?pnic_after,cpu_state,memory_state): if?os.name?==?nt': os.system("cls") más: os.system("clear") """Imprimir?estadísticas?en?pantalla."" #imprimir?hora?actual?#cpu?estado?#memoria print(time.asctime() "?|?" cpu_state "? |?" #?totals print("?NetStates:") print("total?bytes:?enviado:?-10s?recibido:?s"?(bytes2human(tot_after.bytes_sent), bytes2human(tot_after.bytes_recv)) ) print("total?packets:?sent:?-10s?received:?s"?(tot_after.packets_sent, ?tot_after.packets_recv) ) #"Detalles de cada interfaz de red:" Ordenemos las interfaces de red, para que #network las interfaces que generan más tráfico se muestran al frente print("") nic_names?=?pnic_after.keys() #nic_names.sort(key=lambda?x:?sum(pnic_ after[x]),?reverse =True) for?-15s?15s?15s" print(templ?? (nombre,?" TOTAL",?" POR-SEC")) print(templ?? ("bytes-enviados", bytes2human(stats_after.bytes_sent), bytes2human (stats_after.bytes_sent?-?stats_before.bytes_sent)? ?'/( "bytes-recv", bytes2human(stats_after.bytes_recv), bytes2human(stats_after.bytes_recv?-?stats_before.bytes_recv)? ?'/s' , )) print(templ?? ( "pkts-sent", stats_after.packets_sent, stats_after.packets_sent?-?stats_before.packets_sent, )) print(templ?? ( "pkts-recv", stats_after.packets_recv, stats_after.packets_recv ?-? stats_before.packets_recv, )) print("")

intenta: ¿intervalo?=?0 mientras?