
    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           Y/var/www/cs2snipe.com/venv/lib/python3.12/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                 D   t        t        d      r| j                  \  }}t        t        j                        }t
        j                  j                        t
        j                  j                  |      }j                  |      xr t        fddD               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_DIRc              3   t   K   | ]/  }|j                  t        j                  j                        v  1 y wr   )splitospathsep).0	directory	file_names     r   	<genexpr>z/FunctionCall.is_project_func.<locals>.<genexpr>2   s/      > Y__RWW[[99>s   58)zsite-packageszdist-packagesN)
hasattrr   r   strr$   r'   r(   normpath
startswithany)r   _base_dirr,   s      @r   is_project_funczFunctionCall.is_project_func$   s     8Z("iiOIq!8,,-H((3Iww''1H''1 # >!C> ; 7  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}   z/site-packages/   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   r1   endswithfindrsplitr'   r)   lenr   )	r   	func_namenamer,   line_nummethodidx
split_path	file_paths	            r   func_std_stringzFunctionCall.func_std_string8   s    II	Ra=H$Q<Ds#c(:Qr
***.))'Ix..!23CRx%sRxl3	"))"&&!4J:"'0'7'7'B$	9&	9 	 	r   c              #   X  K   | j                   \  }}}t        | j                  j                  | j                           }t        | 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;      r   r3   )r   r   r   r   )r   rA   r   all_calleesr   	enumerateitemsr   r   r
   r/   r   r   )
r   hsvcountir   r   h1s1s
             r   subfuncszFunctionCall.subfuncsX   s
    ((1aDLL,,TYY78 )$,,*B*B499*M*S*S*U V 	A}eq1uo$**q.99BAh!meAhA.F)GB

Qtww<#%A.??dggY6QK 	s   D(D*c                      | j                   d   S )Nr;   r   r   s    r   rR   zFunctionCall.counth       zz!}r   c                      | j                   d   S )Nr7   rX   r   s    r   tottimezFunctionCall.tottimek   rY   r   c                 B    | j                   \  }}}}| j                   d   S )NrK   rX   r   ccncttcts        r   cumtimezFunctionCall.cumtimen   s!    BBzz!}r   c                 :    | j                   \  }}}}|dk(  ry||z  S Nr   rX   r]   s        r   tottime_per_callzFunctionCall.tottime_per_callr   &    BB7Bwr   c                 :    | j                   \  }}}}|dk(  ry||z  S rd   rX   r]   s        r   cumtime_per_callzFunctionCall.cumtime_per_callz   rf   r   c                      d| j                   z  S )N   r   r   s    r   indentzFunctionCall.indent   s    DJJr   )r   Nr   N)r   g      ?r;   )__name__
__module____qualname__r   r   r"   r5   rI   rV   rR   r[   rb   re   rh   rl    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   r{   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 )NFrK   r   T)appendhas_subfuncsr   rV   r   capture_project_coder5   add_node)r   	func_listr   	max_depthcum_timesubfuncs         r   r   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 )Nrx   r   rk   rK   PROFILER_THRESHOLD_RATIOPROFILER_MAX_DEPTHr   )r.   rx   create_statsr   r   calc_calleesrv   labelrz   r{   __code__r
   dt_settings
get_configr   record_stats)r   r|   response	root_funcrootr   cum_time_thresholdr}   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   )rm   rn   ro   __doc__r3   titletemplater   r   r   r{   r   r   __classcell__)r}   s   @r   rr   rr      sE     kNE4H1;1134STGK8 8r   rr   )rv   r'   colorsysr   pstatsr   django.confr   django.utils.htmlr   django.utils.translationr   r3   debug_toolbarr   debug_toolbar.panelsr   r
   rr   rp   r   r   <module>r      s9     	     ) 6 1 &u up28U 28r   