o
    èe)  ã                   @   s6   d dl Z d dlZ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   s4   t |tƒsJ ‚ddg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)Ú
isinstanceÚstrÚ_optionsÚ_parse_from_string)ÚselfÚoptions_str© r   úND:\Projects\ConvertPro\env\Lib\site-packages\paddleocr/ppocr/utils/profiler.pyÚ__init__.   s   úzProfilerOptions.__init__c                 C   s¼   |  dd¡ d¡D ]R}| 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 S )Nú Ú ú;ú=r   ú[ú]ú,é   r   é   r   )ÚyesÚtrueÚtÚ1)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__K   s
   ÿ
zProfilerOptions.__getitem__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r/   r   r   r   r   r      s
    r   c                 C   sŒ   | du rdS t du rt| ƒa tt d d kr#tjj t d t d ¡ ntt d d kr@tjj t d t d ¡ t d	 r@t 	d¡ td7 adS )
al  
    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   r   r   r	   r   r   r
   r   )
Ú_profiler_optionsr   Ú_profiler_step_idÚpaddleÚutilsZprofilerZstart_profilerZstop_profilerÚsysÚexit)r   r   r   r   Úadd_profiler_stepR   s   
ÿÿ
r:   )N)r8   r6   r5   r4   Úobjectr   r:   r   r   r   r   Ú<module>   s   8