[BangPypers] log and figure out what bits are slow and optimize them.
Saju M
sajuptpm at gmail.com
Sun Feb 12 08:38:19 CET 2012
Hi,
I wrote a decorator using cProfile.
Issue is log-file getting messed up with logs of unwanted method
calls(library calls).
I tried with prof.getstats() and prof.print_stats(), prof.getstats() force
to code extra loops to get infos.
I am also planning to enable/disable this logging using DEBUG flag.
Have any suggestions to improve this code ??? or any other-way ??
import cProfile
def debug_time(method):
def timed(*args, **kw):
if DEBUG:
prof = cProfile.Profile()
prof.enable(subcalls=False, builtins=False)
result = prof.runcall(method, *args, **kw)
#prof.print_stats()
msg = "\n\n\n\n#######################################"
msg += "\n\nURL : %s" %(tg.request.url)
msg += "\nMethod: %r" %(method.__name__)
print "--ddd--------", type(prof.getstats())
msg += "\n\nStatus : %s" %(prof.print_stats())
msg += "\n\n#######################################"
print msg
LOGGER.debug(msg)
else:
result = method(*args, **kw)
return result
return timed
ref :
http://stackoverflow.com/questions/5375624/a-decorator-that-profiles-a-method-call-and-logs-the-profiling-result
On Fri, Feb 10, 2012 at 7:24 PM, Noufal Ibrahim <noufal at nibrahim.net.in>wrote:
> Saju M <sajuptpm at gmail.com> writes:
>
> > Hi,
> >
> > Yes i saw profile module, I think, i have to do function call via
> > cProfile.run('foo()') I know, we can debug this way.
>
> You should do this in development to identify pain points. The results
> might be interesting.
>
>
> > But, I need a fixed logging system and want to use it in production.
> > I think, we can't permanently include profile's debugging code in
> > source code,
> > will cause any performance issue ??
>
> Yes. You can't do that.
>
> One option is to use something like graphite to capture statistics that
> your app emits. It should be able to give you a graph of various
> parameters at various times.
>
>
> [...]
>
>
> --
> ~noufal
> http://nibrahim.net.in
>
> If Roosevelt were alive, he'd turn over in his grave. -Samuel Goldwyn
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
Regards
Saju Madhavan
+91 09535134654
More information about the BangPypers
mailing list