Ñò
‡„[Jc @ sº d Z d d k Z d d k Z d d k l Z d d k Z d Z e ƒ Z h e ƒ d 6e d 6d d 6d d 6Z d a d d
„ Z
d h d d „ Z d „ Z d „ Z d „ Z d „ Z d S( s§ Profiling support for unit and performance tests.
These are special purpose profiling methods which operate
in a more fine-grained way than nose's profiling plugin.
iÿÿÿÿN( t function_namedt profiledt function_call_countt conditional_call_countt targetst reportt timet callst sortt limitc sa ˆ d j o
d ‰ n ˆ t j o
d ˆ GHn t i ˆ ƒ d ˆ ‰ ‡ ‡ ‡ f d † } | S( s7 Optional function profiling.
@profiled('label')
or
@profiled('label', report=True, sort=('calls',), limit=20)
Enables profiling for a function when 'label' is targetted for
profiling. Report options can be supplied, and override the global
configuration and command-line options.
t anonymous_targets' Warning: redefining profile target '%s's %s.profc s( ‡ ‡ ‡ ‡ f d † } t | ˆ i ƒ S( Nc sö ˆ t d j o" ˆ i d d ƒ o ˆ | | Ž St ˆ ˆ | | Ž \ } } } ˆ i d t d ƒ } | ow ˆ i d t d ƒ } ˆ i d t d ƒ } d ˆ ˆ f GH| ƒ } | i | Œ | o | i | ƒ qå | i ƒ n t i ˆ ƒ | S( NR t alwaysR R R s# Profile report for target '%s' (%s)( t profile_configt gett Nonet _profilet
sort_statst print_statst ost unlink( t argst kwt elapsedt
load_statst resultR t sort_R t stats( t targett target_optst filenamet fn( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR + s$
( R t __name__( R R ( R R R ( R s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyt decorator* s N( R t all_targetst add( R R R ( ( R R R s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR s
gš™™™™™©?c sÕ t t i ƒ } d i g } t i D] } | t | ƒ q# ~ ƒ ‰ xb | oZ d i g } | D] } | t | ƒ q] ~ ƒ } | | j o | | ‰ Pn | i ƒ qE Wˆ d j o d „ S‡ ‡ ‡ f d † } | S( sã Assert a target for a test case's function call count.
count
Optional, general target function call count.
versions
Optional, a dictionary of Python version strings to counts,
for example::
{ '2.5.1': 110,
'2.5': 100,
'2.4': 150 }
The best match for the current running python will be used.
If none match, 'count' will be used as the fallback.
variance
An +/- deviation percentage, defaults to 5%.
t .c S s | S( ( ( R ( ( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyt h s c s( ‡ ‡ ‡ ‡ f d † } t | ˆ i ƒ S( Nc sá zµ d ˆ i } t | ˆ | | Ž \ } } } | ƒ } | i } | i d d ƒ | i ƒ t ˆ ˆ ƒ } | ˆ | j p | ˆ | j o$ t d | ˆ d ˆ ˆ f ƒ ‚ n | SWd t i i | ƒ o t i
| ƒ n Xd S( Ns %s.profR t
cumulativesJ Function call count %s not within %s%% of expected %s. (Python version %s)id ( R R t total_callsR R t intt AssertionErrorR t patht existsR ( R R R R t stat_loaderR R R t deviance( t countt variancet
py_versionR ( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyt countedk s"
( R R ( R R0 ( R- R. R/ ( R s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR j s N( t listt syst version_infot joint strt popR ( R- t versionsR. R3 t _[1]t vt _[2]t versionR ( ( R- R. R/ s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR F s 3 0
c s ‡ ‡ f d † } | S( sb Apply a function call count conditionally at runtime.
Takes two arguments, a callable that returns a key value, and a dict
mapping key values to a tuple of arguments to function_call_count.
The callable is not evaluated until the decorated function is actually
invoked. If the `discriminator` returns a key not present in the
`categories` dictionary, no call count assertion is applied.
Useful for integration tests, where running a named test in isolation may
have a function count penalty not seen in the full suite, due to lazy
initialization in the DB-API, SA, etc.
c s% ‡ ‡ ‡ f d † } t | ˆ i ƒ S( Nc sO ˆ i ˆ ƒ d ƒ } | d j o ˆ | | Ž St | Œ ˆ ƒ } | | | Ž S( N( R
R R ( R R t criteriat rewrapped( R t
discriminatort
categories( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyt
at_runtime— s
( R R ( R R@ ( R> R? ( R s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR – s ( ( R> R? R ( ( R> R? s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR ‡ s c O s‰ t pJ d a t i d j o0 y d d k } d a WqM t j
o qM XqQ n t d j o t | | | | Ž St | | | | Ž Sd S( Nt hotshoti i iÿÿÿÿt cProfile( i i ( t profilerR2 R3 RB t ImportErrort _profile_cProfilet _profile_hotshot( R R R R RB ( ( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR ¢ s
c
s› d d k } d d k } d d k ‰ d d k } ‡ ‡ f d † } | i ƒ | i ƒ } | i d t ƒ t ƒ d ˆ ƒ| i ƒ } | | | t ƒ d f S( Niÿÿÿÿc s
ˆ i ˆ ƒ S( ( t Stats( ( R t pstats( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR$ µ s s result = fn(*args, **kw)R R ( RB t gcRH R t collectt runctxt globalst locals(
R R R R RB RI R R t begant ended( ( R RH s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyRE ² s 0
c s¹ d d k } d d k ‰ d d k ‰ d d k } ‡ ‡ f d † } | i ƒ ˆ i ˆ ƒ } | i ƒ } | i ƒ z | | | Ž } Wd | i ƒ | i ƒ }
| i ƒ X|
| | | f S( Niÿÿÿÿc s ˆ i i ˆ ƒ S( ( R t load( ( RA R ( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyR$ Á s ( RI RA t
hotshot.statsR RJ t Profilet startt stopt close( R R R R RI R R t profRN R RO ( ( R RA s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyRF ¿ s 0
( s profileds function_call_counts conditional_call_count( s times calls( t __doc__R R2 t sqlalchemy.utilR t configt __all__t setR! t TrueR R RC R R R R RE RF ( ( ( s= /usr/lib/python2.6/site-packages/sqlalchemy/test/profiling.pyt s
1A