h _@sddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z dZ dZ de e dZdZdZGd d d ZdS) N) os_helper) print_warningi <zDSOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguagec@sPeZdZ ddZddZddZddd Zd d Zd d ZddZ ddZ dS)WindowsLoadTrackercCs$g|_d|_d|_d|_|dS)N)_values_load_buffer_popenstartselfr3/usr/lib64/python3.10/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_lengthrrrrOs.z$WindowsLoadTracker._get_counter_nameTcCs6|jdurdSd|_|r"|j|jd|_dSN)r r killwait)rr3rrrr%^s    zWindowsLoadTracker.closecCs |dSr2)r%rrrr__del__is zWindowsLoadTracker.__del__cCsN|d}t|dkrt|d}|dr6|ds:t|dd}t|S)N,rr))splitlen ValueError startswithendswithfloat)rlinetokensvaluerrr _parse_linels   zWindowsLoadTracker._parse_linecCst|jtd\}}|d\}}|dkr.dS|}|dd}|j|}|d}z| |dWn t y| d|_Y|S0d|_|S) NTFrrZoemreplacer8r) rZReadFilerrr getbufferdecoder splitlinesrBr;pop)rr_Z bytes_readresoutputlinesrrr _read_lineszs"    zWindowsLoadTracker._read_linesc Cs|jdurdS|j}|dur0|jdddSz |}WntyX|YdS0|D]}|}d|vrtq^|szq^z||}Wntytd|Yq^0|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__rr rr%r5rBrLrUrrrrrs$   r)rmathrr$r!rr*Z test.supportrZtest.libregrtest.utilsrrr exprPrQr-rrrrrs