
    	h              	      r   % S r SSKJr  SSKrSSKr\R
                  r0 rS\S'   SS jrSS\R                  S4S jr
SS\R                  SS4S	 jrS
 rS r\S\R                  4S jr\S:X  aI  \" 5         \" S5      r\" S\" S\S95        \" S\
" \" S5      \" S5      5      5        \" S5        \" 5         gg)a  Utilities 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 <om win32pdh.EnumObjectItems>(None,None,(eg)"Memory", -1) to do this,
  the easiest way is often to simply use PerfMon to find out the names.
    )annotationsNzdict[str, int]counter_english_mapc                x   [         (       ds  SS KnSS KnUR                  UR                  S5      nUS   n[        S[        U5      S-
  S5       H-  n [        XV   5      nU[         XVS-      R                  5       '   M/     [        R                  " U[         U R                  5          5      $ ! [         a     Mj  f = f)Nr   zCounter 009      )r   win32apiwin32conRegQueryValueExHKEY_PERFORMANCE_DATArangelenint
ValueErrorlowerwin32pdhLookupPerfNameByIndex)english_namemachine_namer   r	   counter_reg_valuecounter_listi
counter_ids           iC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\win32/lib/win32pdhutil.pyfind_pdh_counter_localized_namer   #   s    $44**M
 )+q#l+a/3A 1
 @JU 3 9 9 ;< 4 ))),*<*<*>?   s   B++
B98B9c                   [         R                  " XPUS X145      n[         R                  " 5       n [         R                  " Xv5      n [         R                  " U5        [         R
                  " X5      u  pU
[         R                  " U5        [         R                  " U5        $ ! [         R                  " U5        f = f! [         R                  " U5        f = fN)r   MakeCounterPath	OpenQuery
AddCounterCollectQueryDataGetFormattedCounterValueRemoveCounter
CloseQuery)objectcounterinstanceinumformatmachinepathhqhctypevals              r   GetPerformanceAttributesr0   7   s     ##Whd$TUD				B	   *	'%%b) 99"EID""2&B ""2&Bs#   B? /B$ 7B? $B<<B? ?Cc                   Uc  [        SU5      nUc  [        SU5      nU(       a  [        R                  " SUSS5        U R                  5       n [        R                  " SSUS5      u  pg0 nU H  n	 X==   S-  ss'   M     / n
UR                  5        HL  u  p[        US-   5       H5  nU	R                  5       U :X  d  M  U
R                  [        XXX45      5        M7     MN     U
$ ! [
         a    SX'    M  f = f)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.
NProcess
ID Processr   r   r   )
r   r   EnumObjectsr   EnumObjectItemsKeyErroritemsr   appendr0   )instanceNamer%   r&   r)   r*   bRefreshr7   	instancesinstance_dictr'   retmax_instancesr(   s                r   FindPerformanceAttributesByNamer?   Q   s    ~0GD1,HT7Aq1%%'L//dFBGEM	(#q(#  C#0#6#6#8-!+,D~~</

, - $9 J  	(&'M#	(s   2C&&C87C8c                    [        S5      n [        R                  " S S U [        R                  5      u  p0 nU H  n X4==   S-  ss'   M     [        S5      /US S -   n[        SSR                  U5      5        UR                  5        GHA  u  pE[        US-   5       GH(  n[        R                  " 5       n/ nU HB  n	[        R                  " S XS Xi45      n
UR                  [        R                  " Xz5      5        MD     [        R                  " U5        [        R                  " S5        [        R                  " U5        [        S	US S
 -  SS9  U HM  n[        R                   " U[        R"                  5      u  p[        SU-  SS9  [        R$                  " U5        MO     [        5         [        R&                  " U5        GM+     GMD     g ! [         a	    SX4'    GM  f = f)Nr2   r   r   r3      zProcess Name,g{Gz?z%-15s	    )endz%5d)r   r   r5   PERF_DETAIL_WIZARDr6   printjoinr7   r   r   r   r8   r    r!   timesleepr"   PDH_FMT_LONGr#   r$   )r%   r7   r;   r<   r'   r>   r(   r,   hcsitemr+   r-   r.   r/   s                 r   ShowAllProcessesrN   z   s   ,Y7F//dFH77E M	(#q(#  -\:;eBQiGE	.#((5/*#0#6#6#8-!+,D##%BC//6T4> 

8..r89	 
 %%b) JJt%%b))x}-37$==b(BWBWX	esm-&&r*  G#' - $9  	(&'M#	(s   GG$#G$c           
         U  H\  n[         R                  " U5      u  nnnnnn[        X7XF[         R                  U5      n[	        SU-  U5        [	        SXsX$Xe4-  5        M^     g)NzValue of '%s' iszDAdded '%s' on object '%s' (machine %s), instance %s(%d)-parent of %sr   )r   ParseCounterPathr0   PDH_FMT_DOUBLErG   )	countersr&   r*   r%   r'   parentInstanceindexcounterNameresults	            r   BrowseCallBackDemorW      s     %%g.	
 *(2I2I7
 	 7*F3RGuMN	
 $     zPython Browserc           	     4    [         R                  " S SXUSS9  g )Nr   T)ReturnMultiple)r   BrowseCounters)callbacktitlelevels      r   browser_      s    
 D!XeDQrX   __main__zVirtual ByteszVirtual Bytes = python)r&   zAvailable Bytes = MemoryzAvailable ByteszBrowsing for counters...r   )__doc__
__future__r   rI   r   errorr   __annotations__r   rK   r0   r?   rN   rW   rF   r_   __name__r&   rG    rX   r   <module>ri      s   ( #  
 ') ^ (* #H4I4ISW 8   &R$$V0  


%
%R z-o>G	;HgV 
 +H5+,=>	
 

$%
H! rX   