oi UdZddlmZddlZddlZejZiZded<ddZddej dfdZ ddej ddfd Z d Z d Z e d ejfd Zedkrke edZede deede ededededSdS)aUtilities for the win32 Performance Data Helper module Example: To get a single bit of data: >>> import win32pdhutil >>> win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes") 6053888 >>> win32pdhutil.FindPerformanceAttributesByName("python", counter="Virtual Bytes") [22278144] First example returns data which is not associated with any specific instance. The second example reads data for a specific instance - hence the list return - it would return one result for each instance of Python running. In general, it can be tricky finding exactly the "name" of the data you wish to query. Although you can use (None,None,(eg)"Memory", -1) to do this, the easiest way is often to simply use PerfMon to find out the names. ) annotationsNzdict[str, int]counter_english_mapctsddl}ddl}||jd}|d}t dt |dz dD]N} t||}n#t$rY%wxYw|t||dz <Otj |t| S)Nrz Counter 009) rwin32apiwin32conRegQueryValueExHKEY_PERFORMANCE_DATArangelenint ValueErrorlowerwin32pdhLookupPerfNameByIndex) english_name machine_namerr counter_reg_value counter_listi counter_ids FC:\PYTHON\Scheduler\python\Lib\site-packages\win32/lib/win32pdhutil.pyfind_pdh_counter_localized_namer#s  J$44  *M  )+ q#l++a/33 J JA  a11     ?I  QU 3 9 9 ; ; < <  )),*<*<*>*>?  sA-- A:9A:ctj|||d||f}tj} tj||} tj|tj||\} } | tj|tj|S#tj|wxYw#tj|wxYwN)rMakeCounterPath OpenQuery AddCounterCollectQueryDataGetFormattedCounterValue RemoveCounter CloseQuery) objectcounterinstanceinumformatmachinepathhqhctypevals rGetPerformanceAttributesr07s  #WfhdG$T U UD    B   T * * '  %b ) ) ) 9"fEEID#  "2 & & &B  "2 & & & &Bs#B4-B2B4B11B44C c |td|}|td|}|rtjd|dd|}tjdd|d\}}i}|D](} || xxdz cc<#t $rd|| <Y%wxYwg} |D]Y\} } t| dzD]A} | |kr'| t||| | ||BZ| S)zFind performance attributes by (case insensitive) instance name. Given a process name, return a list with the requested attributes. Most useful for returning a tuple of PIDs given a process name. NProcess ID Processrrr) rr EnumObjectsrEnumObjectItemsKeyErroritemsr appendr0) instanceNamer%r&r)r*bRefreshr7 instances instance_dictr'ret max_instancesr(s rFindPerformanceAttributesByNamer?Qso~0GDD1,HH2T7Aq111%%''L/dFBGGE9M(( ( ( # # #q ( # # # # ( ( (&'M( # # # ( C#0#6#6#8#8--!+,,  D~~<// ,4  Js3BBBc td}tjdd|tj\}}i}|D](} ||xxdz cc<#t$rd||<Y%wxYwtdg|ddz}t dd||D]B\}}t|dzD](}tj }g}|D]D} tj d||d|| f} | tj || Etj |tjdtj |t d |dd zd |D]L} tj| tj\} } t d | zd tj| Mt tj|*DdS)Nr2rrr3z Process Name,g{Gz?z%-15s  )endz%5d)rrr5PERF_DETAIL_WIZARDr6printjoinr7r rrr8r r!timesleepr" PDH_FMT_LONGr#r$)r%r7r;r<r'r>r(r,hcsitemr+r-r.r/s rShowAllProcessesrNzsG ,Y 7 7F/ dFH7E9M(( ( ( # # #q ( # # # # ( ( (&'M( # # # (-\ : : ;eBQBi GE .#((5//***#0#6#6#8#8$$--!+,, $ $D#%%BC : :/68T4> 8.r4889999  %b ) ) ) Jt     %b ) ) ) )x}-3 7 7 7 7 + +$=b(BWXX cesm----&r**** GGG   # # # #' $$$sA  AAc |D]f}tj|\}}}}}}t||||tj|}t d|z|t d||||||fzgdS)NzValue of '%s' iszDAdded '%s' on object '%s' (machine %s), instance %s(%d)-parent of %sr)rParseCounterPathr0PDH_FMT_DOUBLErG) countersr&r*r%r'parentInstanceindex counterNameresults rBrowseCallBackDemorWs    %g . .      * K5(2I7    7*F333 RFGXunM N     1zPython Browserc:tjdd|||ddS)NrT)ReturnMultiple)rBrowseCounters)callbacktitlelevels rbrowser_s(  D!XueDQQQQQQrX__main__z Virtual ByteszVirtual Bytes = python)r&zAvailable Bytes = MemoryzAvailable ByteszBrowsing for counters...r)__doc__ __future__rrIrerrorr__annotations__rrKr0r?rNrWrFr___name__r&rGrXrris(#"""""  ')((((*#H4ISW    8      &&&&R$$$$$$V   0   %RRRR z--o>>G E;;HgVVV E  + +H 5 5 + +,= > >   E $%%% FHHHHH!rX