summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-25 02:51:16 -0400
committerIan Moffett <ian@osmora.org>2025-07-25 02:54:17 -0400
commiteba141e6dcef379f3be50e3e2a5a1e4bfad9131a (patch)
tree5368e55f06df30ad7823f2904286d47a0eaa5b12 /usr.bin
parent2adbd223b794ec8dbfb90def60cc2a13cb8dfe42 (diff)
usr: kstat: Add CPU percent online reporting
Reports the CPU online percentage given how many cores are online and how many cores are offline. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/kstat/kstat.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/usr.bin/kstat/kstat.c b/usr.bin/kstat/kstat.c
index 853bc8b..e3b7e6a 100644
--- a/usr.bin/kstat/kstat.c
+++ b/usr.bin/kstat/kstat.c
@@ -37,6 +37,8 @@ get_sched_stat(void)
{
struct sched_stat stat;
struct sched_cpu *cpu;
+ double nonline, noffline;
+ uint16_t online_percent;
int fd;
fd = open("/ctl/sched/stat", O_RDONLY);
@@ -50,10 +52,15 @@ get_sched_stat(void)
}
close(fd);
+ noffline = stat.nhlt;
+ nonline = (stat.ncpu - noffline);
+ online_percent = (uint16_t)(((double)nonline / (nonline + noffline)) * 100);
+
printf("-------------------------------\n");
printf("Number of tasks: %d\n", stat.nproc);
printf("Number of cores online: %d\n", stat.ncpu);
printf("Scheduler quantum: %d usec\n", stat.quantum_usec);
+ printf("CPU is %d%% online\n", online_percent);
printf("-------------------------------\n");
/*