0

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).

12
  • 1
    Welcome to Ask Different. Your phrasing of these calculations confuses me since the virtual memory model on macOS makes these values (especially swap) transient and squishy. It feels to me you’re trying to re-implement memory pressure which is already provided by the OS. Could you edit this to explain more the end goal you have in mind? What are you trying to do with these measures?
    – bmike
    Oct 20, 2023 at 14:09
  • 1
    Also - browse this thread for some very well written discussion on what the definitions of various measures are and how they relate to the built in tools.
    – bmike
    Oct 20, 2023 at 14:15
  • Hey @bmike , thanks for the quick reply. I have added an example at the end to explain what I want to achieve.
    – user508046
    Oct 20, 2023 at 14:20
  • 1
    What do you do with this percentage when you have it? Generally, macOS manages memory very well, and you shouldn't need to do anything. Not using Chrome will of course reduce your memory use considerably, and improve your privacy!
    – benwiggy
    Oct 21, 2023 at 9:04
  • 1
    Yes, but what do you do once you know the value? Is this research? Unless you're actually experiencing a memory leak that's affecting performance, there's no need to watch over the memory manager. Also, by "portal", you mean a website?
    – benwiggy
    Oct 26, 2023 at 13:35

0

You must log in to answer this question.