0

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

KZiovas
  • 3,491
  • 3
  • 26
  • 47
  • You could look into [profilers](https://docs.python.org/3/library/profile.html) – Tobi208 Jan 27 '22 at 12:56
  • For execution time you can use the [`timeit` module](https://docs.python.org/3/library/timeit.html), for CPU/RAM usage I'd use an external program (e.g. Windows Task Manager, UNIX htop). – jfaccioni Jan 27 '22 at 12:58
  • @jfaccioni I wish to avoid using an external program and just get the stats from the script itself – KZiovas Jan 27 '22 at 13:04
  • @Tobi208 hey. Thanks from what I see profilers only give time statistics right? No cpu or ram – KZiovas Jan 27 '22 at 14:26
  • How about [this](https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python) – Tobi208 Jan 27 '22 at 14:28
  • @Tobi208 yeah I ve seen it than you. I a using this at the moment to make my own solution based on this tool. But there is nothing ready made at the moment it seems which is weird. – KZiovas Jan 27 '22 at 16:36

1 Answers1

1

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

KZiovas
  • 3,491
  • 3
  • 26
  • 47