HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/libregrtest/__pycache__/win_utils.cpython-37.opt-1.pyc
B

��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�6/usr/local/lib/python3.7/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}WdQRXt|�}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)rr0rrrr#\s


zWindowsLoadTracker.closecCs|��dS)N)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�}y|�	|d�Wn t
k
r�|�d�|_YnXd|_|S)	NTFrrZoem�replacer5r)rZReadFilerrr�	getbuffer�decoder�
splitlinesr?r8�pop)rr�_Z
bytes_readZres�output�linesrrr�_read_linesxs

zWindowsLoadTracker._read_linesc	Cs|jdkrdS|j��}|dk	r0|jdd�dSy|��}Wntk
rX|��dSXx�|D]�}|��}d|krvq`|s|q`y|�|�}Wn"tk
r�td|�w`YnX|j	dk	r�|j	t
|dt
|_	q`t|j�t
kr�|j�|�q`t|j�t|j�|_	q`W|j	S)NF)r0zPDH-CSVz#Failed to parse typeperf output: %ag�?)rZpollr#rH�BrokenPipeError�rstripr?r8rr
�
LOAD_FACTOR_1r7r	�NVALUE�append�sum)r�
returncoderGr<Zprocessor_queue_lengthrrr�
getloadavg�s:



zWindowsLoadTracker.getloadavgN)T)�__name__�
__module__�__qualname__�__doc__rr
rr#r2r?rHrPrrrrrs"
r)rZmathrr"rrr(ZtestrZtest.libregrtest.utilsrrrZexprKrLr+rrrrr�<module>s