summaryrefslogtreecommitdiff
path: root/usr.bin/kstat/kstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/kstat/kstat.c')
-rw-r--r--usr.bin/kstat/kstat.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/usr.bin/kstat/kstat.c b/usr.bin/kstat/kstat.c
index e3b7e6a..cbbe602 100644
--- a/usr.bin/kstat/kstat.c
+++ b/usr.bin/kstat/kstat.c
@@ -28,10 +28,51 @@
*/
#include <sys/sched.h>
+#include <sys/vmstat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
+#define MIB_PER_GIB 1024
+
+static void
+print_size_mib(const char *name, size_t mib)
+{
+ if (name == NULL) {
+ return;
+ }
+
+ if (mib >= MIB_PER_GIB) {
+ printf("%s: %d GiB\n", name, mib / MIB_PER_GIB);
+ } else {
+ printf("%s: %d MiB\n", name, mib);
+ }
+}
+
+static void
+get_vm_stat(void)
+{
+ struct vm_stat vmstat;
+ int retval, fd;
+
+ fd = open("/ctl/vm/stat", O_RDONLY);
+ if (fd < 0) {
+ printf("failed to open '/ctl/vm/stat'\n");
+ return;
+ }
+
+ retval = read(fd, &vmstat, sizeof(vmstat));
+ if (retval <= 0) {
+ printf("failed to read vmstat\n");
+ return;
+ }
+
+ close(fd);
+ print_size_mib("memory available", vmstat.mem_avail);
+ print_size_mib("memory used", vmstat.mem_used);
+ print_size_mib("memory total", vmstat.mem_total);
+}
+
static void
get_sched_stat(void)
{
@@ -56,12 +97,10 @@ get_sched_stat(void)
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("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");
/*
* Log out some per-cpu information
@@ -75,6 +114,9 @@ get_sched_stat(void)
int
main(void)
{
+ printf("-- scheduler statistics --\n");
get_sched_stat();
+ printf("-- memory statistics --\n");
+ get_vm_stat();
return 0;
}