0

Possible Duplicate:
How can you profile a Python script?

I'm developing an API with several packages collaborating together via various gui's and I'm slowly thinking about how I would be able to analyze the amount of calls the packages and modules and methods and classes are getting from the user under a normal run. Thinking I might be able to detect bottlenecks and find out where most of the work is required, while also seeing where I might be able to merge similar functionality.

I'm picturing it like a simple bar chart

enter image description here

Where each bar represents one method, module or package depending on which "depth" you're interested to look at, and the height axis is the amount of calls it has gotten.

Is there anything similar currently and/or how would you implement this in Python?

I'm thinking of putting a simple logger at the entrance of each method, under say Debug, and then filter those out when I'm making the diagram. But that means my code would get messier and I'd have to remember to do it for all of them. What would be easier is if I could apply a compile-time decorator when compiling it with say a certain flag. Is that possible with Python?

Thanks

asked Nov 27, 2012 at 9:38
1
  • Indeed, I've found what I was looking for. Thank you! Commented Nov 27, 2012 at 12:20

2 Answers 2

1

I think the trace module from the stdlib would be helpful.

answered Nov 27, 2012 at 10:29
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that link opened up a good can of worms that I have overlooked.
0

There's decorator mentioned in the PythonDecoratorLibrary for profiling/tracing a single function. It would give you a running start in implementing what you describe.

You don't really compile things in Python, it's done on-the-fly, but you can vary the decorator definition based on a runtime flag to turn it on and off.

answered Nov 27, 2012 at 12:11

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.