a
    ތxd7                     @   s   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	d
 ZG dd deZG dd dZG dd deZdS )    N)
hsv_to_rgb)Stats)format_html)gettext_lazy)settings)Panelz_lsprof.Profilerc                 C   s(   d}| D ]}t |tr|t|v O }q|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)Z
func_tupleZhas_profilervalue r   V/var/www/html/Ranjet/env/lib/python3.9/site-packages/debug_toolbar/panels/profiling.pycontains_profiler   s
    
r   c                   @   s   e Zd ZdZdd ZdS )DjangoDebugToolbarStatsNc                 C   sL   | j d u rF| j D ]0\}\}}}}}t|dkrt|s|| _  qFq| j S Nr   )_DjangoDebugToolbarStats__rootstatsitemslenr   )selffuncccncttctcallersr   r   r   get_root_func   s    
z%DjangoDebugToolbarStats.get_root_func)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                   @   sp   e Zd Zdddg dfddZdd Zdd	 Zd
d Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )FunctionCallr   N)r   g      ?   c                 C   sH   || _ || _|r|| _n|j| d d | _|| _|| _|| _|| _d S )N   )statobjr   r   depthid
parent_idshsv)r   r#   r   r$   r   r%   r&   r'   r   r   r   __init__)   s    zFunctionCall.__init__c                 C   s   | j S N)parent_classesr   r   r   r   r*   7   s    zFunctionCall.parent_classesc                 C   s*   t | j \}}}d|d |d |d S )Nzrgb({:f}%,{:f}%,{:f}%)d   )r   r'   format)r   rgbr   r   r   
background:   s    zFunctionCall.backgroundc           	      C   s   | j }|d d dkrH|d }|drB|drBd|dd  S |S np| j \}}}|d}|dkrv||d	 d  }|tjd}t|dkr|tjd\}}nd
}td||||S 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idxZ
split_path	file_pathr   r   r   func_std_string>   s*    
zFunctionCall.func_std_stringc           
      c   s   d}| j \}}}t| jj| j }| jj| j  D ]\}}|d7 }||| | jd   }|d dkrld}	n||d | jd   }	t| j|| jd |t	| j
d t	| | j| j
g ||	dfdV  q4d S )Nr   r!      _)r   r%   r&   r'   )r'   r   r#   Zall_calleesr   r   r$   r   r    r	   r%   r&   )
r   ihsvcountr   r   Zh1s1r   r   r   subfuncs^   s$    zFunctionCall.subfuncsc                 C   s
   | j d S )Nr!   r   r+   r   r   r   rL   s   s    zFunctionCall.countc                 C   s
   | j d S )Nr2   rO   r+   r   r   r   tottimev   s    zFunctionCall.tottimec                 C   s   | j \}}}}| j d S )NrF   rO   r   r   r   r   r   r   r   r   cumtimey   s    zFunctionCall.cumtimec                 C   s"   | j \}}}}|dkrdS || S r   rO   rQ   r   r   r   tottime_per_call}   s    zFunctionCall.tottime_per_callc                 C   s"   | j \}}}}|dkrdS || S r   rO   rQ   r   r   r   cumtime_per_call   s    zFunctionCall.cumtime_per_callc                 C   s
   d| j  S )N   r$   r+   r   r   r   indent   s    zFunctionCall.indent)r   r   r   r(   r*   r1   rE   rN   rL   rP   rR   rS   rT   rW   r   r   r   r   r    (   s   

 r    c                       s>   e Zd ZdZedZdZ fddZdddZd	d
 Z	  Z
S )ProfilingPanelz4
    Panel that displays profiling information.
    Z	Profilingz#debug_toolbar/panels/profiling.htmlc                    s   t  | _| jt j|S r)   )cProfileZProfileprofilerZruncallsuperprocess_request)r   request	__class__r   r   r\      s    
zProfilingPanel.process_request皙?c                 C   sR   | | d|_|j|k rN| D ]*}|jd |kr"d|_| j||||d q"d S )NFrF   T)cum_time)appendZhas_subfuncsr$   rN   r   add_node)r   	func_listr   	max_depthra   Zsubfuncr   r   r   rc      s    

zProfilingPanel.add_nodec                 C   s   t | dsd S | j  t| j| _| j  | j }|rt| j|dd}g }| ||t	
 d |jd d  | d|i d S )NrZ   r   rV   ZPROFILER_MAX_DEPTHrF      rd   )hasattrrZ   Zcreate_statsr   r   Zcalc_calleesr   r    rc   dt_settingsZ
get_configZrecord_stats)r   r]   responseZ	root_funcrootrd   r   r   r   generate_stats   s     




zProfilingPanel.generate_stats)r`   )r   r   r   __doc__rG   titletemplater\   rc   rk   __classcell__r   r   r^   r   rX      s   
	rX   )rY   r<   colorsysr   Zpstatsr   Zdjango.utils.htmlr   Zdjango.utils.translationr   rG   Zdebug_toolbarr   rh   Zdebug_toolbar.panelsr   r
   r   r   r    rX   r   r   r   r   <module>   s   
i