-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
siimilar tool for intel macs? #70
Comments
@akohlsmith There's: You can also try If you don't mind being a bit imprecise though, one workable solution (which thankfully also doesn't need sudo/root access) is looking at the output from
Here's how I'm doing it in bash at the moment (on macOS, but should probably* work on most linux/unix OS's too): # in just one line:
top -l 2 -stats "cpu,power" | awk -v N=2 '/%CPU[[:blank:]]*POWER/{++n} n>=N && $0 !~ /0.0[[:space:]]*$/' | tail -n +2 | awk '{cpu_total += $1}; {power_total += $2} END {print power_total - cpu_total "%"}'
# Explanation:
# 1. so we start by listing the CPU and Power usage for each running process
top -l 2 -stats "cpu,power"
# here, `-l 2` means take two samples and print both the results
# the only keys we need to pass in to `-stats` to get an approximate GPU busy percentage are cpu and power
# but we can also pass in other keys like: command and pid
# which would show the process name and id respectively
# (use `man top` to learn more about other keys you can pass in)
# for debugging purposes, just to make sure things looked correct, I started with:
top -l 2 -stats "pid,cpu,power,command"
# 2. we pipe that into awk and look for the 2nd occurrence of "%CPU POWER"
## which we expect from top's output, since we're printing two samples
# `-v N=2` passes in a hard-coded variable that we can use in our awk program
## to grab all the lines *after* the 2nd occurrence of the relevant header string
# the `[[:blank:]]` means match whitespace, and `*` means any number of them in a row
## since the output from top could contain more than one whitespace char between the headers
# everything between the /'s is a regex, and then we increment n with each line that we process
## and check if the current line is greater than or equal to our Nth match (second match)
## this will include only the matching line and all lines after it, so we ignore the first sample
## because the first sample is (almost) always all 0.0's for every value, both cpu and power
# next, we use `&&` to run a second filter, which removes any lines where Power has a value of 0.0
## `$0` is the whole line, and `!~` means don't include what matches the following regex
## `[[:space:]]` is similar to `[[:blank:]]` but it includes newline characters as well.
## `*` is any number of them just to be safe
## and `$` checks that the match is at the end of the line, where we expect the power value to be
awk -v N=2 '/%CPU[[:blank:]]*POWER/{++n} n>=N && $0 !~ /0.0[[:space:]]*$/'
# 3. after that, it's handy to remove the Header line...
## we could have done this in awk in the previous step
## but it makes things a bit more complicated imo, so let's pipe the output from step 2, above, into:
tail -n +2
# which removes the header AND a preceding blank line
# whereas if we just use `-n +1` we only remove the preceding blank line and not the header
# 4. now let's pipe that into awk one more time to do some simple math
## add up the values from column $1 into cpu_total
## add up the values from column $2 into power_total
## then subtract the cpu from the power, and print it with a percent on the end as well
awk '{cpu_total += $1}; {power_total += $2} END {print power_total - cpu_total "%"}'
# 5. you should see output similar to:
11.5%
# although it could be any number from 0% to 100%, assuming top is working correctly, and assuming we're filtering the list and calculating the totals all correctly. and obviously, instead of adding up the values from each column, you could modify this to just calculate the GPU busy percentage for a specific process, or for each process individually, if you wanted. I notice when comparing the output to what I see from Activity Monitor (press Cmd + 4 to bring up the GPU History) the values seem roughly correlated, but this method doesn't tend to show you spikes and dips in performance as much as you'd see from the GPU History view in activity monitor, unless you were running this command more frequently, but I would recommend keeping it somewhere around every 1-5 seconds at the smallest. I have this feeding into my tmux, but you could display this output however you like really ^.^ good luck |
I understand that asitop is for apple silicon only. I'm curious if there is a similar tool for intel macs. I've not yet been able to find the magic search terms (if the exist)
The text was updated successfully, but these errors were encountered: