'How to measure execution stats of a Python script CPU usage, RAM usage, disk usage etc?

Is there a Python module that you can use to get execution stats for a piece of code or a python app ? For example something like:

get_stats.start() 
#python code 
stats = get_stats.end()

The stats I am interested in are cpu usage, ram usage and execution time



Solution 1:[1]

So using psutil i made this helper metrics class you can see in this gist

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KZiovas