Last active
August 21, 2019 01:52
-
-
Save trptcolin/e579bc7ca17cbfb1df40 to your computer and use it in GitHub Desktop.
A DTrace script to print the average, min, and max run queue count by CPU
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
#!/usr/sbin/dtrace -s | |
/* | |
* runq.d - run queue sizes by CPU. | |
* | |
* This prints the average, min, and max run queue count by CPU each second. A | |
* consistently large run queue count is a sign of CPU saturation. | |
* | |
* USAGE: runq.d | |
* | |
* FIELDS: | |
* CPU cpu ID | |
* avg-rq average run queue count over the last 1 second (sorry, no floats in D) | |
* min-rq minimum run queue count over the last 1 second | |
* max-rq maximum run queue count over the last 1 second | |
* %idle percent of the time the CPU state was idle | |
* | |
* 03-Nov-2015 Colin Jones | |
*/ | |
#pragma D option quiet | |
profile-1000hz | |
/curthread->last_processor->state == 4/ /* idle */ | |
{ | |
@idle[cpu] = count(); | |
} | |
profile-1000hz | |
{ | |
this->runq_count = curthread->last_processor->processor_set->pset_runq.count; | |
@min_rq[cpu] = min(this->runq_count); | |
@max_rq[cpu] = max(this->runq_count); | |
@avg_rq[cpu] = avg(this->runq_count); | |
} | |
profile:::tick-1sec | |
{ | |
/* turn it into a percentage: we take 1000 samples/second, so dividing the idle sample count by 10 makes sense */ | |
normalize(@idle, 10); | |
printf("\n%8s %8s %8s %8s %8s\n", "CPU", "avg-rq", "min-rq", "max-rq", "%idle"); | |
printa("%8d %@8d %@8d %@8d %@8d\n", @avg_rq, @min_rq, @max_rq, @idle); | |
clear(@idle); | |
clear(@min_rq); | |
clear(@max_rq); | |
clear(@avg_rq); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment