h ²ƒÎ_c@s„ddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z dZ dZ de  e d¡ZdZdZGd d „d ƒZdS) éN)Ú os_helper)Ú print_warningi éi<izDSOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguagec@sPeZdZ dd„Zdd„Zdd„Zddd „Zd d „Zd d „Zdd„Z dd„Z dS)ÚWindowsLoadTrackercCs$g|_d|_d|_d|_| ¡dS)NÚ)Ú_valuesÚ_loadÚ_bufferÚ_popenÚstart©Úself©r ú3/usr/lib64/python3.10/test/libregrtest/win_utils.pyÚ__init__$s  ÿ€zWindowsLoadTracker.__init__c CsÎdtt ¡ƒ}tj}|tjO}|tjO}t ||tjdt t tj tj ¡|_ t  |tjdtj tjdtj ¡}t |d¡}tj|j dd}| d¡| ¡}d|dttƒg}tjd |¡|tjd |_t |¡dS) Nz\\.\pipe\typeperf_output_rrT)Ú overlappedZtypeperfz-siz )ZstdoutZcwd)ZstrÚ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Ú subprocessZPopenZjoinrZSAVEDCWDr ÚosÚclose)r Z pipe_nameZ open_modeZpipe_write_endZcommand_stdoutZoverlapZ counter_nameZcommandr r rr +s.  þ  þ   þÿ€zWindowsLoadTracker.startcCsvt tjt¡ }t |d¡d}Wdƒn1s40Yt|ƒ}tt||ƒƒ}|d}|d}d|›d|›dS)NZCounterrZ2Z44z"\z\ú")ÚwinregZOpenKeyZHKEY_LOCAL_MACHINEÚCOUNTER_REGISTRY_KEYZ QueryValueExZiterZdictZzip)r ZperfkeyZcountersZ counters_dictZsystemZprocess_queue_lengthr r rrOs.ÿ€z$WindowsLoadTracker._get_counter_nameTcCs6|jdurdSd|_|r"|j ¡|j ¡d|_dS©N)r rÚkillZwait)r r r r rr^s    ÿ€zWindowsLoadTracker.closecCs | ¡dSr)rr r r rÚ__del__is ÿ€zWindowsLoadTracker.__del__cCsN| d¡}t|ƒdkrt‚|d}| d¡r6| d¡s:t‚|dd…}t|ƒS)Nz,irréÿÿÿÿ)ZsplitÚlenÚ ValueErrorZ startswithZendswithZfloat)r ÚlineZtokensZvaluer r rÚ _parse_linels   ÿ€zWindowsLoadTracker._parse_linecCs”t |jtd¡\}}| d¡\}}|dkr.dS| ¡}| dd¡}|j|}| d¡}z|  |d¡Wn t yˆ|  d¡|_Y|S0d|_|S) NTFrr ZoemZreplacer"r) rZReadFilerrrZ getbufferZdecoderZ splitlinesr&r$Zpop)r rZ_Z bytes_readZresZoutputÚlinesr r rÚ _read_lineszs"    üÿ€zWindowsLoadTracker._read_linesc Cs|jdurdS|j ¡}|dur0|jdddSz | ¡}WntyX| ¡YdS0|D] }| ¡}d|vrtq^|szq^z| |¡}Wnty¦td|ƒYq^0|j durÌ|j t |dt |_ q^t |j ƒt krè|j  |¡q^t|j ƒt |j ƒ|_ q^|j S)NF)r zPDH-CSVz#Failed to parse typeperf output: %agð?)r Zpollrr(ZBrokenPipeErrorZrstripr&r$rrÚ LOAD_FACTOR_1r#rÚNVALUEZappendZsum)r Z returncoder'r%Zprocessor_queue_lengthr r rÚ getloadavg“s>         ÿÿ€zWindowsLoadTracker.getloadavgN)T) Z__name__Z __module__Z __qualname__rr rrr!r&r(r+r r r rrs$   ÿ€r)rZmathrrrrrZ test.supportrZtest.libregrtest.utilsrrrZexpr)r*rrr r r rZs   ÿ€