Created
October 3, 2023 03:21
-
-
Save dylan-chong/1ade569ac0741da3fcd7c88b8046c6f2 to your computer and use it in GitHub Desktop.
Select all on the memory page of the Mac Activity Monitor and then run the script. It will add up how much all of the similar processes (e.g., add up to)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IO.puts "Reading activity monitor data from clipboard:" | |
{activity_monitor_data, 0} = System.cmd("pbpaste", []) | |
memory_grouped_by_name = | |
activity_monitor_data | |
|> String.split("\n") | |
|> Enum.filter(fn line -> | |
match? [_name, _size | _], String.split(line, "\t") | |
end) | |
|> Enum.map(fn line -> | |
IO.puts "Processing line: " <> inspect("#{line}") | |
[name, size | _] = line |> String.split("\t") | |
[size_num_str, size_unit] = size |> String.split(" ") | |
{size_num, _} = Float.parse(size_num_str) | |
modifier = | |
case size_unit do | |
"bytes" -> 1 / 1000 | |
"GB" -> 1 | |
"MB" -> 1000 | |
"KB" -> 1_000_000 | |
end | |
{name, size_num / modifier} | |
end) | |
|> Enum.group_by(fn {name, _} -> name end, fn {_, size} -> size end) | |
|> Enum.map(fn {name, sizes} -> {name, Enum.sum(sizes)} end) | |
|> Enum.sort_by(fn {_, total_size} -> total_size end) | |
total = | |
memory_grouped_by_name | |
|> Enum.map(fn {_, total_size} -> total_size end) | |
|> Enum.sum() | |
IO.inspect %{ | |
memory_grouped_by_name: memory_grouped_by_name, | |
total_gb: total | |
}, limit: :infinity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment