î
à^Q\ƒ  ã               @   sü   d  d l  m Z m Z m Z 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 d
 Z d d „  Z Gd d „  d e	 ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d S)é    )Úabsolute_importÚdivisionÚunicode_literalsN)Ú
hsv_to_rgb)ÚStats)Úsix)Úformat_html)Úugettext_lazy)Úsettings)ÚPanelz_lsprof.Profilerc             C   s@   d } x3 |  D]+ } t  | t j ƒ r | t | k O} q q W| S)zwHelper function that checks to see if the tuple contains
    the INVALID_PROFILE_FUNC in any string value of the tuple.F)Ú
isinstancer   Ústring_typesÚINVALID_PROFILER_FUNC)Z
func_tupleZhas_profilerÚvalue© r   úR/var/www/dbchiro/venv/build/django-debug-toolbar/debug_toolbar/panels/profiling.pyÚcontains_profiler   s
    r   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚDjangoDebugToolbarStatsNc             C   st   |  j  d  k rm x[ |  j j ƒ  D]G \ } \ } } } } } t | ƒ d k r t | ƒ r | |  _  Pq q Wn  |  j  S)Nr   )Ú_DjangoDebugToolbarStats__rootÚstatsÚitemsÚlenr   )ÚselfÚfuncÚccÚncÚttÚctZ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               @   s£   e  Z d  Z d d d g  d 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ç      à?é   c             C   sf   | |  _  | |  _ | 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,   9   s    zFunctionCall.parent_classesc             C   s5   t  |  j Œ  \ } } } d | d | d | d f S)Nzrgb(%f%%,%f%%,%f%%)éd   )r   r*   )r   ÚrÚgÚbr   r   r   Ú
background<   s    zFunctionCall.backgroundc             C   sÙ   |  j  } | d  d … d k r` | d } | j d ƒ rY | j d ƒ rY d | d d … S| Snu |  j  \ } } } | j d ƒ } | d k r¤ | | d	 d  … } n  | j t j d ƒ \ } } t d
 | | | | ƒ Sd  S)Né   ú~r   ú<ú>z{%s}r$   z/site-packages/é   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>))r3   r   éÿÿÿÿr7   )r   Ú
startswithÚendswithÚfindÚrsplitÚosÚsepr   )r   Ú	func_nameÚnameÚ	file_nameÚline_numÚmethodÚidxÚ	file_pathr   r   r   Úfunc_std_string@   s"    	
zFunctionCall.func_std_stringc       
      c   s  d } |  j  \ } } } t |  j j |  j ƒ } xÜ |  j j |  j j ƒ  D]Á \ } } | d 7} | | | |  j d } | d d k r“ d }	 n | | d |  j d }	 t |  j | |  j d d | d t	 |  j
 ƒ d t	 | ƒ d |  j |  j
 g d | |	 d f ƒVqK Wd  S)	Nr   r$   é   r   r(   Ú_r)   r*   )r*   r   r&   Zall_calleesr   r   r'   r   r"   Ústrr(   r)   )
r   ÚiÚhÚsÚvÚcountr   r   Úh1Ús1r   r   r   Úsubfuncs[   s     &
		zFunctionCall.subfuncsc             C   s   |  j  d S)Nr$   )r   )r   r   r   r   rM   n   s    zFunctionCall.countc             C   s   |  j  d S)Nr2   )r   )r   r   r   r   Útottimeq   s    zFunctionCall.tottimec             C   s    |  j  \ } } } } |  j  d S)NrF   )r   )r   r   r   r   r   r   r   r   Úcumtimet   s    zFunctionCall.cumtimec             C   s-   |  j  \ } } } } | d k r% d S| | S)Nr   )r   )r   r   r   r   r   r   r   r   Útottime_per_callx   s    zFunctionCall.tottime_per_callc             C   s-   |  j  \ } } } } | d k r% d S| | S)Nr   )r   )r   r   r   r   r   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    r!   r+   r,   r1   rE   rP   rM   rQ   rR   rS   rT   rV   r   r   r   r   r"   +   s   r"   c               @   sO   e  Z d  Z d Z e d ƒ Z d Z d d „  Z d d d „ Z d	 d
 „  Z	 d S)ÚProfilingPanelz4
    Panel that displays profiling information.
    Z	Profilingz#debug_toolbar/panels/profiling.htmlc             C   s2   t  j ƒ  |  _ | f | } |  j j | | | Ž S)N)ÚcProfileZProfileÚprofilerZruncall)r   ÚrequestZ	view_funcZ	view_argsZview_kwargsÚargsr   r   r   Úprocess_view”   s    zProfilingPanel.process_viewgš™™™™™¹?c             C   s{   | j  | ƒ d | _ | j | k  rw xO | j ƒ  D]> } | j d | k r2 d | _ |  j | | | d | ƒq2 q2 Wn  d  S)NFrF   TÚcum_time)ÚappendZhas_subfuncsr'   rP   r   Úadd_node)r   Ú	func_listr   Z	max_depthr]   Zsubfuncr   r   r   r_   ™   s    		zProfilingPanel.add_nodec             C   s¸   t  |  d ƒ s d  S|  j j ƒ  t |  j ƒ |  _ |  j j ƒ  |  j j ƒ  } | r´ t |  j | d d ƒ} g  } |  j | | t	 j
 ƒ  d | j d d ƒ |  j i | d 6ƒ n  d  S)NrY   r'   r   ZPROFILER_MAX_DEPTHrF   é   r`   )ÚhasattrrY   Zcreate_statsr   r   Zcalc_calleesr   r"   r_   Údt_settingsZ
get_configZrecord_stats)r   rZ   ÚresponseZ	root_funcÚrootr`   r   r   r   Úgenerate_stats¢   s    	zProfilingPanel.generate_statsN)
r   r    r!   Ú__doc__rG   ÚtitleÚtemplater\   r_   rf   r   r   r   r   rW   Œ   s   	rW   )Ú
__future__r   r   r   rX   r<   Zcolorsysr   Zpstatsr   Zdjango.utilsr   Zdjango.utils.htmlr   Zdjango.utils.translationr	   rG   Zdebug_toolbarr
   rc   Zdebug_toolbar.panelsr   r   r   r   Úobjectr"   rW   r   r   r   r   Ú<module>   s   
a