Settings

Theme

Chronic - Python Instrumentation

github.com

34 points by dcraw 12 years ago · 11 comments

Reader

JeffJenkins 12 years ago

This is cool. I implemented an extremely similar system for my last job. The data was dumped into mongo and then we visualized it with stacked bar graphs.

One thing to consider since you're using a count+total model is that the most interesting timings will often be the 90th or 99th percentile, so by calculating averages you might be missing useful information.

I ran into some issues with the implementation after switching to using an async framework since the code was no longer a series of nested function calls. Since the current best practice is coroutines where this will still work I think it's okay, but you should consider how someone using callbacks might time their code. In my case I was in a hurry so I manually called the equivalent of your __enter__ and __exit__, but it was pretty ugly and left a lot of room for bugs.

  • dcrawOP 12 years ago

    You're totally right on the averages. I'll add the percentiles but maybe I can also make it extensible somehow.

    I haven't thought about callback code at all... if you have any ideas or sample code to share, it would be great if you could create a github issue for it.

    Thanks!

smilliken 12 years ago

See also: http://pycounters.readthedocs.org/en/latest/

drdaeman 12 years ago

Trivial but useful. Next time, instead of kicking in my own custom timing decorator (5-liner, but...) I'll probably use this. [Edit: pycounter looks even nicer, didn't heard of them before, thanks for sharing!]

The only downside I see, it does record function name, but doesn't record module name (and, for class members, classname). For example, it wouldn't be too useful to see "authorize" instead of "ppp.common.authorize" in RADIUS server profiling logs. :)

  • dcrawOP 12 years ago

    Yeah, the simplest thing to do would be to add the module name, which I may do. You can also pass a name parameter to the decorator.

  • dcrawOP 12 years ago

    Thanks for your thoughts!

armon 12 years ago

We built a similar decorator/context manager for profiling, but it is really much more useful if you can export the data to statsite + graphite so that you can graph and view it on an on going basis. The insight into the runtime is much more valuable when you have historic data to compare it to.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection