o
    vaZ                     @   sH   d Z ddlmZ ddlmZ dddddd	ddgZG d
d deZdS )zPer-CPU plugin.    )cpu_percent)GlancesPluginuserzUser CPU usage%)namedescriptionZy_unitsystemzSystem CPU usagec                       sH   e Zd ZdZd fdd	Zdd Zejejdd Z	dd	d
Z
  ZS )Pluginz~Glances per-CPU plugin.

    'stats' is a list of dictionaries that contain the utilization percentages
    for each CPU.
    Nc                    s"   t t| j||tg d d| _dS )zInit the plugin.)argsconfigitems_history_listZstats_init_valueTN)superr	   __init__r   Zdisplay_curse)selfr
   r   	__class__ @/usr/lib/python3/dist-packages/glances/plugins/glances_percpu.pyr   )   s   
zPlugin.__init__c                 C   s   dS )zReturn the key of the list.Z
cpu_numberr   )r   r   r   r   get_key3   s   zPlugin.get_keyc                 C   s.   |   }| jdkrtjdd}n	 || _| jS )z,Update per-CPU stats using the input method.ZlocalT)percpu)Zget_init_valueZinput_methodr   getstats)r   r   r   r   r   update7   s   
zPlugin.updatec                 C   sJ  g }| j r| jjr|  r|S | dr"dd}|| |d dD ]}|| j d vr.q$d|}|| | q$| j D ]c}||   | drmz	d|d	 }W n tyd   d
d}Y nw || | dD ]2}|| j d vryqoz	d|| }W n ty   d
d}Y nw || || j	|| |d qoq?|S )z2Return the dict to display in the curse interface.Z	quicklookz{:7}zPER CPUZTITLE)r   r   ZidleZiowaitZstealr   z{:>7}z{:6.1f}%totalz{:>6}%?)header)
r   r
   r   Zis_disabledformatappendZcurse_add_lineZcurse_new_line	TypeErrorZ	get_alert)r   r
   Z	max_widthretmsgstatZcpur   r   r   	msg_curseK   sF   






zPlugin.msg_curse)NN)__name__
__module____qualname____doc__r   r   r   Z_check_decoratorZ_log_result_decoratorr   r"   __classcell__r   r   r   r   r	   "   s    
r	   N)r&   Zglances.cpu_percentr   Zglances.plugins.glances_pluginr   r   r	   r   r   r   r   <module>   s   