Can someone suggest what would be the best practice or a suitable library to determine:
- Number of CPU cycles used during execution of a Python function?
- Amount of Memory used by the same Python function?
I had looked at guppy and meliae, but still can’t get granular to the function level? Am I missing something?
UPDATE
The need for asking this question is to solve a specific situation which is, the scenario is that we have a set of distributed tasks running on cloud instances, and now we need to reorganize the placement of tasks on right instance types withing the cluster, for example high memory consuming functional tasks would be placed on larger memory instances and so on. When I mean tasks (celery-tasks), these are nothing but plain functions for which we need to now profile their execution usage.
Thanks.
You may want to look into a
CPU profilerfor Python:http://docs.python.org/library/profile.html
Example output of
cProfile.run(command[, filename])Also,
memoryneeds a profiler too:open source profilers: PySizer and Heapy