+
    :i*                        R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHtHt  ^ RI	t	Rt
]
tR R ltR R	 lt ! R
 R4      tR#   ] d    Rt
 L%i ; i)a  
Memory monitoring utilities for measuring memory usage.

Example usage:
    tracker = MemoryTracker("my_function")
    with tracker.monitor():
        my_function()
    # Access data: tracker.rss_delta, tracker.duration, etc.
    # Get formatted string: tracker.get_summary()
)annotationsN)DictOptionalTFc                   V ^8  d   QhRR/# )   returnzOptional[int] )formats   "T/var/www/html/photoedit/myenv/lib/python3.14/site-packages/numba/misc/memoryutils.py__annotate__r      s      m     c                     \         '       d#    \        P                  ! 4       p V P                  # R#   \         d     R# i ; i)z
Get current available system memory in bytes.

Used for memory threshold checking in parallel test execution.

Returns:
    int or None: Available memory in bytes, or None if unavailable
N)_HAS_PSUTILpsutilvirtual_memory	available	Exception)sys_mems    r
   get_available_memoryr      sD     {	++-G$$$   		s    1 A A c                   V ^8  d   QhRR/# )r   r   zDict[str, Optional[int]]r   )r	   s   "r
   r   r   /   s     " "2 "r   c                    / p \         '       dn    \        P                  ! \        P                  ! 4       4      pVP                  4       pVP                  V R&   \        P                  ! 4       pVP                  V R&   RV 9  d   RV R&   RV 9  d   RV R&   V #   \        P                  \        P                  3 d     LAi ; i)a>  
Get memory usage information needed for monitoring.

Returns only RSS and available memory which are the fields
actually used by the MemoryTracker.

Returns:
    dict: Memory usage information including:
        - rss: Current process RSS (physical memory currently used)
        - available: Available system memory
rssr   N)r   r   Processosgetpidmemory_infor   r   r   NoSuchProcessAccessDenied)r   processmem_infor   s       r
   get_memory_usager    /   s     K{	nnRYY[1G**,H!)K ++-G'.'8'8K$ K!E+%#'K  $$f&9&9: 		s   A,B %B>=B>c                      ] tR t^Tt$ RtR]R&   R]R&   R]R&   R]R&   R	]R
&   R	]R&   R]R&   R]R&   R R lt]P                  R 4       t	R R lt
RtR# )MemoryTrackerz
A simple memory monitor that tracks RSS delta and timing.

Stores monitoring data in instance attributes for later access.
Each instance is typically used for monitoring a single operation.
intpidstrnamezfloat | None
start_timeend_timezDict[str, int | None] | Nonestart_memory
end_memorydurationz
int | None	rss_deltac                   V ^8  d   QhRR/# )r   r&   r%   r   )r	   s   "r
   r   MemoryTracker.__annotate__d   s     	 	S 	r   c                    \         P                  ! 4       V n        Wn        RV n        RV n        RV n        RV n        RV n        RV n	        R# )z6Initialize a MemoryTracker with empty monitoring data.N)
r   r   r$   r&   r'   r(   r)   r*   r+   r,   )selfr&   s   &&r
   __init__MemoryTracker.__init__d   s?    99;	 r   c              #    "   \         P                   ! 4       V n        \        4       V n         V x  \         P                   ! 4       V n        \        4       V n        V P                  V P                  ,
          V n        V P                  P                  R^ 4      pV P
                  P                  R^ 4      pV'       d   V'       d	   W!,
          M^ V n        R#   \         P                   ! 4       T n        \        4       T n        T P                  T P                  ,
          T n        T P                  P                  R^ 4      pT P
                  P                  R^ 4      pT'       d   T'       d   Y!,
          T n        i ^ T n        i ; i5i)a_  
Context manager to monitor memory usage during function execution.

Records start/end memory usage and timing, calculates RSS delta,
and stores all data in instance attributes.

Args:
    name (str): Name/identifier for the function or operation being
                monitored

Yields:
    self: The MemoryTracker instance for accessing stored data
r   N)	timer'   r    r)   r(   r*   r+   getr,   )r0   	start_rssend_rsss   &  r
   monitorMemoryTracker.monitoro   s      ))+,.	?J !IIKDM.0DO MMDOO;DM ))--eQ7Ioo))%3G!*w  '2<= N !IIKDM.0DO MMDOO;DM ))--eQ7Ioo))%3G!*w  '2DN<= Ns)   *FC BFFBE?)E??Fc                   V ^8  d   QhRR/# )r   r   r%   r   )r	   s   "r
   r   r.      s     4 4S 4r   c                X   V P                   e   V P                  f   \        R4      hV P                  P                  R4      pRR lp\        P
                  ! R\        P                  ! V P                  4      4      pV P                   P                  R^ 4      pV P                  P                  R^ 4      pRV P                   2RV P                   2RV 2R	V P                  R
 R2RV! V4       2RV! V4       2RV! V P                  RR7       2RV! V4       2.pRP                  V4      # )at  
Return a formatted summary of the memory monitoring data.

Formats the stored monitoring data into a human-readable string
containing name, PID, RSS delta, available memory, duration,
and start time.

Returns:
    str: Formatted summary string with monitoring results

Note:
    Should be called after monitor() context has completed
    to ensure all data is available.
z$Memory monitoring data not availabler   c                    V f   R# V ^ 8X  d   R# RpV'       d   V ^ 8  d   RMRp\        V 4      p R
 F  pV R8  d   V V R RV 2u # V R,          p K!  	  V V R R	2# )z&Convert bytes to human readable formatzN/Az0 B -+g      @z.2f z TB)BKBMBGB)abs)	bytes_val	show_signsignunits   &&  r
   format_bytes/MemoryTracker.get_summary.<locals>.format_bytes   s{     A~D'!msII/v%"VIc?!D6::V#	 0 VIc?#..r   z%H:%M:%Sr   zName: zPID: zStart: z
Duration: z.3fszStart RSS: z	End RSS: zRSS delta: T)rG   zAvail memory: z | )F)r)   r*   
ValueErrorr5   r4   strftime	localtimer'   r&   r$   r+   r,   join)r0   current_availablerJ   start_tsr6   r7   bufs   &      r
   get_summaryMemoryTracker.get_summary   s%    $(?CDD OO//<	/$ ==T^^DOO-LM%%))%3	//%%eQ/ TYYK DHH:hZ s+1-,y123W-./,t~~FGH\*;<=>	
 zz#r   )r+   r*   r(   r&   r$   r,   r)   r'   N)__name__
__module____qualname____firstlineno____doc____annotations__r1   
contextlibcontextmanagerr8   rT   __static_attributes__r   r   r
   r"   r"   T   sa     
H
I..,,	 ? ?@4 4r   r"   )rZ   
__future__r   r   r\   r4   typingr   r   r   r   ImportErrorIS_SUPPORTEDr   r    r"   r   r   r
   <module>rc      s]   	 # 	   !K
 &"Jp p  Ks   > 	A
	A
