1

I am beginner and I am looking for some help for measuring how much memory a specific program is taking to complete its execution? Is there any article or built in functions I need to start with.

closed as off-topic by Ghanima Oct 6 '16 at 14:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Ghanima
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Let me know what exactly you are looking for and specific program. May be these command might help.. To show all processes - ps -ef List processes ps ax List processes To kill a specific program.. sudo killall Myproj.a Thanks. – Hussain Patel Oct 6 '16 at 5:21
  • 1
    I am closing this as off-topic as it is not specific to the Pi. Profiling the performance of a python script belongs to StackOverflow but beware of the tough crowd there and check for duplicate questions first. – Ghanima Oct 6 '16 at 14:56
3

You may want to start by running top and locating your program in the list. It will look similar to this:

enter image description here

As you can see, there are 3 different memory metrics, each with its own gotchas:

  • VIRT - this is virtual memory, which lists all the addresses your program is allowed to access. As its name suggests, it doesn't have to be fully backed by actual RAM. However, if your program does access all these addresses, it will be able to consume this much without requesting any new memory from the system.
  • RES - this is how much of your program's memory stays resident in RAM. If you have swap enabled, this value will depend not only on your program's behaviour, but also on the swapping strategy.
  • SHR - this is how much resident memory your program shares with other processes (the most typical example is shared libraries). When your program stops using some of this memory, its SHR and RES values will go down but no actual memory will be freed.

Hope this clears some things up.

  • 1
    Also check out htop, I like to use it for its tree-view of process threads. Installs with sudo apt-get install htop – jogco Oct 6 '16 at 8:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.