§
    “©ºj~  ã                   óº   — d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZ ddlmZ  ej        e¦  «        Z G d	„ d
e¦  «        ZdS )z<Profiler to check if there are any bottlenecks in your code.é    N)ÚABCÚabstractmethod)Ú	Generator)Úcontextmanager)ÚPath)ÚAnyÚCallableÚOptionalÚTextIOÚUnion)Úget_filesystemc            	       óœ  — e Zd ZdZ	 	 ddeeeef                  dee         ddfd„Ze	deddfd„¦   «         Z
e	deddfd	„¦   «         Zdefd
„Zededefd„¦   «         Zdededdfd„Z	 	 ddee         dedefd„Zdd„Zdd„Zdeeef         defd„Zddedee         dee         ddfd„Zdee         ddfd„Zdd„Zedefd„¦   «         ZdS ) ÚProfilerzKIf you wish to write a custom profiler, you should inherit from this class.NÚdirpathÚfilenameÚreturnc                 óZ   — || _         || _        d | _        d | _        d | _        d | _        d S )N)r   r   Ú_output_fileÚ_write_streamÚ_local_rankÚ_stage)Úselfr   r   s      út/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/profilers/profiler.pyÚ__init__zProfiler.__init__!   s5   € ð
 ˆŒØ ˆŒà.2ˆÔØ15ˆÔØ*.ˆÔØ%)ˆŒˆˆó    Úaction_namec                 ó   — dS )z)Defines how to start recording an action.N© ©r   r   s     r   ÚstartzProfiler.start.   ó   € € € r   c                 ó   — dS )z>Defines how to record the duration once an action is complete.Nr   r   s     r   ÚstopzProfiler.stop2   r!   r   c                 ó   — dS )NÚ r   ©r   s    r   ÚsummaryzProfiler.summary6   s   € Øˆrr   c              #   óœ   K  — 	 |                       |¦  «         |V — |                      |¦  «         dS # |                      |¦  «         w xY w)aG  Yields a context manager to encapsulate the scope of a profiled action.

        Example::

            with self.profile('load training data'):
                # load training data code

        The profiler will start once you've entered the context and will automatically
        stop once you exit the code block.

        N)r    r#   r   s     r   ÚprofilezProfiler.profile9   sY   è è € ð	#Ø�JŠJ�{Ñ#Ô#Ð#ØÐÐÐà�IŠI�kÑ"Ô"Ð"Ð"Ð"øˆD�IŠI�kÑ"Ô"Ð"Ð"øøøs	   „4 ´AÚargsÚkwargsc                 ó>   — | j         dv rt          j        |i |¤Ž d S d S )N©Nr   )r   ÚlogÚinfo)r   r*   r+   s      r   Ú_rank_zero_infozProfiler._rank_zero_infoL   s3   € ØÔ˜yÐ(Ð(ÝŒH�dÐ%˜fÐ%Ð%Ð%Ð%Ð%ð )Ð(r   ú.txtÚ	extensionc                 óÐ  — g }| j         �|                     | j         ¦  «         | j        r|                     | j        ¦  «         | j        �'|                     t	          | j        ¦  «        ¦  «         |�|                     |¦  «         d                     |¦  «        }t          j        dd|¦  «        }t          j        dd|¦  «        }|                     ¦   «         }|sd}||z   S )Nú-z[\\/:*?\"<>|\n\r\t]Ú_z_+r)   )	r   Úappendr   r   ÚstrÚjoinÚreÚsubÚstrip)r   r   r2   r*   Úbases        r   Ú_prepare_filenamezProfiler._prepare_filenameP   sÜ   € ð
 ˆØŒ;Ð"Ø�KŠK˜œÑ$Ô$Ð$ØŒ=ð 	'Ø�KŠK˜œÑ&Ô&Ð&ØÔÐ'Ø�KŠK�˜DÔ,Ñ-Ô-Ñ.Ô.Ð.ØÐ"Ø�KŠK˜Ñ$Ô$Ð$Ø�xŠx˜‰~Œ~ˆåŒvÐ,¨c°4Ñ8Ô8ˆÝŒv�e˜S $Ñ'Ô'ˆØ�zŠz‰|Œ|ˆØð 	ØˆDØ�iÑÐr   c                 óf  — | j         �d S | j        r”| j        r�t          j                             | j        |                      ¦   «         ¦  «        }t          |¦  «        }|                     | j        d¬¦  «         | 	                    |d¦  «        }|| _
        |j        | _         d S | j        | _         d S )NT)Úexist_okÚa)r   r   r   ÚosÚpathr8   r=   r   ÚmkdirsÚopenr   Úwriter0   )r   ÚfilepathÚfsÚfiles       r   Ú_prepare_streamszProfiler._prepare_streamsg   s§   € ØÔÐ)ØˆFØŒ=ð 	6˜Tœ\ð 	6Ý”w—|’| D¤L°$×2HÒ2HÑ2JÔ2JÑKÔKˆHÝ Ñ)Ô)ˆBØ�IŠI�d”l¨TˆIÑ2Ô2Ð2Ø—7’7˜8 SÑ)Ô)ˆDØ $ˆDÔØ!%¤ˆDÔÐÐà!%Ô!5ˆDÔÐÐr   c                 ó  — |                       ¦   «          |                      ¦   «         }|r| j        �|                      |¦  «         | j        �| j                             ¦   «          |                      | j        ¬¦  «         dS )z2Logs a profile report after the conclusion of run.N©Ústage)rI   r'   r   r   ÚflushÚteardownr   )r   r'   s     r   ÚdescribezProfiler.describet   s�   € ð
 	×ÒÑÔÐØ—,’,‘.”.ˆØð 	(�tÔ)Ð5Ø×Ò˜wÑ'Ô'Ð'ØÔÐ(ØÔ×#Ò#Ñ%Ô%Ð%Ø�Š˜DœKˆÑ(Ô(Ð(Ð(Ð(r   Ústatsc                 óP  — | j         �| j                              ¦   «         › d�nd}|dz   g}|                     ¦   «         D ]H\  }}d|› �}| j        �|d| j        › �z  }|                     |¦  «         |                     |¦  «         ŒIt
          j                             |¦  «        S )Nú r%   zProfiler ReportzProfile stats for: z rank: )r   ÚupperÚitemsr   r6   rA   Úlinesepr8   )r   rP   rL   ÚoutputÚactionÚvalueÚheaders          r   Ú_stats_to_strzProfiler._stats_to_str�   sº   € Ø-1¬[Ð-D�4”;×$Ò$Ñ&Ô&Ð)Ð)Ð)Ð)È"ˆØÐ+Ñ+Ð,ˆØ"Ÿ[š[™]œ]ð 	!ð 	!‰MˆF�EØ3¨6Ð3Ð3ˆFØÔÐ+ØÐ6 DÔ$4Ð6Ð6Ñ6�Ø�MŠM˜&Ñ!Ô!Ð!Ø�MŠM˜%Ñ Ô Ð Ð ÝŒz�Š˜vÑ&Ô&Ð&r   rL   Ú
