
    ]j7                         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Zd	 Z G d
 de      Z G d d      Z G d de      Zy)    N)
hsv_to_rgb)Stats)format_html)gettext_lazy)settings)Panelz_lsprof.Profilerc                 P    d}| D ]  }t        |t              s|t        |v z  }  |S )zwHelper function that checks to see if the tuple contains
    the INVALID_PROFILE_FUNC in any string value of the tuple.F)
isinstancestrINVALID_PROFILER_FUNC)
func_tuplehas_profilervalues      H/root/env/lib/python3.12/site-packages/debug_toolbar/panels/profiling.pycontains_profilerr      s:     L ;eS!1U::L;     c                       e Zd ZdZd Zy)DjangoDebugToolbarStatsNc                     | j                   V| j                  j                         D ]9  \  }\  }}}}}t        |      dk(  st	        |      r'|| _          | j                   S  | j                   S Nr   )_DjangoDebugToolbarStats__rootstatsitemslenr   )selffuncccncttctcallerss          r   get_root_funcz%DjangoDebugToolbarStats.get_root_func   sl    ;;37::3C3C3E //r2r2ww<1$->t-D"&DK{{	 {{r   )__name__
__module____qualname__r   r"    r   r   r   r      s    Fr   r   c                   Z    e Zd Zdddg dfdZd Zd Zd Zd Zd	 Zd
 Z	d Z
d Zd Zd Zy)FunctionCallr   N)r   g      ?   c                     || _         || _        |r|| _        n|j                  |   d d | _        || _        || _        || _        || _        y )N   )statobjr   r   depthid
parent_idshsv)r   r,   r   r-   r   r.   r/   r0   s           r   __init__zFunctionCall.__init__)   sO     	DJ t,Ra0DJ
$r   c                     | j                   S N)parent_classesr   s    r   r4   zFunctionCall.parent_classes7   s    """r   c                 f    t        | j                   \  }}}dj                  |dz  |dz  |dz        S )Nzrgb({:f}%,{:f}%,{:f}%)d   )r   r0   format)r   rgbs       r   
backgroundzFunctionCall.background:   s7    dhh'1a'..q3wCSIIr   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/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   
startswithendswithfindrsplitossepr   r   )	r   	func_namename	file_nameline_nummethodidx
split_path	file_paths	            r   func_std_stringzFunctionCall.func_std_string>   s    II	Ra=H$Q<Ds#c(:Qr
***.))'Ix..!23CRx%sRxl3	"))"&&!4J:"'0'7'7'B$	9&	9 	 	r   c              #   J  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   r)      _)r   r.   r/   r0   )r0   r   r,   all_calleesr   r   r-   r   r(   r   r.   r/   )
r   ihsvcountr   r   h1s1s
             r   subfuncszFunctionCall.subfuncs^   s    ((1aDLL,,TYY78<<33DII>DDF 	KD%FAa%iDJJN33BQx1}%(TZZ]23

Qtww<#%A.??dggY6QK 	s   D!D#c                      | j                   d   S )Nr)   r   r5   s    r   r[   zFunctionCall.counts       zz!}r   c                      | j                   d   S )Nr>   r`   r5   s    r   tottimezFunctionCall.tottimev   ra   r   c                 B    | j                   \  }}}}| j                   d   S )NrT   r`   r   r   r   r   r    s        r   cumtimezFunctionCall.cumtimey   s!    BBzz!}r   c                 :    | j                   \  }}}}|dk(  ry||z  S r   r`   re   s        r   tottime_per_callzFunctionCall.tottime_per_call}   &    BB7Bwr   c                 :    | j                   \  }}}}|dk(  ry||z  S r   r`   re   s        r   cumtime_per_callzFunctionCall.cumtime_per_call   ri   r   c                      d| j                   z  S )N   r-   r5   s    r   indentzFunctionCall.indent   s    DJJr   )r#   r$   r%   r1   r4   r<   rR   r^   r[   rc   rf   rh   rk   ro   r&   r   r   r(   r(   (   sF    #$DQ2;#J@*r   r(   c                   D     e Zd ZdZ ed      ZdZ fdZddZd Z	 xZ
S )ProfilingPanelz4
    Panel that displays profiling information.
    	Profilingz#debug_toolbar/panels/profiling.htmlc                 ~    t        j                         | _        | j                  j                  t        |   |      S r3   )cProfileProfileprofilerruncallsuperprocess_request)r   request	__class__s     r   ry   zProfilingPanel.process_request   s/     ((*}}$$UW%<gFFr   c                     |j                  |       d|_        |j                  |k  rE|j                         D ]1  }|j                  d   |k\  sd|_        | j                  ||||       3 y y )NFrT   T)cum_time)appendhas_subfuncsr-   r^   r   add_node)r   	func_listr   	max_depthr}   subfuncs         r   r   zProfilingPanel.add_node   sm    !::	!==? T==#x/(,D%MM)Wi(MST "r   c                    t        | d      sy | j                  j                          t        | j                        | _        | j                  j                          | j                  j                         }|rgt        | j                  |d      }g }| j                  ||t        j                         d   |j                  d   dz         | j                  d|i       y y )Nrv   r   rn   PROFILER_MAX_DEPTHrT      r   )hasattrrv   create_statsr   r   calc_calleesr"   r(   r   dt_settings
get_configrecord_stats)r   rz   response	root_funcrootr   s         r   generate_statszProfilingPanel.generate_stats   s    tZ(""$,T]];


!JJ,,.	

IQ?DIMM&&()=>

1!	 {I67 r   )g?)r#   r$   r%   __doc__rU   titletemplatery   r   r   __classcell__)r{   s   @r   rq   rq      s)     kNE4HGT8r   rq   )rt   rH   colorsysr   pstatsr   django.utils.htmlr   django.utils.translationr   rU   debug_toolbarr   r   debug_toolbar.panelsr   r   r   r   r(   rq   r&   r   r   <module>r      sO     	   ) 6 1 &
 + 	e 	f fR)8U )8r   