/* * swrun_procinfo.c: * hrSWRunTable data access: * getprocs() interface - AIX */ #include #include #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #include #include #include #include #include #include #include "swrun_private.h" int avail = 1024; /* Size of table to allocate */ /* --------------------------------------------------------------------- */ void netsnmp_arch_swrun_init(void) { /* Nothing to do */ return; } /* --------------------------------------------------------------------- */ int netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags) { struct procsinfo *proc_table; pid_t proc_index = 0; int nprocs, i; char pentry[128], *ppentry, fullpath[128]; netsnmp_swrun_entry *entry; /* * Create a buffer for the process table, based on the size of * the table the last time we loaded this information. * If this isn't big enough, keep increasing the size of the * table until we can retrieve the whole thing. */ proc_table = (struct procsinfo *) malloc(avail*(sizeof(struct procsinfo))); while ( avail == (nprocs = getprocs(proc_table, sizeof(struct procsinfo), 0, sizeof(struct fdsinfo), &proc_index, avail))) { avail += 1024; free( proc_table ); proc_table = (struct procsinfo *) malloc(avail*(sizeof(struct procsinfo))); } for ( i=0 ; ihrSWRunPath_len = snprintf(entry->hrSWRunPath, sizeof(entry->hrSWRunPath), "%s", fullpath); ppentry = strrchr(fullpath, '/'); if(ppentry == NULL) { entry->hrSWRunName_len = snprintf(entry->hrSWRunName, sizeof(entry->hrSWRunName), "%s", fullpath); } else { entry->hrSWRunName_len = snprintf(entry->hrSWRunName, sizeof(entry->hrSWRunName), "%s", ppentry + 1); } ppentry = strchr(pentry, ' '); entry->hrSWRunParameters_len = snprintf(entry->hrSWRunParameters, sizeof(entry->hrSWRunParameters), "%.*s", (int)(pentry - ppentry), ppentry + 1); } entry->hrSWRunType = (SKPROC & proc_table[i].pi_flags) ? 2 /* kernel process */ : 4 /* application */ ; switch (proc_table[i].pi_state) { case SACTIVE: case SRUN: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNING; break; case SSLEEP: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNABLE; break; case SSTOP: entry->hrSWRunStatus = HRSWRUNSTATUS_NOTRUNNABLE; break; case SIDL: case SZOMB: default: entry->hrSWRunStatus = HRSWRUNSTATUS_INVALID; break; } entry->hrSWRunPerfCPU = (proc_table[i].pi_ru.ru_utime.tv_sec * 100); entry->hrSWRunPerfCPU += (proc_table[i].pi_ru.ru_utime.tv_usec / 10000000); entry->hrSWRunPerfCPU += (proc_table[i].pi_ru.ru_stime.tv_sec * 100); entry->hrSWRunPerfCPU += (proc_table[i].pi_ru.ru_stime.tv_usec / 10000000); entry->hrSWRunPerfMem = proc_table[i].pi_size; entry->hrSWRunPerfMem *= (getpagesize()/1024); /* in kB */ } free(proc_table); DEBUGMSGTL(("swrun:load:arch"," loaded %d entries\n", (int) CONTAINER_SIZE(container))); return 0; }