
    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dS )    N)
hsv_to_rgb)Stats)settings)format_html)gettext_lazy)Panelc                   Z    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dS )FunctionCallr   Nr   g      ?   c                     || _         || _        |r|| _        n|j        |         d d         | _        || _        || _        |pg | _        || _        d S )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__   s_     	 	1DJJ t,RaR0DJ
$*    c                     | j         S N)parent_classesr   s    r   r   zFunctionCall.parent_classes   s    ""r   c                 V    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    sJ    dh'1a=a#g===1s7===C=====r   c                     t          t          d          r.| j        \  }}}t          t          j                  |v od|vod|vS dS )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$   s\     8Z(( 	"iOIq!H%&&)3 7%Y67%Y6
 tr   c                    | j         }|d d         dk    rA|d         }|                    d          r"|                    d          rd|dd         z  S |S | j         \  }}}|                    d          }|dk    r||d	z   d          }|                    t
          j        d          }t          |          dk    r$|                    t
          j        d          \  }}nd
}t          d||||          S )N   )~r   <>z{%s}r   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   I	RaR=H$$Q<Ds## c(:(: QrT
***.)'Ix..!233CRxx%sRxll3	"))"&!44J:""'0'7'7'B'B$	99&	9 	 	 	r   c              #     K   d}| j         \  }}}t          | 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          V  d S )Nr   r      r+   )r   r   r   r   )r   r:   r   all_calleesr   itemsr   r   r
   r)   r   r   )
r   ihsvcountr   r   h1s1s
             r   subfuncszFunctionCall.subfuncsT   s     (1aDL,TY788<3DI>DDFF 	 	KD%FAa%iDJN33BAh!mmeAhA.F)GB
Qtw<<#%A.?dgY6QK      		 	r   c                     | j         d         S )Nr   r   r   s    r   rK   zFunctionCall.countf       z!}r   c                     | j         d         S )Nr.   rP   r   s    r   tottimezFunctionCall.tottimei   rQ   r   c                 4    | j         \  }}}}| j         d         S )NrD   rP   r   ccncttcts        r   cumtimezFunctionCall.cumtimel   s    BBz!}r   c                 4    | j         \  }}}}|dk    rdS ||z  S Nr   rP   rU   s        r   tottime_per_callzFunctionCall.tottime_per_callp   (    BB771Bwr   c                 4    | j         \  }}}}|dk    rdS ||z  S r\   rP   rU   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    DJr   )r   Nr   Nr   )__name__
__module____qualname__r   r   r$   r,   rB   rN   rK   rS   rZ   r]   r`   rd    r   r   r
   r
      s        MX   # # #> > >     @  $              r   r
   c                   v     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                            t	                      j        |          S r   )cProfileProfileprofilerruncallsuperprocess_request)r   request	__class__s     r   rs   zProfilingPanel.process_request   s2     (**}$$UWW%<gFFFr   c                 >   |                     |           d|_        |j        |k     rs|                                D ]`}|j        d         |k    s,| j        rD|                                r0|j        d         dk    rd|_        |                     ||||           _d S d S )NFrD   r   T)appendhas_subfuncsr   rN   r   capture_project_coder,   add_node)r   	func_listr   	max_depthcum_timesubfuncs         r   rz   zProfilingPanel.add_node   s    !:	!!==?? K K=#x//- 0//11 0  a(1,,(,D%MM)WiJJJ "!K Kr   c                 B   t          | d          sd S | j                                         t          | j                  | _        | j                                         t          j        t                      j	        j
                  }|| j        j        v rt          | j        |d          }g }|j        d         t          j                    d         z  }|                     ||t          j                    d         |           |                     d|i           d S d S )Nrp   r   rc   rD   PROFILER_THRESHOLD_RATIOPROFILER_MAX_DEPTHr{   )r(   rp   create_statsr   r   calc_calleesrn   labelrr   rs   __code__r
   dt_settings
get_configrz   record_stats)r   rt   response	root_funcrootr{   cum_time_thresholdru   s          r   generate_statszProfilingPanel.generate_stats   s   tZ(( 	4""$$$4=))

!!!N577#:#CDD	
(((
IQ???DI
1 6 8 89S TT  MM&(()=>"	   {I677777 )(r   )re   rf   rg   __doc__r+   titletemplater   r   ry   rs   rz   r   __classcell__)ru   s   @r   rj   rj      s          AkNNE4H1;1334STG G G G GK K K8 8 8 8 8 8 8 8 8r   rj   )rn   r8   colorsysr   pstatsr   django.confr   django.utils.htmlr   django.utils.translationr   r+   debug_toolbarr   debug_toolbar.panelsr   r
   rj   rh   r   r   <module>r      s     				                         ) ) ) ) ) ) 6 6 6 6 6 6 1 1 1 1 1 1 & & & & & &s s s s s s s sl28 28 28 28 28U 28 28 28 28 28r   