Measure the use of Python code in the CPU and Memory

Asked

Viewed 939 times

-1

I have a code and I want to know how much he’s getting from the processor and the memory.

  • 2

    Ctrl+Shift+Esc on Windows 10 and analyze the python.exe process

  • This command opens the Task Manager

  • But there will show the data at runtime?

1 answer

1


If you are not using task manager, you can use psutils library

import psutil 

print(psutil.cpu_percent())                    # Em porcentagem, uso da CPU
print(psutil.virtual_memory()._asdict())       # Em dicionário informações de memória física

returns, for example:

14.2

Ordereddict(['total', 8272900096), ('available', 3767132160), ('Percent', 54.5), ('used', 4505767936), ('free', 3767132160)])

Edit: There is a process id approach as well, "a little' more complex if you don’t like it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.