[BangPypers] log and figure out what bits are slow and optimize them.
Vishal
vsapre80 at gmail.com
Mon Feb 13 12:41:57 CET 2012
Hi,
Since you want to profile a single method (or a bunch of methods), it makes
sense to line_profile them.
you can add that capability as well.
See:http://packages.python.org/line_profiler/
<http://packages.python.org/line_profiler/>
getit: http://pypi.python.org/pypi/line_profiler
Enjoy,
Vishal Sapre
On Sun, Feb 12, 2012 at 1:08 PM, Saju M <sajuptpm at gmail.com> wrote:
> 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
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
Thanks and best regards,
Vishal Sapre
---
"Life is 10% how you make it, and 90% how you take it"
"बहुजन हिताय, बहुजन सुखाय (Benefit for most people, Happiness for most
people.)"
---
Please DONT print this email, unless you really need to.
Save Energy & Paper. Save the Earth.
More information about the BangPypers
mailing list