
    7 f                         d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ  G d d	      Z G d
 de      Zy)    N)
hsv_to_rgb)Stats)settings)format_html)gettext_lazy)Panelc                   X    e Zd Z	 ddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)FunctionCallNc                     || _         || _        |r|| _        n|j                  |   d d | _        || _        || _        |xs g | _        || _        y )N   )statobjfuncstatsdepthid
parent_idshsv)selfr   r   r   r   r   r   r   s           T/var/www/equiseq/venv/lib/python3.11/site-packages/debug_toolbar/panels/profiling.py__init__zFunctionCall.__init__   sT     	DJ t,Ra0DJ
$*    c                     | j                   S N)parent_classesr   s    r   r   zFunctionCall.parent_classes   s    """r   c                 ^    t        | j                   \  }}}d|dz  dd|dz  dd|dz  ddS )Nzrgb(d   fz%,z%))r   r   )r   rgbs       r   
backgroundzFunctionCall.background    sC    dhh'1aa#ga[1s71+RC{"==r   c                     t        t        d      r7| j                  \  }}}t        t        j                        |v xr
 d|vxr d|vS y)z
        Check if the function is from the project code.

        Project code is identified by the BASE_DIR setting
        which is used in Django projects by default.
        BASE_DIR/site-packages/z/dist-packages/N)hasattrr   r   strr$   )r   	file_name_s      r   is_project_funczFunctionCall.is_project_func$   sT     8Z("iiOIq!H%%&)3 7%Y67%Y6
 r   c                    | j                   }|d d dk(  r1|d   }|j                  d      r|j                  d      rd|dd z  S |S | j                   \  }}}|j                  d      }|dkD  r||d	z   d  }|j	                  t
        j                  d      }t        |      dkD  r$|j	                  t
        j                  d      \  }}nd
}t        d||||      S )N   )~r   <>z{%s}   r%      z<module>z<span class="djdt-path">{0}/</span><span class="djdt-file">{1}</span> in <span class="djdt-func">{3}</span>(<span class="djdt-lineno">{2}</span>))	r   
startswithendswithfindrsplitosseplenr   )	r   	func_namenamer(   line_nummethodidx
split_path	file_paths	            r   func_std_stringzFunctionCall.func_std_string4   s    II	Ra=H$Q<Ds#c(:Qr
***.))'Ix..!23CRx%sRxl3	"))"&&!4J:"'0'7'7'B$	9&	9 	 	r   c              #   H  K   d}| j                   \  }}}t        | j                  j                  | j                           }| j                  j                  | j                     j                         D ]  \  }}|dz  }|||z  | j                  dz   z  z   }|d   dk(  rdn||d   | j                  d   z  z  }	t        | j                  || j                  dz   |t        | j                        dz   t        |      z   | j                  | j                  gz   ||	df        y w)Nr   r0      r)   )r   r   r   r   )r   r9   r   all_calleesr   itemsr   r   r
   r'   r   r   )
r   ihsvcountr   r   h1s1s
             r   subfuncszFunctionCall.subfuncsT   s
    ((1aDLL,,TYY78<<33DII>DDF 	KD%FAa%iDJJN33BAh!meAhA.F)GB

Qtww<#%A.??dggY6QK 		s   D D"c                      | j                   d   S )Nr0   r   r   s    r   rJ   zFunctionCall.countf       zz!}r   c                      | j                   d   S )Nr,   rO   r   s    r   tottimezFunctionCall.tottimei   rP   r   c                 B    | j                   \  }}}}| j                   d   S )NrC   rO   r   ccncttcts        r   cumtimezFunctionCall.cumtimel   s!    BBzz!}r   c                 :    | j                   \  }}}}|dk(  ry||z  S Nr   rO   rT   s        r   tottime_per_callzFunctionCall.tottime_per_callp   &    BB7Bwr   c                 :    | j                   \  }}}}|dk(  ry||z  S r[   rO   rT   s        r   cumtime_per_callzFunctionCall.cumtime_per_callx   r]   r   c                      d| j                   z  S )N   r   r   s    r   indentzFunctionCall.indent   s    DJJr   )r   Nr   N)r   g      ?r0   )__name__
__module____qualname__r   r   r"   r*   rA   rM   rJ   rR   rY   r\   r_   rc    r   r   r
   r
      sB    MX#> @$r   r
   c                   n     e Zd ZdZ ed      ZdZ ej                         d   Z	 fdZ
d Z fdZ xZS )ProfilingPanelz4
    Panel that displays profiling information.
    	Profilingz#debug_toolbar/panels/profiling.htmlPROFILER_CAPTURE_PROJECT_CODEc                 ~    t        j                         | _        | j                  j                  t        |   |      S r   )cProfileProfileprofilerruncallsuperprocess_request)r   request	__class__s     r   rr   zProfilingPanel.process_request   s/     ((*}}$$UW%<gFFr   c                 :   |j                  |       d|_        |j                  |k  rt|j                         D ]`  }|j                  d   |k\  s1| j
                  s"|j                         s3|j                  d   dkD  sFd|_        | j                  ||||       b y y )NFrC   r   T)appendhas_subfuncsr   rM   r   capture_project_coder*   add_node)r   	func_listr   	max_depthcum_timesubfuncs         r   ry   zProfilingPanel.add_node   s    !::	!==? K==#x/--//1a(1,(,D%MM)WiJK "r   c                 6   t        | d      sy | j                  j                          t        | j                        | _        | j                  j                          t        j                  t        | $  j                        }|| j                  j                  v r~t        | j                  |d      }g }|j                  d   t        j                         d   z  }| j                  ||t        j                         d   |       | j                  d|i       y y )Nro   r   rb   rC   PROFILER_THRESHOLD_RATIOPROFILER_MAX_DEPTHrz   )r&   ro   create_statsr   r   calc_calleesrm   labelrq   rr   __code__r
   dt_settings
get_configry   record_stats)r   rs   response	root_funcrootrz   cum_time_thresholdrt   s          r   generate_statszProfilingPanel.generate_stats   s    tZ(""$4==)


!NN57#:#C#CD	

(((

IQ?DI

1 6 6 89S TT  MM&&()=>"	 {I67 )r   )rd   re   rf   __doc__r)   titletemplater   r   rx   rr   ry   r   __classcell__)rt   s   @r   ri   ri      sE     kNE4H1;1134STGK8 8r   ri   )rm   r7   colorsysr   pstatsr   django.confr   django.utils.htmlr   django.utils.translationr   r)   debug_toolbarr   debug_toolbar.panelsr   r
   ri   rg   r   r   <module>r      s9     	     ) 6 1 &s sl28U 28r   