o
    'j                     @   s>   d dl Z d dlmZ d adadaG dd deZdddZdS )    Nc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ProfilerOptionsa  
    Use a string to initialize a ProfilerOptions.
    The string should be in the format: "key1=value1;key2=value;key3=value3".
    For example:
      "profile_path=model.profile"
      "batch_range=[50, 60]; profile_path=model.profile"
      "batch_range=[50, 60]; tracer_option=OpDetail; profile_path=model.profile"

    ProfilerOptions supports following key-value pair:
      batch_range      - a integer list, e.g. [100, 110].
      state            - a string, the optional values are 'CPU', 'GPU' or 'All'. 
      sorted_key       - a string, the optional values are 'calls', 'total',
                         'max', 'min' or 'ave.
      tracer_option    - a string, the optional values are 'Default', 'OpDetail',
                         'AllOpDetail'.
      profile_path     - a string, the path to save the serialized profile data,
                         which can be used to generate a timeline.
      exit_on_finished - a boolean.
    c                 C   s6   t |tsJ ddgddddddd| _| | d S )	N
      ZAlltotalZDefaultz/tmp/profileT)batch_rangestate
sorted_keytracer_optionprofile_pathexit_on_finished
timer_only)
isinstancestr_options_parse_from_string)selfoptions_str r   _/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddleocr/ppocr/utils/profiler.py__init__/   s   	zProfilerOptions.__init__c                 C   s   | dddD ]\}|d\}}|dkrD| dd ddd}ttt|}t|d	krC|d
 d
krC|d |d
 krC|| j|< q	|dkrR| dv | j|< q	|dv r\|| j|< q	|dkre|| j|< q	d S )N  ;=r   [],   r      r   )yestruet1)r   r   r	   r
   r   )replacesplitlistmapintlenr   lower)r   r   kvkeyvalueZ
value_listr   r   r   r   =   s(   

z"ProfilerOptions._parse_from_stringc                 C   s(   | j |d d u rtd| | j | S )Nz1ProfilerOptions does not have an option named %s.)r   get
ValueError)r   namer   r   r   __getitem__O   s
   
zProfilerOptions.__getitem__N)__name__
__module____qualname____doc__r   r   r0   r   r   r   r   r      s
    r   c                 C   s   | du rdS t du rt| a tdu r6tt d tdk}tjt d d t d d ftd|dat  nt  t	t d d krYt
  tjdd	d
d dat d rYtd t	d7 a	dS )ag  
    Enable the operator-level timing using PaddlePaddle's profiler.
    The profiler uses a independent variable to count the profiler steps.
    One call of this function is treated as a profiler step.
    Args:
      profiler_options - a string to initialize the ProfilerOptions.
                         Default is None, and the profiler is disabled.
    Nr   Tr   r   r   z./profiler_log)Z	schedulerZon_trace_readyr   Fms)Z	op_detailZ
thread_sepZ	time_unitr   )_profiler_optionsr   _profr   profilerZProfilerZexport_chrome_tracingstartstep_profiler_step_idstopsummarysysexit)r   Z_timer_onlyr   r   r   add_profiler_stepV   s0   	

r@   )N)	r>   Zpaddle.profilerr8   r;   r6   r7   objectr   r@   r   r   r   r   <module>   s   <