more goodies

This commit is contained in:
albert
2003-10-16 03:30:41 +00:00
parent 3a16c12ce3
commit e180e4875f
5 changed files with 136 additions and 20 deletions

View File

@@ -1,8 +1,8 @@
_3_1_12 {
_3_1_14 {
global:
__cyg_profile_func_enter; __cyg_profile_func_exit; main;
readproc; readtask; readproctab; look_up_our_self; escape_command;
readproc; readtask; readproctab; readproctab2; look_up_our_self; escape_command;
escape_str; escape_strlist;
openproc; closeproc;
tty_to_dev; dev_to_tty; open_psdb_message; open_psdb; wchan;

View File

@@ -216,6 +216,9 @@ ENTER(0x220);
case_Pid:
P->tid = strtol(S,&S,10);
continue;
case_Threads:
P->nlwp = strtol(S,&S,10);
continue;
case_ShdPnd:
memcpy(ShdPnd, S, 16);
@@ -311,7 +314,9 @@ ENTER(0x160);
"%d %d %d %d %d "
"%lu %lu %lu %lu %lu "
"%Lu %Lu %Lu %Lu " /* utime stime cutime cstime */
"%ld %ld %ld %ld "
"%ld %ld "
"%d "
"%ld "
"%Lu " /* start_time */
"%lu "
"%ld "
@@ -324,7 +329,9 @@ ENTER(0x160);
&P->ppid, &P->pgrp, &P->session, &P->tty, &P->tpgid,
&P->flags, &P->min_flt, &P->cmin_flt, &P->maj_flt, &P->cmaj_flt,
&P->utime, &P->stime, &P->cutime, &P->cstime,
&P->priority, &P->nice, &P->timeout, &P->it_real_value,
&P->priority, &P->nice,
&P->nlwp,
&P->it_real_value,
&P->start_time,
&P->vsize,
&P->rss,
@@ -933,6 +940,7 @@ void look_up_our_self(proc_t *p) {
}
HIDDEN_ALIAS(readproc);
HIDDEN_ALIAS(readtask);
/* Convenient wrapper around openproc and readproc to slurp in the whole process
* table subset satisfying the constraints of flags and the optional PID list.
@@ -969,3 +977,96 @@ proc_t** readproctab(int flags, ...) {
closeproc(PT);
return tab;
}
// Try again, this time with threads and selection.
proc_data_t *readproctab2(int(*want_proc)(proc_t *buf), int(*want_task)(proc_t *buf), int flags, ...) {
PROCTAB* PT = NULL;
proc_t** ptab = NULL;
proc_t** ttab = NULL;
proc_t* data = NULL;
unsigned n_alloc = 0;
unsigned n_used = 0;
unsigned n_proc_alloc = 0;
unsigned n_proc = 0;
unsigned n_task = 0;
unsigned n_task_alloc = 0;
va_list ap;
proc_data_t *pd;
va_start(ap, flags);
if (flags & PROC_UID) {
// temporary variables ensure that va_arg() instances
// are called in the right order
uid_t* u;
int i;
u = va_arg(ap, uid_t*);
i = va_arg(ap, int);
PT = openproc(flags, u, i);
}
else if (flags & PROC_PID)
PT = openproc(flags, va_arg(ap, void*));
else
PT = openproc(flags);
va_end(ap);
for(;;){
proc_t *tmp;
if(n_alloc == n_used){
//proc_t *old = data;
n_alloc = n_alloc*5/4+30; // grow by over 25%
data = realloc(data,sizeof(proc_t)*n_alloc);
//if(!data) return NULL;
}
if(n_proc_alloc == n_proc){
//proc_t **old = ptab;
n_proc_alloc = n_proc_alloc*5/4+30; // grow by over 25%
ptab = realloc(ptab,sizeof(proc_t*)*n_proc_alloc);
//if(!ptab) return NULL;
}
tmp = readproc_direct(PT, data+n_used);
if(!tmp) break;
if(!want_proc(tmp)) continue;
ptab[n_proc++] = tmp;
n_used++;
if(!( PT->flags & PROC_LOOSE_TASKS )) continue;
for(;;){
proc_t *t;
if(n_alloc == n_used){
//proc_t *old = data;
n_alloc = n_alloc*5/4+30; // grow by over 25%
data = realloc(data,sizeof(proc_t)*n_alloc);
//if(!data) return NULL;
}
if(n_task_alloc == n_task){
//proc_t **old = ttab;
n_task_alloc = n_task_alloc*5/4+1; // grow by over 25%
ttab = realloc(ttab,sizeof(proc_t*)*n_task_alloc);
//if(!ttab) return NULL;
}
t = readtask_direct(PT, tmp, data+n_used);
if(!t) break;
if(!want_task(t)) continue;
ttab[n_task++] = t;
n_used++;
}
}
closeproc(PT);
pd = malloc(sizeof(proc_data_t));
pd->proc = ptab;
pd->task = ttab;
pd->nproc = n_proc;
pd->ntask = n_task;
if(flags & PROC_LOOSE_TASKS){
pd->tab = ttab;
pd->n = n_task;
}else{
pd->tab = ptab;
pd->n = n_proc;
}
return pd;
}

View File

@@ -71,7 +71,6 @@ typedef struct proc_t {
#endif
long
priority, // stat kernel scheduling priority
timeout, // stat ?
nice, // stat standard unix nice level of process
rss, // stat resident set size from /proc/#/stat (pages)
it_real_value, // stat ?
@@ -129,6 +128,7 @@ typedef struct proc_t {
int
pgrp, // stat process group id
session, // stat session id
nlwp, // stat,status number of threads, or 0 if no clue
tgid, // (special) task group ID, the POSIX PID (see also: tid)
tty, // stat full device number of controlling terminal
euid, egid, // stat(),status effective
@@ -172,6 +172,16 @@ typedef struct PROCTAB {
// initialize a PROCTAB structure holding needed call-to-call persistent data
extern PROCTAB* openproc(int flags, ... /* pid_t*|uid_t*|dev_t*|char* [, int n] */ );
typedef struct proc_data_t {
proc_t **tab;
proc_t **proc;
proc_t **task;
int n;
int nproc;
int ntask;
} proc_data_t;
extern proc_data_t *readproctab2(int(*want_proc)(proc_t *buf), int(*want_task)(proc_t *buf), int flags, ... /* same as openproc */ );
// Convenient wrapper around openproc and readproc to slurp in the whole process
// table subset satisfying the constraints of flags and the optional PID list.