o
    i                     @  sZ   d dl mZ d dlZd dlmZ d dlmZ d dlmZ ej	dddd	Z
ddddZdS )    )annotationsN)Callablewraps)Any	save_file
str | Nonec              	   c  s    ddl }| }|  zdV  W |  | r#| dkr#||  dS |jdd dS |  | r;| dkr;||  w |jdd w )zRun a cprofile

    Args:
        save_file: path to save the profile result. "1" or
            None will result in printing to stdout.
    r   N1cumtime)sort)cProfileProfileenabledisable
dump_statsprint_stats)r   r   prof r   J/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm/utils/profiling.pycprofile_context   s   r   Tenabledboolc                   s   d fdd}|S )zDecorator to profile a Python method using cProfile.

    Args:
        save_file: Path to save the profile result.
            If "1", None, or "", results will be printed to stdout.
        enabled: Set to false to turn this into a no-op
    funcr   c                   s   t  d fdd}|S )Nargsr   kwargsc                    sL    s	| i |S t  | i |W  d    S 1 sw   Y  d S N)r   )r   r   )r   r   r   r   r   wrapper-   s
   
$z,cprofile.<locals>.decorator.<locals>.wrapper)r   r   r   r   r   )r   r   r   r   )r   r   	decorator,   s   zcprofile.<locals>.decoratorN)r   r   r   )r   r   r   r   r   r   cprofile#   s   	r   r   )r   r   )NT)r   r   r   r   )
__future__r   
contextlibcollections.abcr   	functoolsr   typingr   contextmanagerr   r   r   r   r   r   <module>   s   