Skip to content

Instantly share code, notes, and snippets.

@kinichiro
Created August 13, 2014 08:04
Show Gist options
  • Save kinichiro/e7f2ac1cc07169cc1ab6 to your computer and use it in GitHub Desktop.
Save kinichiro/e7f2ac1cc07169cc1ab6 to your computer and use it in GitHub Desktop.
sample code for pstat_getdynamic()
/* test_pstat_getdynamic.c */
#include <stdio.h>
#include <sys/pstat.h>
int main() {
struct pst_dynamic buf;
if(pstat_getdynamic(&buf, sizeof(buf), 1, 0) != 1) {
perror("pstat_getdynamic()");
return -1;
}
printf("++++++++++----------++++++++++----------++++++++++----------\n");
printf("last run process ID = %d\n", buf.psd_last_pid);
printf("run queue length = %d\n", buf.psd_rq);
printf("jobs in disk wait = %d\n", buf.psd_dw);
printf("jobs in page wait = %d\n", buf.psd_pw);
printf("jobs sleeping in core = %d\n", buf.psd_sl);
printf("swapped out runnable jobs = %d\n", buf.psd_sw);
printf("total virtual memory = %d\n", buf.psd_vm);
printf("active virtual memory = %d\n", buf.psd_avm);
printf("virt mem text = %d\n", buf.psd_vmtxt);
printf("active virt mem text = %d\n", buf.psd_avmtxt);
printf("free memory pages = %d\n", buf.psd_free);
printf("global cpu time/state =\n");
int i, j;
for(i = 0; i < buf.psd_proc_cnt; ++ i) {
printf("%2d:", i);
for(j = 0; j < PST_MAX_CPUSTATES; ++ j) {
printf(" %d/", buf.psd_mp_cpu_time[i][j]);
}
printf("\n");
}
printf("global run queue lengths 1/5/15 min. = %lf/ %lf/ %lf/\n",
buf.psd_avg_1_min, buf.psd_avg_5_min, buf.psd_avg_15_min);
printf("# of active proc table entries = %d\n", buf.psd_activeprocs);
printf("# of active inode table entries = %d\n", buf.psd_activeinodes);
printf("# of active file table entries = %d\n", buf.psd_activefiles);
printf("Number of process structures currently allocated = %d\n", buf.psd_numprocsallocd);
printf("Number of thread structures currently allocated = %d\n", buf.psd_numkthreadsallocd);
printf("# of active threads on system = %d\n", buf.psd_activethreads);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment