I want to calculate the memory usage as a percentage for some processes on the device.
That is, how much percent of total memory a particular process is taking on the system. (Need it for reporting some metrics for both Windows and Mac devices, so the percentage seems to be consistent among both)
With the top
command, we get the memory usage as size (KB, MB, GB) and the value is also not the actual physical memory (RAM) used but the virtual memory (physical + swap memory).
Q1. So, if I manually calculate the memory usage percentage, what formula should I use:
- (process mem usage from top command) / (total physical memory + swap space used) * 100
- (process mem usage from top command) / (total physical memory + swap space alloted) * 100
- (process mem usage from top command) / (total physical memory) * 100
Q2. Is there any other way other than top command which only gives physical memory usage for individual processes so that I can use the third formula above?
Example: If Chrome is using 1 GB of memory, then I can say that it is using xx % of memory. But to calculate that I need the same units in the numerator (memory usage of the process) and denominator (memory available in the system).