add proc_state.threads metric

This commit is contained in:
Doug MacEachern 2005-11-22 21:45:45 +00:00
parent 5ae081f7a9
commit fb61a2ebb0
5 changed files with 34 additions and 1 deletions

View File

@ -348,6 +348,11 @@ my %classes = (
desc => 'Kernel scheduling priority of process',
plat => 'DFHLSW'
},
{
name => 'threads', type => 'Long',
desc => 'Number of active threads',
plat => ''
},
],
ProcFd => [
{

View File

@ -21,7 +21,8 @@ public class TestProcState extends SigarTestCase {
ProcState procState = sigar.getProcState(sigar.getPid());
char state = procState.getState();
traceln(procState.getName() + "=" + state);
traceln("threads=" + procState.getThreads());
assertTrue((state == 'R') || (state == 'S'));
assertTrue(procState.getName().indexOf("java") != -1);

View File

@ -255,6 +255,7 @@ typedef struct {
int tty;
int priority;
int nice;
int threads;
} sigar_proc_state_t;
SIGAR_DECLARE(int) sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,

View File

@ -696,6 +696,29 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
return SIGAR_OK;
}
static int proc_status_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_state_t *procstate)
{
char buffer[BUFSIZ], *ptr;
int status = SIGAR_PROC_FILE2STR(buffer, pid, PROC_PSTATUS);
if (status != SIGAR_OK) {
return status;
}
ptr = strstr(buffer, "\nThreads:");
if (ptr) {
/* 2.6+ kernel only */
ptr = sigar_skip_token(ptr);
procstate->threads = sigar_strtoul(ptr);
}
else {
procstate->threads = SIGAR_FIELD_NOTIMPL;
}
return SIGAR_OK;
}
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_state_t *procstate)
{
@ -714,6 +737,8 @@ int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
procstate->priority = pstat->priority;
procstate->nice = pstat->nice;
proc_status_get(sigar, pid, procstate);
return SIGAR_OK;
}

View File

@ -660,6 +660,7 @@ int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
procstate->tty = pinfo->pr_ttydev;
procstate->priority = pinfo->pr_lwp.pr_pri;
procstate->nice = pinfo->pr_lwp.pr_nice - NZERO;
procstate->threads = pinfo->pr_nlwp;
switch (pinfo->pr_lwp.pr_state) {
case SONPROC: