Ñò ô†³Kc @s×dZddkZddkZddkZddkZddkZddkZddkZddkl Z ddk l Z ddgZ de fd„ƒYZd„Zd „Zd e fd „ƒYZd d d„ZdS(se Middleware that profiles the request and displays profiling information at the bottom of each page. iÿÿÿÿN(tStringIO(tresponsetProfileMiddlewaretprofile_decoratorcBs/eZdZdZdddd„Zd„ZRS(s• Middleware that profiles all requests. All HTML pages will have profiling information appended to them. The data is isolated to that single request, and does not include data from previous requests. This uses the ``hotshot`` module, which affects performance of the application. It also runs in a single-threaded mode, so it is only usable in development environments. sWclear: both; background-color: #ff9; color: #000; border: 2px solid #000; padding: 5px;sprofile.log.tmpi(cCs.||_tiƒ|_||_||_dS(N(tappt threadingtLocktlockt log_filenametlimit(tselfRt global_confRR ((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyt__init__&s  c sŒg‰g‰d‡‡‡fd†‰‡‡‡‡fd†}ˆiiƒz.tiˆiƒ}|idˆiddƒƒz|i|ƒWd|i ƒXdi ˆƒ‰ˆd}t i |dƒ}|djp|i dƒ oˆgStiiˆiƒ}|iƒ|id d ƒt|iˆiƒ}t|iˆiƒ} ˆd ˆiti|ƒti| ƒf7‰ˆgSWdˆiiƒXdS( Ncs*ˆi||gƒˆ|||ƒˆiS(N(textendtappend(tstatustheaderstexc_info(tbodytstart_responsetcatch_response(s7/usr/lib/python2.6/site-packages/paste/debug/profile.pytreplace_start_response1scsIˆiˆˆƒ}zˆi|ƒWdt|dƒo|iƒnXdS(Ntclose(RR thasattrR(tapp_iter(RRR tenviron(s7/usr/lib/python2.6/site-packages/paste/debug/profile.pytrun_app5s tURLt PATH_INFOtis content-types text/htmlttimetcallss
%s
%s
(tNoneRtacquirethotshottProfileRtaddinfotgettruncallRtjoinRt header_valuet startswithtstatstloadt strip_dirst sort_statstcapture_outputt print_statsR t print_callerststyletcgitescapetrelease( R RRRtprofRt content_typeR*toutputtoutput_callers((RRRR RRs7/usr/lib/python2.6/site-packages/paste/debug/profile.pyt__call__.s4    & N(t__name__t __module__t__doc__R1R R R9(((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyRs   cOsCtƒ}ti}|t_z|||ŽWd|t_X|iƒS(N(Rtsyststdouttgetvalue(tfunctargstkwtoutt old_stdout((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyR.Vs    c s1ˆidƒod„}|S‡fd†}|S(sú Profile a single function call. Used around a function, like:: @profile_decorator(options...) def ... All calls to the function will be profiled. The options are all keywords, and are: log_file: The filename to log to (or ``'stdout'`` or ``'stderr'``). Default: stderr. display_limit: Only show the top N items, default: 20. sort_stats: A list of string-attributes to sort on. Default ``('time', 'calls')``. strip_dirs: Strip directories/module names from files? Default True. add_info: If given, this info will be added to the report (for your own tracking). Default: none. log_filename: The temporary filename to log profiling data to. Default; ``./profile_data.log.tmp`` no_profile: If true, then don't actually profile anything. Useful for conditional profiling. t no_profilecSs|S(N((R@((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyt decorator…scs‡‡fd†}|S(Ncstˆˆ||ŽS(N(tDecoratedProfile(RARB(R@toptions(s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyt replacement‰s((R@RI(RH(R@s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyRFˆs(R%(RHRF((RHs7/usr/lib/python2.6/site-packages/paste/debug/profile.pyRbs " RGcBs8eZeiƒZd„Zd„Zd„Zd„ZRS(cKs||_||_dS(N(R@RH(R R@RH((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyR ’s cOs<|iiƒz|i|i||ŽSWd|iiƒXdS(N(RR!tprofileR@R4(R RARB((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyR9–s c Osq|i}|iddƒ}ti|ƒ}|id|i|||Žƒ|idƒo|id|dƒnd}zKtiƒ}y|i|||Ž} Wnt i ƒ}nXtiƒ} Wd|i ƒXti i |ƒ} ti|ƒ|idtƒo| iƒn| i|iddƒŒ|id d ƒ} t| i| ƒ} t| i| ƒ}|id ƒ}|djo t i}nY|djo t i}n?t|dƒ}|idddƒ|idtidƒƒ|id|i|||Žƒ|id| |ƒ|i| ƒ|i|ƒ|djo|i ƒn|o|d|d|d‚n| S(NRsprofile_data.log.tmps Function Calltadd_infos Extra infoR,R-RRt display_limititlog_filetstderrt-R>tas %s i<s Date: %s s%csFunction call: %s sWall time: %0.2f seconds iii(stimescalls(Nsstderr(ROsstdout(NROsstdoutsstderr(RHR%R"R#R$tformat_functionR RR&R=RRR*R+tostunlinktTrueR,R-R.R/R0RNR>topentwritetstrftime(R R@RARBtopst prof_filenameR5Rt start_timetresulttend_timeR*RLR7R8t output_filetf((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyRJsX               cOsgtt|ƒ}|ig}|iƒD]\}}|d||fq&~ƒd|idi|ƒfS(Ns%s=%rs%s(%s)s, (tmaptreprR titemsR:R'(R R@RARBt_[1]tktv((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyRQÎs8( R:R;RRRR R9RJRQ(((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyRGŽs     1sprofile.log.tmpi(cCs"t|ƒ}t|d|d|ƒS(s  Wrap the application in a component that will profile each request. The profiling data is then appended to the output of each page. Note that this serializes all requests (i.e., removing concurrency). Therefore never use this in production. RR (tintR(RR RR ((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pytmake_profile_middlewareÕs (R<R=RRR"t hotshot.statsRR2Rt cStringIORtpasteRt__all__tobjectRR.RRGRf(((s7/usr/lib/python2.6/site-packages/paste/debug/profile.pyts         A ,I