
    Rh?                         d dl Z d dlZd dlZd dlZd dlZd dlZdZd ej                  edz        z  ZdZ	 G d d      Z
y)    N   <      c                       e Zd ZdZd Zej                  ej                  fdZ	e
j                  e
j                  ej                  fdZd	dZej                  ej"                  ej                  fdZd Zy)
WindowsLoadTrackerz
    This class asynchronously reads the performance counters to calculate
    the system load on Windows.  A "raw" thread is used here to prevent
    interference with the test suite's cases for the threading module.
    c                 8   d | _         d | _        t        j                  t        j                         g | _        d | _        t        j                  d ddd       | _         t        j                  d ddd       | _        t        j                  | j                  di        y )NTF )_running_stoppedwinregQueryInfoKeyHKEY_PERFORMANCE_DATA_values_load_overlappedCreateEvent_threadstart_new_thread_update_loadselfs    1/usr/lib/python3.12/test/libregrtest/win_utils.py__init__zWindowsLoadTracker.__init__   s|     	F889
#//dE4H#//dE4H  !2!2B;    c                      || j                   d      r$| j                           || j                   d      r$ || j                         y )Ni  )r
   _calculate_loadr   )r   _wait_signals      r   r   zWindowsLoadTracker._update_load*   s<    
 DMM4(  " DMM4( 	r   c                     ||d      \  }} |d|d      \  } |d||      \  }}||z   }	||z   }
|
|	k  r0 |d||
      \  }}}|
|z  }
|dk(  r|	|z   } |d||      \  }n|
|	k  r0y | j                   &| j                   t        z  |dt        z
  z  z   | _         y t        | j                        t        k  r| j                  j                  |       y t        | j                        t        | j                        z  | _         y )N2L   4xLLLL28xL,   g      ?)r   LOAD_FACTOR_1lenr   NVALUEappendsum)r   _query_hkey_unpackdata_	obj_start
data_start
defn_start	data_base	defn_basesizeidxoffsetcounter_offsetprocessor_queue_lengths                   r   r   z"WindowsLoadTracker._calculate_load4   s    $a S$+
	 ")y!A
J
*	
*	)# !($	 BD#vIby!*V!3*1#t^*L'& )#  ::!**}44}9LMNDJ'LL 67T\\*S->>DJr   c                 $    | j                          y N)__del__)r   kills     r   closezWindowsLoadTracker.closel   s    r   c                     | j                   X || j                           || j                  d        || j                           || j                         d x| _         | _        y y )N)r
   r   )r   r   _closer   s       r   r<   zWindowsLoadTracker.__del__p   sS    
 ==$DMM"$--$4==!4==!,00DMDM %r   c                     | j                   S r;   )r   r   s    r   
getloadavgzWindowsLoadTracker.getloadavg   s    zzr   N)T)__name__
__module____qualname____doc__r   _winapiWaitForSingleObjectr   SetEventr   r   QueryValueExr   structunpack_fromr   r>   CloseHandler<   rC   r	   r   r   r   r      st    <$ #66(11  &22$:: & 2 2	6?p 11**#,,	1r   r   )r   r   rH   mathrL   r   SAMPLING_INTERVALexpr&   r(   r   r	   r   r   <module>rR      sO            HDHH.344 
m mr   