Spade
Mini Shell
�
q�fc@s�dZddlZddlZddlZddlZddlZddlmZdgZdfd��YZ dfd��YZ
d�Zd �Zd
�Z
d�Zd�Zd
�Zd�Zedkr�ddlZyddlZWnek
r�nXdejfd��YZddlZeej�dkrFejdZneZy4ee�ZejdIJej�ejdIJWnek
r�nXndS(s3Class for printing reports on profiled python
code.i����N(t
cmp_to_keytStatscBs<eZdZd�Zd�Zd�Zd�Zd�Zd�Zid8d
6d;d6d>d6dAd6dDd6dGd6dJd6dMd6dPd6dQdRdSfdfd6dVd6dYd"6d\d%6d_d&6Z d'�Z
d(�Zd)�Zd*�Z
d+�Zd,�Zd-�Zd.�Zd/�Zd0�Zd1�Zd2d3�Zd4�Zd5�ZRS(`s<This
class is used for creating reports from data generated by the
Profile class. It is a "friend" of that class, and imports
data either
by direct access to members of Profile class, or by reading in a
dictionary
that was emitted (via marshal) from the Profile class.
The big change from the previous Profiler (in terms of raw
functionality)
is that an "add()" method has been provided to combine Stats
from
several distinct profile runs. Both the constructor and the add()
method now take arbitrarily many file names as arguments.
All the print methods now take an argument that indicates how many
lines
to print. If the arg is a floating point number between 0 and 1.0,
then
it is taken as a decimal percentage of the available lines to be
printed
(e.g., .1 means print 10% of all available lines). If it is an
integer,
it is taken to mean the number of lines of data that you wish to have
printed.
The sort_stats() method now processes some additional options (i.e., in
addition to the old -1, 0, 1, or 2). It takes an arbitrary number of
quoted strings to select the sort order. For example
sort_stats('time',
'name') sorts on the major key of 'internal function
time', and on the
minor key of 'the name of the function'. Look at the two
tables in
sort_stats() and get_sort_arg_defs(self) for more examples.
All methods return self, so you can string together commands like:
Stats('foo',
'goo').strip_dirs().sort_stats('calls').
print_stats(5).print_callers(5)
cOs�tj|_d|kr/|d|_|d=n|r�|j�}|j�djg|D]}d|||f^qX�}td|�nt|�s�d}n|d}|d}|j |�|j
|�dS(Ntstreams, s%s=%ssunrecognized keyword args:
%sii(tsyststdoutRtkeystsorttjoint
ValueErrortlentNonetinittadd(tselftargstkwdsRtktextrastarg((s/usr/lib64/python2.7/pstats.pyt__init__>s
0
cCs�d|_g|_d|_d|_d|_d|_d|_i|_i|_ i|_
|j|�d}z|j�d}Wd|r�|j
dI|jr�|j
|jdIn|j
JnXdS(NiisInvalid
timing datai����(R
tall_calleestfilestfcn_listttotal_ttttotal_callst
prim_callstmax_name_lent top_leveltstatst
sort_arg_dictt
load_statstget_top_level_statsR(R
Rttrouble((s/usr/lib64/python2.7/pstats.pyRTs(
cCs�|si|_n�t|t�r�t|d�}tj|�|_|j�y-tj|�}t j
|j�d|}WnnX|g|_n1t
|d�r�|j�|j|_i|_n|js�td|j|f��ndS(Ntrbs
tcreate_statss.Cannot create or construct a %r object from %r(Rt
isinstancet
basestringtopentmarshaltloadtclosetoststatttimetctimetst_mtimeRthasattrR"t TypeErrort __class__(R
Rtft
file_stats((s/usr/lib64/python2.7/pstats.pyRjs(
cCs�x�|jj�D]�\}\}}}}}|j|7_|j|7_|j|7_d|krtd|j|<ntt|��|j krtt|��|_ qqWdS(Ntjprofileitprofiler(R3iR4(
RtitemsRRRR
RR tfunc_std_stringR(R
tfunctcctncttttcttcallers((s/usr/lib64/python2.7/pstats.pyRs+cGst|s
|St|�dkr0|j|d�n|d}t|�t|�ksd|j|jkrst|�}n|j|j7_|j|j7_|j|j7_|j|j7_x|j D]}d|j |<q�W|j|jkr�|j|_nd|_xg|j
j�D]V\}}||j
krA|j
|}nddddif}t||�|j
|<qW|S(Nii(R RttypeR0RRRRRRR
RRRt iteritemstadd_func_stats(R
targ_listtotherR7R*t
old_func_stat((s/usr/lib64/python2.7/pstats.pyR�s,
* cCs8t|d�}ztj|j|�Wd|j�XdS(s:Write
the profile data to a file we know how to load
back.twbN(tfileR&tdumpRR((R
tfilenameR1((s/usr/lib64/python2.7/pstats.pyt
dump_stats�sii����s
call counttcallstncallsiscumulative timetcumtimet
cumulativeis file nameRDRFisline numbertlinetmoduleis
function
nametnamesname/file/linetnflisprimitive call counttpcallsis
standard
nametstdnameis
internal
timeR+ttottimecCs�|js�i|_}i}xh|jj�D]W\}}|}xB|r�|sQPn||krkd||<Pn|||<|d
}qAWq,Wx|D]
}||=q�Wn|jS(s)Expand all abbreviations that are
unique.ii����(Rtsort_arg_dict_defaultR>(R
tdicttbad_listtwordttuptfragment((s/usr/lib64/python2.7/pstats.pytget_sort_arg_defs�s
cGs�|sd|_|St|�dkrnt|dttf�rnidd6dd6dd6dd6|dg}n|j�}d}d |_d }xA|D]9}|||d}|j|||d7_d
}q�Wg}xY|jj�D]H\}\}} }
}}|j || |
|f|t
|�|f�q�W|jdtt
|�j��g|_}
x|D]}|
j |d�qhW|S(
NiiRQi����RHR+RKits,
tkey((RR R#tinttlongRYt sort_typeRR>tappendR6RRt TupleComptcompare(R
tfieldt
sort_arg_defst
sort_tuplet connectorRVt
stats_listR7R8R9R:R;R<Rttuple((s/usr/lib64/python2.7/pstats.pyt
sort_stats�s2 +
+
cCs|jr|jj�n|S(N(Rtreverse(R
((s/usr/lib64/python2.7/pstats.pyt
reverse_order�s cCsX|j}i|_}d}x�|j�D]�\}\}}}}} t|�}
tt|
��|kr}tt|
��}ni}x*| j�D]\}}
|
|t|�<q�W|
|kr�t||
|||||f�||
<q)|||||f||
<q)W|j}i|_}x|D]}d|t|�<qW||_d|_ d|_
|S(Ni(RR>tfunc_strip_pathR R6R?RR
RRR(R
toldstatstnewstatsRR7R8R9R:R;R<tnewfunct
newcallerstfunc2tcallertold_toptnew_top((s/usr/lib64/python2.7/pstats.pyt
strip_dirs�s.
(
c
Cs�|jr
dSi|_}x�|jj�D]x\}\}}}}}||kr^i||<nxA|j�D]3\}} ||kr�i||<n| |||<qkWq*WdS(N(RRR>(
R
RR7R8R9R:R;R<RpRq((s/usr/lib64/python2.7/pstats.pytcalc_calleess
+
c Csw|}t|t�r�ytj|�}Wn)tjk
rS|d|7}||fSXg}x�|D]+}|jt|��ra|j|�qaqaWn�t|�}t|t �r�d|ko�dknr�t
||d�}|| }nDt|t
tf�r/d|ko|knr/|}||
}nt|�t|�krm|dt|�t|�|f7}n||fS(Ns#
<Invalid regular expression %r>
gg�?g�?is6 List reduced from %r to %r due to restriction <%r>
(R#R$tretcompileterrortsearchR6R_R tfloatR\R](R
tseltlisttmsgtnew_listtrexR7tcount((s/usr/lib64/python2.7/pstats.pyteval_print_amount%s,
+
1
cCs|j}|jr0|j}d|jd}n|jj�}d}x)|D]!}|j|||�\}}qLWt|�}|s�d|fS|j|IJ|t|j�kr�d}x>|D]3}tt|��|kr�tt|��}q�q�Wn|d|fS(Ns
Ordered by: s
s! Random listing order was used
ii( RRR^RRR�R RR6(R
tsel_listtwidtht stat_listR}t selectionR�R7((s/usr/lib64/python2.7/pstats.pytget_print_list?s$
cGsx|jD]}|j|IJq
W|jr4|jJnd}x*|jD]}|j|It|�IJqDW|j|I|jIdI|j|jkr�|jd|jIn|jd|jIJ|jJ|j|�\}}|r|j�x|D]}|j |�q�W|jJ|jJn|S(Nt
isfunction callss(%d primitive calls)sin %.3f secondss (
RRRtfunc_get_function_nameRRRR�tprint_titlet
print_line(R
tamountRFtindentR7R�R|((s/usr/lib64/python2.7/pstats.pytprint_statsWs(
cGs�|j|�\}}|r�|j�|j|d�xM|D]E}||jkrn|j|||j|�q<|j||i�q<W|jJ|jJn|S(Ns called...(R�Rutprint_call_headingRtprint_call_lineR(R
R�R�R|R7((s/usr/lib64/python2.7/pstats.pyt
print_calleesms
c
Gs�|j|�\}}|r|j|d�x@|D]8}|j|\}}}}} |j||| d�q2W|jJ|jJn|S(Nswas
called by...s<-(R�R�RR�R(
R
R�R�R|R7R8R9R:R;R<((s/usr/lib64/python2.7/pstats.pyt
print_callers|s
c
Cs�|jdj|�|IJt}xQ|jj�D]@\}}}}}|r0|j�j�} t| t�}Pq0q0W|r�|jd|dIJndS(Ns Function
R�s ncalls tottime cumtime(RtljusttFalseRt
itervaluestnextR#Rg(
R
t name_sizetcolumn_titlet subheaderR8R9R:R;R<tvalue((s/usr/lib64/python2.7/pstats.pyR��s%s->cCsT|jt|�j|�|I|s1|jJdS|j�}|j�d}x|D]�}t|�}||} t| t�r| \}
}}}
|
|kr�d|
|f}n
d|
f}d|jddt|��t |�t |
�|f}|d}n.d|| t |j
|d �f}|d }|j|||IJd
}qTWdS(NRZs%d/%ds%ds%s %s %s %siiis %s(%r)
%siR�(RR6R�RRR#RgtrjustR tf8R(R
R�tsourcet call_dicttarrowtclistR�R7RNR�R9R8R:R;tsubstatst
left_width((s/usr/lib64/python2.7/pstats.pyR��s,
$
cCs|jdI|jdIJdS(Ns- ncalls tottime percall cumtime
percallsfilename:lineno(function)(R(R
((s/usr/lib64/python2.7/pstats.pyR��s
cCs|j|\}}}}}t|�}||krK|dt|�}n|j|jd�I|jt|�I|dkr�|jdIn|jtt|�|�I|jt|�I|dkr�|jdIn|jtt|�|�I|jt|�IJdS(Nt/i iR�is
s
(RtstrRR�R�RzR6(R
R7R8R9R:R;R<tc((s/usr/lib64/python2.7/pstats.pyR��s(ii����((ii����(((ii����s
call count(ii����((ii����(((ii����s
call
count(ii����((ii����(((ii����scumulative
time(ii����((ii����(((ii����scumulative
time(ii((ii(((iis file name(ii((ii(((iis file
name(ii((ii(((iisline number(ii((ii(((iis file
name(ii((ii(((iis
function
name(ii(ii(ii(ii����((ii����(((ii����sprimitive
call count(ii((ii(((iis
standard
name(ii����((ii����(((ii����s
internal
time(ii����((ii����(((ii����s
internal
time(t__name__t
__module__t__doc__RRRRRRGRSRYRhRjRtRuR�R�R�R�R�R�R�R�R�(((s/usr/lib64/python2.7/pstats.pyR
sH
R`cBs eZdZd�Zd�ZRS(s�This class
provides a generic function for comparing any two tuples.
Each instance records a list of tuple-indices (from most significant
to least significant), and sort direction (ascending or decending) for
each tuple-index. The compare functions can then be used as the
function
argument to the system sort() function when a list of tuples need to be
sorted in the instances
order.cCs
||_dS(N(tcomp_select_list(R
R�((s/usr/lib64/python2.7/pstats.pyR�scCsSxL|jD]A\}}||}||}||kr;|S||kr
|Sq
WdS(Ni(R�(R
tlefttrighttindext directiontltr((s/usr/lib64/python2.7/pstats.pyRa�s
(R�R�R�RRa(((s/usr/lib64/python2.7/pstats.pyR`�s cCs(|\}}}tjj|�||fS(N(R)tpathtbasename(t func_nameRFRLRN((s/usr/lib64/python2.7/pstats.pyRk�scCs|dS(Ni((R7((s/usr/lib64/python2.7/pstats.pyR��scCsZ|d
d
krN|d}|jd�rG|jd�rGd|dd!S|Snd |SdS(Nit~it<t>s{%s}ii����s %s:%d(%s)(R�i(t
startswithtendswith(R�RN((s/usr/lib64/python2.7/pstats.pyR6�s
cCsV|\}}}}}|\}}} }
}|||||| ||
t||�fS(s3Add together all the stats for two profile
entries.(tadd_callers(ttargetR�R8R9R:R;R<tt_cctt_nctt_tttt_ctt t_callers((s/usr/lib64/python2.7/pstats.pyR?�scCs�i}x$|j�D]\}}|||<qWx�|j�D]�\}}||kr�t|t�r�tgt|||�D]}|d|d^qx�||<q�||c|7<q:|||<q:W|S(s*Combine
two caller lists in a single
list.ii(R>R#Rgtzip(R�R�tnew_callersR7Rqti((s/usr/lib64/python2.7/pstats.pyR��s9cCs+d}x|j�D]}||7}qW|S(s@Sum
the caller statistics to get total number of calls
received.i(R�(R<R9RH((s/usr/lib64/python2.7/pstats.pytcount_callsscCsd|S(Ns%8.3f((tx((s/usr/lib64/python2.7/pstats.pyR�st__main__tProfileBrowsercBs�eZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d�Zd �Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(cCsNtjj|�d|_d|_tj|_|dk rJ|j |�ndS(Ns%
(
tcmdtCmdRtpromptR
RRRRtdo_read(R
tprofile((s/usr/lib64/python2.7/pstats.pyR&s cCs�|j�}g}x�|D]�}y|jt|��wWntk
rLnXyKt|�}|dkst|dkr�|jdIJwn|j|�wWntk
r�nX|j|�qW|jr�t|j|�|�n
|jdIJdS(Niis#Fraction
argument must be in [0, 1]sNo statistics object is
loaded.(tsplitR_R\RRzRRtgetattr(R
tfnRLRt processedttermtfrac((s/usr/lib64/python2.7/pstats.pytgeneric.s,
cCsR|jdIJ|jdIJ|jdIJ|jdIJ|jdIJ|jdIJdS(NsArguments
may be:s0* An integer maximum number of entries to print.s:* A decimal
fractional number between 0 and 1, controllings- what fraction of selected
entries to print.s8* A regular expression; only entries with function
namess that match it are
printed.(R(R
((s/usr/lib64/python2.7/pstats.pytgeneric_helpFs
cCs-|jr|jj|�n
|jdIJdS(NsNo
statistics object is
loaded.i(RRR(R
RL((s/usr/lib64/python2.7/pstats.pytdo_addNs
cCs|jdIJdS(Ns>Add
profile info from given file to current statistics
object.(R(R
((s/usr/lib64/python2.7/pstats.pythelp_addTscCs|jd|�S(NR�(R�(R
RL((s/usr/lib64/python2.7/pstats.pyt
do_calleesWscCs|jdIJ|j�dS(Ns6Print callees statistics from
the current stat
object.(RR�(R
((s/usr/lib64/python2.7/pstats.pythelp_calleesYs
cCs|jd|�S(NR�(R�(R
RL((s/usr/lib64/python2.7/pstats.pyt
do_callers]scCs|jdIJ|j�dS(Ns6Print callers statistics from
the current stat
object.(RR�(R
((s/usr/lib64/python2.7/pstats.pythelp_callers_s
cCs|jdIJdS(NRZi(R(R
RL((s/usr/lib64/python2.7/pstats.pytdo_EOFcs
cCs|jdIJdS(NsLeave
the profile
brower.(R(R
((s/usr/lib64/python2.7/pstats.pythelp_EOFfscCsdS(Ni((R
RL((s/usr/lib64/python2.7/pstats.pytdo_quitiscCs|jdIJdS(NsLeave
the profile
brower.(R(R
((s/usr/lib64/python2.7/pstats.pyt help_quitkscCs�|r�yt|�|_WnUtk
r@}|j|dIJdStk
rp}|j|jjdI|IJdSX|d|_n?t|j�dkr�|jd
}|j |�n
|jdIJdS(Nit:s% ii����s1No statistics object
is current -- cannot reload.i(
RRtIOErrorRt ExceptionR0R�R�R R�(R
RLRterr((s/usr/lib64/python2.7/pstats.pyR�ns
cCs|jdIJ|jdIJdS(Ns+Read
in profile data from a specified file.s*Without argument, reload the
current
file.(R(R
((s/usr/lib64/python2.7/pstats.pyt help_reads
cCs*|jr|jj�n
|jdIJdS(NsNo
statistics object is
loaded.i(RRjR(R
RL((s/usr/lib64/python2.7/pstats.pyt
do_reverse�s
cCs|jdIJdS(Ns/Reverse the sort order of the
profiling
report.(R(R
((s/usr/lib64/python2.7/pstats.pythelp_reverse�scs�|js|jdIJdS|jj��|rjt�fd�|j�D��rj|jj|j��nH|jdIJx8tjj�D]'\}}|jd||dfIJq�WdS(NsNo
statistics object is
loaded.c3s|]}|�kVqdS(N((t.0R�(tabbrevs(s/usr/lib64/python2.7/pstats.pys <genexpr>�ss/Valid
sort keys (unique prefixes are accepted):s%s --
%sii( RRRYtallR�RhRRSR>(R
RLR[R�((R�s/usr/lib64/python2.7/pstats.pytdo_sort�s
(
cCs|jdIJ|jdIJdS(Ns.Sort
profile data according to specified keys.s3(Typing `sort' without
arguments lists valid
keys.)(R(R
((s/usr/lib64/python2.7/pstats.pyt help_sort�s
cGs)gtjD]}|j|�r
|^q
S(N(RRSR�(R
ttextRta((s/usr/lib64/python2.7/pstats.pyt
complete_sort�scCs|jd|�S(NR�(R�(R
RL((s/usr/lib64/python2.7/pstats.pytdo_stats�scCs|jdIJ|j�dS(Ns.Print
statistics from the current stat
object.(RR�(R
((s/usr/lib64/python2.7/pstats.pyt
help_stats�s
cCs*|jr|jj�n
|jdIJdS(NsNo statistics
object is
loaded.(RRtR(R
RL((s/usr/lib64/python2.7/pstats.pytdo_strip�s cCs|jdIJdS(Ns<Strip
leading path information from filenames in the
report.(R(R
((s/usr/lib64/python2.7/pstats.pyt
help_strip�scCs|jdIJdS(NsShow help for a given
command.(R(R
((s/usr/lib64/python2.7/pstats.pyt help_help�scCs|r
|SdS(N(R
(R
tstopRL((s/usr/lib64/python2.7/pstats.pytpostcmd�sN(R�R�R
RR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s/usr/lib64/python2.7/pstats.pyR�%s4 is*Welcome
to the profile statistics browser.sGoodbye.(
R�RR)R+R&Rvt functoolsRt__all__RR`RkR�R6R?R�R�R�R�R�treadlinetImportErrorR�R�R targvtinitprofileR
tbrowserRtcmdlooptKeyboardInterrupt(((s/usr/lib64/python2.7/pstats.pyt<module>sF ��
