15

Is there a way to see memory usage per app in macOS? That is, I want to see the total memory consumed by each app, including its child processes.

The Activity Monitor shows memory usage by process which makes it hard to determine, for example, how much memory the Chrome app is using, since it spawns multiple processes.

2
  • For Chrome specifically have you used its built in task manager?
    – Atari911
    Commented Jun 12, 2015 at 4:55
  • 1
    Alternatively, don't use Chrome, and your memory management issues will melt away. ;-)
    – benwiggy
    Commented Apr 16, 2023 at 11:22

6 Answers 6

9

Activity Monitor > View > All Processes, Hierarchically ought to do it, with a bit of scrolling...

enter image description here

11
  • 12
    This seemed promising. But on checking I found that the it still doesn't show the total memory being used by an App. It's just individual processes grouped under the parent process. (You can verify that for the Safari and Mail apps shown in your screen shot -- the memory usage doesn't add up). In fact, on my Mac currently, the Chrome.app has child processes that individually seem to be using more memory than the parent Chrome.app process.
    – Himanshu P
    Commented Sep 7, 2014 at 8:42
  • 1
    Without knowing for certain, I'd say that you would need to add up all the child processes, then add the parent, to get the true total - I think you're assuming the parent IS the total. I would assume it's not. A simple test for that would be to check the kernel task total, which is nowhere near the sum of it's sub-processes.
    – Tetsujin
    Commented Sep 7, 2014 at 8:44
  • 3
    That's exactly what I said above... this view doesn't show the total memory usage per app. I am looking for a method that does. I can't be bothered to add 30 3-digit numbers each time I want to see how much memory chrome is using.
    – Himanshu P
    Commented Sep 7, 2014 at 9:28
  • 1
    Then I think you're out of luck - they are child processes, subordinate but separate to the main process. My fairly decent Google-Fu finds no utility that will add them up automatically. Maybe someone else can find one...
    – Tetsujin
    Commented Sep 7, 2014 at 9:59
  • 10
    It's not that simple, processes can share memory, so total memory is not as easy as add all memory from the children. Plus, there's virtual versus real memory. It's a slightly complicated beast. :-(
    – chmac
    Commented Dec 12, 2014 at 15:31
6

If you're not fussed about having a nice GUI and have a python distro installed, you can use psrecord.

  • Open Terminal
  • Install with pip install psrecord
  • Get the Chrome PID (can use activity monitor)

Activity Monitor

  • Run psrecord, with the --include-children flag, providing the PID as an argument

I would recommend specifying some duration (60s in my examples) otherwise psrecord would continue running until Chrome is terminated.

psrecord will record the CPU usage (%) and Memory usage (MB) which you can have it output as either a plot:

psrecord 95639 --plot chrome.png --include-children --duration 60

psrecord plot

or a log file:

psrecord 95639 --log chrome.txt --include-children --duration 60
# Elapsed time   CPU (%)     Real (MB)   Virtual (MB)
       0.000        0.000     1672.918    65500.004
       0.078        2.400     1672.922    65500.004
       0.161        3.200     1672.926    65500.004
       0.245        3.400     1672.926    65500.004
       0.329        4.300     1672.930    65500.004
       0.410        3.400     1672.934    65500.004
       0.492        3.900     1672.938    65500.004
       0.580        2.700     1672.941    65500.004
       0.667        3.200     1672.945    65527.895
       0.748        3.100     1672.945    65500.004
       0.830        3.200     1672.949    65500.004
       0.911        3.000     1672.953    65500.004
       0.993        3.200     1672.953    65500.004
       1.074        3.500     1672.957    65500.004
1

I'm totally a fan of htop which can be installed via Homebrew, which is more powerful and flexible than the activity monitor.

Run it in a console, I think it's straightforward.

1
  • 2
    htop I think has the same problem as Activity Monitor. That is, if you collapse child processes in hierarchical view, it doesn't total up the child processes, it only shows memory of parent process. Unless there's some button I need to push I haven't found yet?
    – Keegan
    Commented Dec 10, 2020 at 18:12
1

For any one coming here, you can use this script:

a=0;for i ($(ps -e -o %mem,command | grep 'Google Chrome' | grep -oE '\d\.\d /Applications' | grep -oE '\d\.\d')) { a=$((a+i)) }; print $a

Change Google Chrome to your name of app, that will work for app under the /Application directory.

8
  • 1
    What does this command do? How does it work? What will be an example result? Please edit your answer to add more supporting information and explanations.
    – Thinkr
    Commented Apr 16, 2023 at 8:39
  • 1
    @thinkr It seems to be rather complicated and zsh-specific way of writing ps -e -o %mem,command | awk '/Google Chrome/ { size += $1 } END { print size}'. So basically it uses ps to get the memory footprint of all processes, filters for Google Chrome and sums up the memory needed by all its processes.
    – nohillside
    Commented Apr 16, 2023 at 8:50
  • @nohillside Thank you for explaining it to me but I wanted to advise @ ZHDI on how to write a good answer, comprehensible to all.
    – Thinkr
    Commented Apr 16, 2023 at 8:52
  • 1
    @thinkr I know, your first comment was spot on. Primarily wanted to point out that the same result can be achieved way simpler by just using awk to do all the work.
    – nohillside
    Commented Apr 16, 2023 at 8:56
  • 1
    @Thinkr It doesn't solve the problem stated in the question ("That is, I want to see the total memory consumed by each app, including its child processes.") as it assumes that all child processes have "Google Chrome" somewhere in their name or path (neither does the solution posted by ZHDI, actually, nor most of the other answers). You can't derive the full memory footprint without looking at the whole process tree.
    – nohillside
    Commented Apr 16, 2023 at 9:03
1

iStat Menus does provide the memory used for the 5 applications that use the most memory summing up their child processes (although it can also show sepate process values like Activity Monitor).

0

There is USS in MacOS available.

The USS (Unique Set Size) is the memory which is unique to a process and which would be freed if the process was terminated right now.

psutil>4.0 Python library can access it

Here is I would use it

sudo python3 -c "import psutil;print(sum(p.memory_full_info().uss for p in psutil.Process(pid=292).children())/1024/1024);"

where pid=292 is PID of most outer process from Activity Monitor.

3
  • 2
    This doesn't seem to work with Mojave. Running with sudo, trying to get the info for a process executing as my uid, I get "psutil.AccessDenied". I'm sure it's some sort of macOS security feature, but I thought I'd mention it.
    – m0j0
    Commented Sep 7, 2019 at 23:30
  • Hmm it worked for me on Mojave
    – gadelat
    Commented Sep 8, 2019 at 11:56
  • I will also add that my normal account does NOT have admin access. As a security precaution, I have a separate account with admin privileges, and I just enter that admin password when needed. I haven't tried it, but it's possible that it might work if I added admin privileges to my main account.
    – m0j0
    Commented Sep 11, 2019 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .