a Z^@sddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z dZ dZ de e dZdZdZGd d d ZdS) N)support) print_warningi <zDSOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguagec@sReZdZdZddZddZddZdd d Zd d Zd dZ ddZ ddZ dS)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_popenstartselfr2/usr/lib64/python3.9/test/libregrtest/win_utils.py__init__$s zWindowsLoadTracker.__init__c Csdtt}tj}|tjO}|tjO}t||tjdt t tj tj |_ t |tjdtj tjdtj }t|d}tj|j dd}|d|}d|dttg}tjd||tjd |_t|dS) Nz\\.\pipe\typeperf_output_rrT) overlappedZtypeperfz-si )stdoutcwd)struuidZuuid4_winapiZPIPE_ACCESS_INBOUNDZFILE_FLAG_FIRST_PIPE_INSTANCEZFILE_FLAG_OVERLAPPEDZCreateNamedPipeZ PIPE_WAITBUFSIZEZNMPWAIT_WAIT_FOREVERZNULLpipeZ CreateFileZ GENERIC_WRITEZ OPEN_EXISTINGmsvcrtopen_osfhandleZConnectNamedPipeGetOverlappedResult_get_counter_nameSAMPLING_INTERVAL subprocessPopenjoinrZSAVEDCWDr osclose)rZ pipe_nameZ open_modeZpipe_write_endZcommand_stdoutZoverlapZ counter_nameZcommandrrrr +s&      zWindowsLoadTracker.startcCsvttjt }t|dd}Wdn1s40Yt|}tt||}|d}|d}d|d|dS)NCounterr2Z44z"\\")winregOpenKeyHKEY_LOCAL_MACHINECOUNTER_REGISTRY_KEYZ QueryValueExiterdictzip)rZperfkeyZcountersZ counters_dictsystemZprocess_queue_lengthrrrrMs.z$WindowsLoadTracker._get_counter_nameTcCs6|jdurdSd|_|r"|j|jd|_dSN)r r killwait)rr3rrrr%\s   zWindowsLoadTracker.closecCs |dSr2)r%rrrr__del__gszWindowsLoadTracker.__del__cCsN|d}t|dkrt|d}|dr6|ds:t|dd}t|S)N,rr))splitlen ValueError startswithendswithfloat)rlinetokensvaluerrr _parse_linejs   zWindowsLoadTracker._parse_linecCst|jtd\}}|d\}}|dkr.dS|}|dd}|j|}|d}z| |dWnt y| d|_Yn0d|_|S) NTFrrZoemreplacer8r) rZReadFilerrr getbufferdecoder splitlinesrBr;pop)rr_Z bytes_readresoutputlinesrrr _read_linesxs    zWindowsLoadTracker._read_linesc Cs |jdurdS|j}|dur0|jdddSz |}WntyX|YdS0|D]}|}d|vrtq^|szq^z||}Wn"tytd|Yq^Yn0|j dur|j t |dt |_ q^t |j t kr|j |q^t|j t |j |_ q^|j S)NF)r3zPDH-CSVz#Failed to parse typeperf output: %ag?)r pollr%rLBrokenPipeErrorrstriprBr;rr LOAD_FACTOR_1r:r NVALUEappendsum)r returncoderKr?Zprocessor_queue_lengthrrr getloadavgs<          zWindowsLoadTracker.getloadavgN)T) __name__ __module__ __qualname____doc__rr rr%r5rBrLrUrrrrrs" r)rmathrr$r!rr*testrZtest.libregrtest.utilsrrr exprPrQr-rrrrrs