Added implementation of that feature.
1998-07-17 Martin Baulig <baulig@Stud.Informatik.uni-trier.de> * sysdeps/sun4/proclist.c (glibtop_get_proclist_p): Added implementation of that feature. * sysdeps/sun4/proc_{uid,state}.c: Now working quite well. * sysdeps/sun4/proc_{mem,time,signal,kernel,segment}.c: Added some basic implementation; this isn't really working yet.
This commit is contained in:
committed by
Martin Baulig
parent
74ca45f795
commit
c41d6e5a77
@@ -1,5 +1,13 @@
|
||||
1998-07-17 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* sysdeps/sun4/proclist.c (glibtop_get_proclist_p): Added
|
||||
implementation of that feature.
|
||||
|
||||
* sysdeps/sun4/proc_{uid,state}.c: Now working quite well.
|
||||
|
||||
* sysdeps/sun4/proc_{mem,time,signal,kernel,segment}.c: Added
|
||||
some basic implementation; this isn't really working yet.
|
||||
|
||||
* sysdeps/linux/sem_limits.c: Applied patch from Albert K T Hui
|
||||
<avatar@deva.net> for glibc 2.1.
|
||||
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include <glibtop/sysdeps.h>
|
||||
|
||||
#ifndef PROFILE_COUNT
|
||||
#define PROFILE_COUNT 1000
|
||||
#define PROFILE_COUNT 1
|
||||
#endif
|
||||
|
||||
int
|
||||
|
@@ -85,6 +85,10 @@ struct _glibtop_machine
|
||||
gid_t gid, egid; /* Real and effective group id */
|
||||
int nlist_count; /* Number of symbols in the nlist */
|
||||
int ncpu; /* Number of CPUs we have */
|
||||
int nproc; /* Number of entries in the process array */
|
||||
size_t ptable_size; /* Size of process array. */
|
||||
unsigned long ptable_offset; /* Offset of process array in kernel. */
|
||||
struct proc *proc_table; /* Process array. */
|
||||
unsigned long pages, epages;
|
||||
struct page *physpage;
|
||||
int bytesize, count;
|
||||
@@ -102,6 +106,10 @@ extern int _glibtop_check_nlist __P((void *, register struct nlist *));
|
||||
|
||||
extern int _glibtop_getkval __P((void *, unsigned long, int *, int, char *));
|
||||
|
||||
extern void _glibtop_read_proc_table __P((void *));
|
||||
|
||||
extern struct proc *_glibtop_find_pid __P((void *, pid_t));
|
||||
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
@@ -118,6 +118,24 @@ glibtop_open_r (glibtop *server, const char *program_name,
|
||||
(_glibtop_check_nlist (server, _glibtop_nlist) > 0))
|
||||
_exit (1);
|
||||
|
||||
/* Get process array stuff. */
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_NPROC].n_value,
|
||||
(int *)(&server->machine.nproc),
|
||||
sizeof (server->machine.nproc),
|
||||
_glibtop_nlist[X_NPROC].n_name);
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_PROC].n_value,
|
||||
(int *)(&server->machine.ptable_offset),
|
||||
sizeof (server->machine.ptable_offset),
|
||||
_glibtop_nlist[X_PROC].n_name);
|
||||
|
||||
server->machine.ptable_size = (unsigned long) server->machine.nproc *
|
||||
(unsigned long) sizeof (struct proc);
|
||||
|
||||
server->machine.proc_table = glibtop_malloc_r
|
||||
(server, server->machine.ptable_size);
|
||||
|
||||
/* This are for the memory statistics. */
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_PAGES].n_value,
|
||||
@@ -221,3 +239,46 @@ _glibtop_getkval (void *void_server, unsigned long offset, int *ptr, int size, c
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Used internally. Reads process table from kernel. */
|
||||
|
||||
void
|
||||
_glibtop_read_proc_table (void *void_server)
|
||||
{
|
||||
glibtop *server = (glibtop *) void_server;
|
||||
|
||||
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
(void) _glibtop_getkval (server, server->machine.ptable_offset,
|
||||
(int *) server->machine.proc_table,
|
||||
(size_t) server->machine.ptable_size,
|
||||
_glibtop_nlist[X_PROC].n_name);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SGID KMEM PART !!! */
|
||||
}
|
||||
|
||||
/* Used internally. Finds pid in process table. */
|
||||
|
||||
struct proc *
|
||||
_glibtop_find_pid (void *void_server, pid_t pid)
|
||||
{
|
||||
register struct proc *pp;
|
||||
register int i;
|
||||
|
||||
glibtop *server = (glibtop *) void_server;
|
||||
|
||||
for (pp = server->machine.proc_table, i = 0;
|
||||
i < server->machine.nproc; pp++, i++) {
|
||||
if ((pp->p_stat != 0) && (pp->p_pid == pid))
|
||||
return pp;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -19,16 +19,38 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/prockernel.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1 << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->k_flags = pp->p_flag;
|
||||
buf->wchan = pp->p_wchan;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
}
|
||||
|
@@ -19,10 +19,13 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#define GLIBTOP_PROCLIST_FLAGS 3
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
|
||||
(1 << GLIBTOP_PROCLIST_SIZE);
|
||||
|
||||
/* Fetch list of currently running processes.
|
||||
*
|
||||
@@ -34,8 +37,56 @@
|
||||
unsigned *
|
||||
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf)
|
||||
{
|
||||
register struct proc *pp;
|
||||
register int i, nproc = 0;
|
||||
unsigned *proc_list = NULL;
|
||||
size_t proc_size;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Count number of processes. */
|
||||
|
||||
for (pp = server->machine.proc_table, i = 0;
|
||||
i < server->machine.nproc; pp++, i++) {
|
||||
if (pp->p_stat == 0)
|
||||
continue;
|
||||
else
|
||||
nproc++;
|
||||
}
|
||||
|
||||
if (nproc == 0) /* Should never happen. */
|
||||
return NULL;
|
||||
|
||||
/* Allocate space for process list. */
|
||||
|
||||
proc_size = nproc * sizeof (unsigned);
|
||||
|
||||
proc_list = glibtop_malloc_r (server, proc_size);
|
||||
|
||||
/* Write process list. */
|
||||
|
||||
for (pp = server->machine.proc_table, i = 0, nproc = 0;
|
||||
i < server->machine.nproc; pp++, i++) {
|
||||
if (pp->p_stat == 0)
|
||||
continue;
|
||||
proc_list [nproc++] = pp->p_pid;
|
||||
}
|
||||
|
||||
/* Since everything is ok now, we can set buf->flags, fill in the remaining fields
|
||||
and return proc_list. */
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->number = nproc;
|
||||
|
||||
buf->total = nproc * sizeof (unsigned);
|
||||
|
||||
return proc_list;
|
||||
}
|
||||
|
@@ -22,13 +22,38 @@
|
||||
#include <config.h>
|
||||
#include <glibtop/procmem.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1 << GLIBTOP_PROC_MEM_SIZE) + (1 << GLIBTOP_PROC_MEM_RSS) +
|
||||
(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->size = (pp)->p_tsize + (pp)->p_dsize + (pp)->p_ssize;
|
||||
|
||||
buf->rss = pp->p_rssize;
|
||||
buf->rss_rlim = pp->p_maxrss;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
}
|
||||
|
@@ -19,16 +19,38 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/procsegment.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment =
|
||||
(1 << GLIBTOP_PROC_SEGMENT_TRS) + (1 << GLIBTOP_PROC_SEGMENT_DRS);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->trs = pp->p_tsize;
|
||||
buf->drs = pp->p_dsize;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
}
|
||||
|
@@ -19,16 +19,41 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/procsignal.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->signal = pp->p_sig;
|
||||
buf->blocked = pp->p_sigmask;
|
||||
buf->sigignore = pp->p_sigignore;
|
||||
buf->sigcatch = pp->p_sigcatch;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
}
|
||||
|
@@ -19,16 +19,38 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/procstate.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
(1 << GLIBTOP_PROC_STATE_STATE) + (1 << GLIBTOP_PROC_STATE_UID);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->state = pp->p_stat;
|
||||
buf->uid = pp->p_uid;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
}
|
||||
|
@@ -19,16 +19,38 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/proctime.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1 << GLIBTOP_PROC_TIME_START_TIME) + (1 << GLIBTOP_PROC_TIME_UTIME);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->start_time = pp->p_time;
|
||||
buf->utime = pp->p_cpticks;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
}
|
||||
|
@@ -19,16 +19,49 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/procuid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1 << GLIBTOP_PROC_UID_UID) + (1 << GLIBTOP_PROC_UID_EUID) +
|
||||
(1 << GLIBTOP_PROC_UID_EGID) + (1 << GLIBTOP_PROC_UID_PID) +
|
||||
(1 << GLIBTOP_PROC_UID_PPID) + (1 << GLIBTOP_PROC_UID_PGRP) +
|
||||
(1 << GLIBTOP_PROC_UID_TPGID) + (1 << GLIBTOP_PROC_UID_PRIORITY) +
|
||||
(1 << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct proc *pp;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
_glibtop_read_proc_table (server);
|
||||
|
||||
/* Find the pid in the process table. */
|
||||
|
||||
pp = _glibtop_find_pid (server, pid);
|
||||
|
||||
if (pp == NULL) return;
|
||||
|
||||
/* Fill in data fields. */
|
||||
|
||||
buf->uid = pp->p_uid;
|
||||
buf->euid = pp->p_suid;
|
||||
buf->egid = pp->p_sgid;
|
||||
buf->pid = pp->p_pid;
|
||||
buf->ppid = pp->p_ppid;
|
||||
buf->pgrp = pp->p_pgrp;
|
||||
buf->tpgid = pp->p_pgrp;
|
||||
buf->priority = pp->p_pri;
|
||||
buf->nice = pp->p_nice;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
}
|
||||
|
@@ -41,9 +41,9 @@ glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
||||
|
||||
/* Make sure all required fields are present. */
|
||||
|
||||
if (((cpu.flags & GLIBTOP_CPU_TOTAL) == 0) ||
|
||||
((cpu.flags & GLIBTOP_CPU_IDLE) == 0) ||
|
||||
((cpu.flags & GLIBTOP_CPU_FREQUENCY) == 0) ||
|
||||
if (((cpu.flags & (1 << GLIBTOP_CPU_TOTAL)) == 0) ||
|
||||
((cpu.flags & (1 << GLIBTOP_CPU_IDLE)) == 0) ||
|
||||
((cpu.flags & (1 << GLIBTOP_CPU_FREQUENCY)) == 0) ||
|
||||
(cpu.frequency == 0))
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user