local_rankÚlog_dirc                 ó>   — || _         || _        | j        p|| _        dS )z-Execute arbitrary pre-profiling set-up steps.N)r   r   r   )r   rL   r[   r\   s       r   ÚsetupzProfiler.setupŒ   s#   € àˆŒØ%ˆÔØ”|Ð. wˆŒˆˆr   c                 óf   — d| _         | j        �"| j                             ¦   «          d| _        dS dS )zoExecute arbitrary post-profiling tear-down steps.

        Closes the currently open file and stream.

        N)r   r   Úclose)r   rL   s     r   rN   zProfiler.teardown’   s@   € ð "ˆÔØÔÐ(ØÔ×#Ò#Ñ%Ô%Ð%Ø $ˆDÔÐÐð )Ð(r   c                 ó<   — |                       | j        ¬¦  «         d S )NrK   )rN   r   r&   s    r   Ú__del__zProfiler.__del__�   s   € Ø�Š˜DœKˆÑ(Ô(Ð(Ð(Ð(r   c                 ó"   — | j         €dn| j         S r-   )r   r&   s    r   r[   zProfiler.local_rank    s   € àÔ$Ð,ˆqˆq°$Ô2BÐBr   )NN)Nr1   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r7   r   r   r   r    r#   r'   r   r   r)   r   r0   r=   rI   rO   ÚdictrZ   Úintr^   rN   rb   Úpropertyr[   r   r   r   r   r      sw  € € € € € ØUÐUð /3Ø"&ð*ð *à˜%  T 	Ô*Ô+ð*ð ˜3”-ð*ð 
ð	*ð *ð *ð *ð ð8 ð 8¨ð 8ð 8ð 8ñ „^ð8ð ðM ð M¨ð Mð Mð Mñ „^ðMð˜ð ð ð ð ð ð# 3ð #¨9ð #ð #ð #ñ „^ð#ð$& Sð &°Cð &¸Dð &ð &ð &ð &ð &*Øð ð  à˜c”]ð ð ð ð 
ð	 ð  ð  ð  ð.6ð 6ð 6ð 6ð)ð )ð )ð )ð	' 4¨¨S¨¤>ð 	'°cð 	'ð 	'ð 	'ð 	'ð/ð /˜3ð /¨H°S¬Mð /È8ÐTWÌ=ð /Ðdhð /ð /ð /ð /ð	%˜h sœmð 	%°ð 	%ð 	%ð 	%ð 	%ð)ð )ð )ð )ð ðC˜Cð Cð Cð Cñ „XðCð Cð Cr   r   )rg   ÚloggingrA   r9   Úabcr   r   Úcollections.abcr   Ú
contextlibr   Úpathlibr   Útypingr   r	   r
   r   r   Ú#lightning_fabric.utilities.cloud_ior   Ú	getLoggerrd   r.   r   r   r   r   ú<module>rs      s  ðð CÐ Bà €€€Ø 	€	€	€	Ø 	€	€	€	Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø %Ð %Ð %Ð %Ð %Ð %Ø %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9à >Ð >Ð >Ð >Ð >Ð >à€gÔ˜Ñ!Ô!€ðDCð DCð DCð DCð DCˆsñ DCô DCð DCð DCð DCr   