| 1 |
/* |
| 2 |
* swrun_nlist.c: |
| 3 |
* hrSWRunTable data access: |
| 4 |
* nlist() interface |
| 5 |
*/ |
| 6 |
#include <net-snmp/net-snmp-config.h> |
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#ifdef HAVE_STDLIB_H |
| 10 |
#include <stdlib.h> |
| 11 |
#endif |
| 12 |
#ifdef HAVE_UNISTD_H |
| 13 |
#include <unistd.h> |
| 14 |
#endif |
| 15 |
#ifdef HAVE_SYS_TYPES_H |
| 16 |
#include <sys/types.h> |
| 17 |
#endif |
| 18 |
|
| 19 |
#include <net-snmp/agent/auto_nlist.h> |
| 20 |
|
| 21 |
#include <net-snmp/net-snmp-includes.h> |
| 22 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 23 |
#include <net-snmp/library/container.h> |
| 24 |
#include <net-snmp/library/snmp_debug.h> |
| 25 |
#include <net-snmp/data_access/swrun.h> |
| 26 |
#include "swrun_private.h" |
| 27 |
|
| 28 |
/* --------------------------------------------------------------------- |
| 29 |
*/ |
| 30 |
void |
| 31 |
netsnmp_arch_swrun_init(void) |
| 32 |
{ |
| 33 |
extern int _swrun_max; |
| 34 |
|
| 35 |
auto_nlist( PROC_SYMBOL, 0, 0); |
| 36 |
auto_nlist( NPROC_SYMBOL, (char *)&_swrun_max, sizeof(int)); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
/* --------------------------------------------------------------------- |
| 41 |
*/ |
| 42 |
int |
| 43 |
netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags) |
| 44 |
{ |
| 45 |
struct proc *proc_table; |
| 46 |
int proc_type_base; |
| 47 |
int nproc, i, rc; |
| 48 |
netsnmp_swrun_entry *entry; |
| 49 |
|
| 50 |
auto_nlist( NPROC_SYMBOL, (char *)&nproc, sizeof(int)); |
| 51 |
proc_table = (struct proc *) malloc(nproc*(sizeof(struct proc))); |
| 52 |
|
| 53 |
auto_nlist( PROC_SYMBOL, (char *)&proc_table_base, sizeof(int)); |
| 54 |
NETSNMP_KLOOKUP(proc_table_base, (char *)proc_table, |
| 55 |
nproc*(sizeof(struct proc))); |
| 56 |
|
| 57 |
for ( i=0 ; i<nproc; i++ ) { |
| 58 |
if (0 == proc_table[i].p_stat) |
| 59 |
continue; /* Skip unused entries */ |
| 60 |
entry = netsnmp_swrun_entry_create(proc_table[i].p_pid); |
| 61 |
if (NULL == entry) |
| 62 |
continue; /* error already logged by function */ |
| 63 |
rc = CONTAINER_INSERT(container, entry); |
| 64 |
|
| 65 |
/* |
| 66 |
* XXX - What information does 'struct proc' contain? |
| 67 |
*/ |
| 68 |
|
| 69 |
/* |
| 70 |
Apparently no process name/argument information |
| 71 |
entry->hrSWRunName_len = snprintf(entry->hrSWRunName, |
| 72 |
sizeof(entry->hrSWRunName)-1, |
| 73 |
"%s", proc_table[i].???); |
| 74 |
entry->hrSWRunPath_len = snprintf(entry->hrSWRunPath, |
| 75 |
sizeof(entry->hrSWRunPath)-1, |
| 76 |
"%s", proc_table[i].???); |
| 77 |
entry->hrSWRunParameters_len = snprintf(entry->hrSWRunParameters, |
| 78 |
sizeof(entry->hrSWRunParameters)-1, |
| 79 |
"%s", ???); |
| 80 |
*/ |
| 81 |
|
| 82 |
switch (proc_table[i].p_stat) { |
| 83 |
/* XXX - which names to use ?? */ |
| 84 |
case SACTIVE: |
| 85 |
case SRUN: |
| 86 |
case SONPROC: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNING; |
| 87 |
break; |
| 88 |
case SSWAP: |
| 89 |
case SSLEEP: |
| 90 |
case SWAIT: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNABLE; |
| 91 |
break; |
| 92 |
case SSTOP: entry->hrSWRunStatus = HRSWRUNSTATUS_NOTRUNNABLE; |
| 93 |
break; |
| 94 |
case SIDL: |
| 95 |
case SZOMB: |
| 96 |
default: entry->hrSWRunStatus = HRSWRUNSTATUS_INVALID; |
| 97 |
break; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
entry->hrSWRunPerfCPU = (proc_table[i].p_utime.tv_sec * 100); |
| 102 |
entry->hrSWRunPerfCPU += (proc_table[i].p_utime.tv_usec / 10000); |
| 103 |
entry->hrSWRunPerfCPU += (proc_table[i].p_stime.tv_sec * 100); |
| 104 |
entry->hrSWRunPerfCPU += (proc_table[i].p_stime.tv_usec / 10000); |
| 105 |
/* |
| 106 |
or entry->hrSWRunPerfCPU = proc_table[i].p_time; |
| 107 |
*/ |
| 108 |
} |
| 109 |
free(proc_table); |
| 110 |
|
| 111 |
DEBUGMSGTL(("swrun:load:arch"," loaded %d entries\n", |
| 112 |
CONTAINER_SIZE(container))); |
| 113 |
|
| 114 |
return 0; |
| 115 |
} |