a „oe”ã@sÆdZddlZddlZejZiZddd„Zddejdfdd„Zddejddfdd „Zd d „Z d d „Z e dej fdd„Z e dkrÂe ƒedƒZededed�ƒedeedƒedƒƒƒedƒe ƒdS)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. éNc Cs”ts€ddl}ddl}| |jd¡}|d}tdt|ƒddƒD]@}zt||ƒ}WntyhYq>Yn0|t||d  ¡<q>t   |t|  ¡¡S)Nrz Counter 009éé) Úcounter_english_mapÚwin32apiÚwin32conZRegQueryValueExÚHKEY_PERFORMANCE_DATAÚrangeÚlenÚintÚ ValueErrorÚlowerÚwin32pdhZLookupPerfNameByIndex)Z english_nameZ machine_namerrZcounter_reg_valueZ counter_listÚiZ counter_id©rú7C:\Program Files\Certbot\pkgs\win32\lib\win32pdhutil.pyÚfind_pdh_counter_localized_name!s ÿ   ÿréÿÿÿÿc CsŽt |||d||f¡}t ¡}z^t ||¡}z6t |¡t ||¡\} } | Wt |¡Wt |¡St |¡0Wt |¡n t |¡0dS)N)r ÚMakeCounterPathÚ OpenQueryÚ AddCounterÚCollectQueryDataÚGetFormattedCounterValueÚ RemoveCounterÚ CloseQuery) ÚobjectÚcounterÚinstanceÚinumÚformatÚmachineÚpathÚhqÚhcÚtypeÚvalrrrÚGetPerformanceAttributes5s    þ ür%c Csâ|durtd|ƒ}|dur$td|ƒ}|r8t d|dd¡| ¡}t dd|d¡\}}i}|D]4} z|| d|| <Wq\tyŽd|| <Yq\0q\g} | ¡D]>\} } t| dƒD](} |  ¡|kr²|  t ||| | ||ƒ¡q²qž| S)zÑFind 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. NÚProcessú ID Processrrr) rr Z EnumObjectsr ÚEnumObjectItemsÚKeyErrorÚitemsrÚappendr%) Z instanceNamerrrrZbRefreshr*Ú instancesÚ instance_dictrÚretÚ max_instancesrrrrÚFindPerformanceAttributesByNameOs0      ÿÿr0c Csftdƒ}t dd|tj¡\}}i}|D]4}z||d||<Wq&tyXd||<Yq&0q&tdƒg|dd…}tdd |¡ƒ| ¡D]Ö\}}t|dƒD]À}t  ¡}g}|D],} t  d||d|| f¡} |  t  || ¡¡q²t  |¡t d¡t  |¡td |dd …d d �|D]2} t | tj¡\} } td | d d �t | ¡�qtƒt |¡qžqŠdS)Nr&rrr'éz Process Nameú,g{®Gáz„?z%-15s éú )Úendz%5d)rr r(ÚPERF_DETAIL_WIZARDr)ÚprintÚjoinr*rrrr+rrÚtimeÚsleeprÚ PDH_FMT_LONGrr)rr*r,r-rr/rr!ZhcsÚitemr r"r#r$rrrÚShowAllProcessesxs> ÿ ÿ   r=c Cs^|D]T}t |¡\}}}}}}t||||tj|ƒ}td||ƒtd||||||fƒqdS)NzValue of '%s' iszDAdded '%s' on object '%s' (machine %s), instance %s(%d)-parent of %sr)r ZParseCounterPathr%ZPDH_FMT_DOUBLEr7) ZcountersrrrrZparentInstanceÚindexZ counterNameÚresultrrrÚBrowseCallBackDemo£s&ùÿÿÿr@zPython BrowsercCstjdd|||dd�dS)NrT)ZReturnMultiple)r ZBrowseCounters)ÚcallbackÚtitleÚlevelrrrÚbrowseºsrDÚ__main__z Virtual ByteszVirtual Bytes = Zpython)rzAvailable Bytes = ZMemoryzAvailable ByteszBrowsing for counters...)N)Ú__doc__r9r Úerrorrrr;r%r0r=r@r6rDÚ__name__rr7rrrrÚsD  ÿ ú )+ý  ÿþþ