summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>1998-08-09 21:11:18 +0000
committerMartin Baulig <martin@src.gnome.org>1998-08-09 21:11:18 +0000
commit32c0ced22a97fa8e1625c14d8f0164450f6f112d (patch)
tree5b89b325ebfdf2856eff8ed786e9ff21545951cc
parentfd95ab60a4983c0a315a275bbfee995bcb5f2c25 (diff)
downloadlibgtop-32c0ced22a97fa8e1625c14d8f0164450f6f112d.tar.gz
Renamed `wchan' field to `nwchan'; added `wchan' which is of type `char
1998-08-09 Martin Baulig <martin@home-of-linux.org> * include/glibtop/prockernel.h (glibtop_proc_kernel): Renamed `wchan' field to `nwchan'; added `wchan' which is of type `char [40]'.
-rw-r--r--ChangeLog3
-rw-r--r--examples/first.c15
-rw-r--r--examples/second.c5
-rw-r--r--features.def4
-rw-r--r--include/glibtop/prockernel.h8
-rw-r--r--include/glibtop/proclist.h13
-rw-r--r--sysdeps/freebsd/prockernel.c97
-rw-r--r--sysdeps/freebsd/proclist.c5
-rw-r--r--sysdeps/freebsd/procsegment.c2
-rw-r--r--sysdeps/names/prockernel.c13
10 files changed, 110 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index 848dbbca..68c08962 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
1998-08-09 Martin Baulig <martin@home-of-linux.org>
+ * include/glibtop/prockernel.h (glibtop_proc_kernel): Renamed
+ `wchan' field to `nwchan'; added `wchan' which is of type `char [40]'.
+
* features.def: Changed format of this file to support multiple
arguments to be passed to a function.
diff --git a/examples/first.c b/examples/first.c
index abae9b3e..ebe2b4d4 100644
--- a/examples/first.c
+++ b/examples/first.c
@@ -275,7 +275,7 @@ main (int argc, char *argv [])
glibtop_get_proc_kernel (&data.proc_kernel, pid);
printf ("Proc_Kernel PID %5u (0x%08lx): "
- "%lu %lu %lu %lu %lu %lu %lu %lu\n", pid,
+ "%lu %lu %lu %lu %lu %lu %lu %lu (%s)\n", pid,
(unsigned long) data.proc_kernel.flags,
(unsigned long) data.proc_kernel.k_flags,
(unsigned long) data.proc_kernel.min_flt,
@@ -284,7 +284,8 @@ main (int argc, char *argv [])
(unsigned long) data.proc_kernel.cmaj_flt,
(unsigned long) data.proc_kernel.kstk_esp,
(unsigned long) data.proc_kernel.kstk_eip,
- (unsigned long) data.proc_kernel.wchan);
+ (unsigned long) data.proc_kernel.nwchan,
+ data.proc_kernel.wchan);
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_segment (&data.proc_segment, pid);
@@ -364,7 +365,7 @@ main (int argc, char *argv [])
glibtop_get_proc_kernel (&data.proc_kernel, ppid);
printf ("Proc_Kernel PPID %5u (0x%08lx): "
- "%lu %lu %lu %lu %lu %lu %lu %lu\n", ppid,
+ "%lu %lu %lu %lu %lu %lu %lu %lu (%s)\n", ppid,
(unsigned long) data.proc_kernel.flags,
(unsigned long) data.proc_kernel.k_flags,
(unsigned long) data.proc_kernel.min_flt,
@@ -373,7 +374,8 @@ main (int argc, char *argv [])
(unsigned long) data.proc_kernel.cmaj_flt,
(unsigned long) data.proc_kernel.kstk_esp,
(unsigned long) data.proc_kernel.kstk_eip,
- (unsigned long) data.proc_kernel.wchan);
+ (unsigned long) data.proc_kernel.nwchan,
+ data.proc_kernel.wchan);
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_segment (&data.proc_segment, ppid);
@@ -454,7 +456,7 @@ main (int argc, char *argv [])
glibtop_get_proc_kernel (&data.proc_kernel, 1);
printf ("Proc_Kernel INIT %5u (0x%08lx): "
- "%lu %lu %lu %lu %lu %lu %lu %lu\n", 1,
+ "%lu %lu %lu %lu %lu %lu %lu %lu (%s)\n", 1,
(unsigned long) data.proc_kernel.flags,
(unsigned long) data.proc_kernel.k_flags,
(unsigned long) data.proc_kernel.min_flt,
@@ -463,7 +465,8 @@ main (int argc, char *argv [])
(unsigned long) data.proc_kernel.cmaj_flt,
(unsigned long) data.proc_kernel.kstk_esp,
(unsigned long) data.proc_kernel.kstk_eip,
- (unsigned long) data.proc_kernel.wchan);
+ (unsigned long) data.proc_kernel.nwchan,
+ data.proc_kernel.wchan);
for (c = 0; c < PROFILE_COUNT; c++)
glibtop_get_proc_segment (&data.proc_segment, 1);
diff --git a/examples/second.c b/examples/second.c
index b63eb341..296e0584 100644
--- a/examples/second.c
+++ b/examples/second.c
@@ -141,7 +141,7 @@ main (int argc, char *argv [])
glibtop_get_proc_kernel (&data.proc_kernel, pid);
printf ("Proc_Kernel PID %5u (0x%08lx): "
- "%lu %lu %lu %lu %lu %lu %lu %lu\n", pid,
+ "%lu %lu %lu %lu %lu %lu %lu %lu (%s)\n", pid,
(unsigned long) data.proc_kernel.flags,
(unsigned long) data.proc_kernel.k_flags,
(unsigned long) data.proc_kernel.min_flt,
@@ -150,7 +150,8 @@ main (int argc, char *argv [])
(unsigned long) data.proc_kernel.cmaj_flt,
(unsigned long) data.proc_kernel.kstk_esp,
(unsigned long) data.proc_kernel.kstk_eip,
- (unsigned long) data.proc_kernel.wchan);
+ (unsigned long) data.proc_kernel.nwchan,
+ data.proc_kernel.wchan);
glibtop_get_proc_segment (&data.proc_segment, pid);
diff --git a/features.def b/features.def
index 265cdd01..20de6e05 100644
--- a/features.def
+++ b/features.def
@@ -6,13 +6,13 @@ void|loadavg|double(loadavg[0],loadavg[1],loadavg[2])
void|shm_limits|ulong(shmmax,shmmin,shmmni,shmseg,shmall)
void|msg_limits|ulong(msgpool,msgmap,msgmax,msgmnb,msgmni,msgssz,msgtql)
void|sem_limits|ulong(semmap,semmni,semmns,semmnu,semmsl,semopm,semume,semusz,semvmx,semaem)
-unsigned *|proclist|ulong(number,size,total)|long(method,param)
+unsigned *|proclist|ulong(number,size,total)|long(which,arg)
void|proc_state|str(cmd):char(state):ulong(uid,gid)|pid_t(pid)
void|proc_uid|long(uid,euid,gid,egid,pid,ppid,pgrp,session,tty,tpgid,priority,nice)|pid_t(pid)
void|proc_mem|long(size,vsize,resident,share,rss,rss_rlim)|pid_t(pid)
void|proc_time|long(start_time,utime,stime,cutime,cstime,timeout,it_real_value)|pid_t(pid)
void|proc_signal|ulong(signal,blocked,sigignore,sigcatch)|pid_t(pid)
-void|proc_kernel|ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,wchan)|pid_t(pid)
+void|proc_kernel|ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,nwchan):str(wchan)|pid_t(pid)
void|proc_segment|long(trs,lrs,drs,dt):ulong(start_code,end_code,start_stack)|pid_t(pid)
glibtop_mountentry *|@mountlist|ulong(number,size,total)|pid_t(all_fs)
void|@fsusage|ulong(blocks,bfree,bavail,files,ffree)|string|mount_dir
diff --git a/include/glibtop/prockernel.h b/include/glibtop/prockernel.h
index c589b2f0..f1139064 100644
--- a/include/glibtop/prockernel.h
+++ b/include/glibtop/prockernel.h
@@ -34,9 +34,10 @@ __BEGIN_DECLS
#define GLIBTOP_PROC_KERNEL_CMAJ_FLT 4
#define GLIBTOP_PROC_KERNEL_KSTK_ESP 5
#define GLIBTOP_PROC_KERNEL_KSTK_EIP 6
-#define GLIBTOP_PROC_KERNEL_WCHAN 7
+#define GLIBTOP_PROC_KERNEL_NWCHAN 7
+#define GLIBTOP_PROC_KERNEL_WCHAN 8
-#define GLIBTOP_MAX_PROC_KERNEL 8
+#define GLIBTOP_MAX_PROC_KERNEL 9
typedef struct _glibtop_proc_kernel glibtop_proc_kernel;
@@ -56,8 +57,9 @@ struct _glibtop_proc_kernel
* child processes */
kstk_esp, /* kernel stack pointer */
kstk_eip, /* kernel stack pointer */
- wchan; /* address of kernel wait channel
+ nwchan; /* address of kernel wait channel
* proc is sleeping in */
+ char wchan [40];
};
#define glibtop_get_proc_kernel(p1, p2) glibtop_get_proc_kernel_l(glibtop_global_server, p1, p2)
diff --git a/include/glibtop/proclist.h b/include/glibtop/proclist.h
index f18e0937..b64d445f 100644
--- a/include/glibtop/proclist.h
+++ b/include/glibtop/proclist.h
@@ -33,6 +33,17 @@ __BEGIN_DECLS
#define GLIBTOP_MAX_PROCLIST 3
+/* You can use the folowing constants as the `which' member of
+ * glibtop_get_proclist () to specify which processes to fetch. */
+
+#define GLIBTOP_KERN_PROC_ALL 0 /* all processes */
+#define GLIBTOP_KERN_PROC_PID 1
+#define GLIBTOP_KERN_PROC_PGRP 2
+#define GLIBTOP_KERN_PROC_SESSION 3
+#define GLIBTOP_KERN_PROC_TTY 4
+#define GLIBTOP_KERN_PROC_UID 5
+#define GLIBTOP_KERN_PROC_RUID 6
+
typedef struct _glibtop_proclist glibtop_proclist;
struct _glibtop_proclist
@@ -43,7 +54,7 @@ struct _glibtop_proclist
size; /* GLIBTOP_PROCLIST_SIZE */
};
-#define glibtop_get_proclist(proclist,method,param) glibtop_get_proclist_l(glibtop_global_server, proclist, method, param)
+#define glibtop_get_proclist(proclist,which,arg) glibtop_get_proclist_l(glibtop_global_server, proclist, which, arg)
#if GLIBTOP_SUID_PROCLIST
#define glibtop_get_proclist_r glibtop_get_proclist_p
diff --git a/sysdeps/freebsd/prockernel.c b/sysdeps/freebsd/prockernel.c
index 494ef2e3..fbb45d40 100644
--- a/sysdeps/freebsd/prockernel.c
+++ b/sysdeps/freebsd/prockernel.c
@@ -36,24 +36,28 @@
#include <unistd.h>
#include <fcntl.h>
-static const unsigned long _glibtop_sysdeps_proc_kernel =
-(1 << GLIBTOP_PROC_KERNEL_K_FLAGS) +
-(1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
-(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) +
-(1 << GLIBTOP_PROC_KERNEL_WCHAN);
-
-static const unsigned long _glibtop_sysdeps_proc_kernel_user =
+static const unsigned long _glibtop_sysdeps_proc_kernel_pstats =
(1 << GLIBTOP_PROC_KERNEL_MIN_FLT) +
(1 << GLIBTOP_PROC_KERNEL_MAJ_FLT) +
(1 << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
(1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT);
+static const unsigned long _glibtop_sysdeps_proc_kernel_pcb =
+(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) +
+(1 << GLIBTOP_PROC_KERNEL_KSTK_ESP);
+
+static const unsigned long _glibtop_sysdeps_proc_kernel_wchan =
+(1 << GLIBTOP_PROC_KERNEL_NWCHAN) +
+(1 << GLIBTOP_PROC_KERNEL_WCHAN);
+
/* Init function. */
void
glibtop_init_proc_kernel_p (glibtop *server)
{
- server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
+ server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel_pstats |
+ _glibtop_sysdeps_proc_kernel_pcb |
+ _glibtop_sysdeps_proc_kernel_wchan;
}
void
@@ -62,9 +66,9 @@ glibtop_get_proc_kernel_p (glibtop *server,
pid_t pid)
{
struct kinfo_proc *pinfo;
- struct i386tss *pcb_tss;
struct user *u_addr = (struct user *)USRSTACK;
struct pstats pstats;
+ struct pcb pcb;
int f, count;
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
@@ -78,32 +82,59 @@ glibtop_get_proc_kernel_p (glibtop *server,
/* Taken from `saveuser ()' in `/usr/src/bin/ps/ps.c'. */
+ /* [FIXME]: /usr/include/sys/user.h tells me that the user area
+ * may or may not be at the same kernel address in all
+ * processes, but I don't see any way to get that address.
+ * Since `ps' simply uses its own address, I think it's
+ * safe to do this here, too. */
+
+ /* NOTE: You need to mount the /proc filesystem to make
+ * `kvm_uread' work. */
+
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
- kvm_uread (server->machine.kd, pinfo [0].kp_proc,
+ kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
(unsigned long) &u_addr->u_stats,
- (char *) &pstats, sizeof (pstats)) == sizeof (pstats)) {
- /*
- * The u-area might be swapped out, and we can't get
- * at it because we have a crashdump and no swap.
- * If it's here fill in these fields, otherwise, just
- * leave them 0.
- */
-
- buf->min_flt = (u_int64_t) pstats.p_ru.ru_minflt;
- buf->maj_flt = (u_int64_t) pstats.p_ru.ru_majflt;
- buf->cmin_flt = (u_int64_t) pstats.p_cru.ru_minflt;
- buf->cmaj_flt = (u_int64_t) pstats.p_cru.ru_majflt;
-
- buf->flags |= _glibtop_sysdeps_proc_kernel_user;
- }
+ (char *) &pstats, sizeof (pstats)) == sizeof (pstats))
+ {
+ /*
+ * The u-area might be swapped out, and we can't get
+ * at it because we have a crashdump and no swap.
+ * If it's here fill in these fields, otherwise, just
+ * leave them 0.
+ */
+
+ buf->min_flt = (u_int64_t) pstats.p_ru.ru_minflt;
+ buf->maj_flt = (u_int64_t) pstats.p_ru.ru_majflt;
+ buf->cmin_flt = (u_int64_t) pstats.p_cru.ru_minflt;
+ buf->cmaj_flt = (u_int64_t) pstats.p_cru.ru_majflt;
+
+ buf->flags |= _glibtop_sysdeps_proc_kernel_pstats;
+ }
-#if 0
- /* kstk_esp: pcb_tss.tss_esp */
- buf->kstk_esp = (u_int64_t) usr.u_pcb.pcb_ksp;
- /* kstk_eip: pcb_tss.tss_eip */
- buf->kstk_eip = (u_int64_t) usr.u_pcb.pcb_pc;
-#endif
+ if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
+ kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
+ (unsigned long) &u_addr->u_pcb,
+ (char *) &pcb, sizeof (pcb)) == sizeof (pcb))
+ {
+ /* Same like with pstats above. */
+
+ buf->kstk_esp = (u_int64_t) pcb.pcb_ksp;
+ buf->kstk_eip = (u_int64_t) pcb.pcb_pc;
+
+ buf->flags |= _glibtop_sysdeps_proc_kernel_pcb;
+ }
+
+ /* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
+
+ buf->nwchan = (u_int64_t) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
+
+ if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
+ strncpy (buf->wchan, pinfo [0].kp_eproc.e_wmesg,
+ sizeof (buf->wchan) - 1);
+ buf->wchan [sizeof (buf->wchan) - 1] = 0;
+ } else {
+ buf->wchan [0] = 0;
+ }
- /* wchan : kinfo_proc.proc.p_wchan */
- buf->wchan = (u_int64_t) pinfo [0].kp_proc.p_wchan;
+ buf->flags |= _glibtop_sysdeps_proc_kernel_wchan;
}
diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c
index bb1fefda..2c1e371e 100644
--- a/sysdeps/freebsd/proclist.c
+++ b/sysdeps/freebsd/proclist.c
@@ -58,7 +58,7 @@ glibtop_init_proclist_p (glibtop *server)
unsigned *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
- int64_t method, int64_t param)
+ int64_t which, int64_t arg)
{
struct kinfo_proc *pinfo;
unsigned *pids = NULL;
@@ -70,8 +70,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
memset (buf, 0, sizeof (glibtop_proclist));
/* Get the process data */
- pinfo = kvm_getprocs (server->machine.kd,
- KERN_PROC_ALL, NULL, &count);
+ pinfo = kvm_getprocs (server->machine.kd, which, arg, &count);
/* Allocate count objects in the pids_chain array
* Same as malloc is pids is NULL, which it is. */
pids = glibtop_realloc_r (server, pids, count * sizeof (unsigned));
diff --git a/sysdeps/freebsd/procsegment.c b/sysdeps/freebsd/procsegment.c
index 584b80d8..999eaa5f 100644
--- a/sysdeps/freebsd/procsegment.c
+++ b/sysdeps/freebsd/procsegment.c
@@ -60,6 +60,7 @@ glibtop_get_proc_segment_p (glibtop *server,
memset (buf, 0, sizeof (glibtop_proc_segment));
+#if 0
/* Get the process info from the kernel */
kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, count);
if (*count != 1) {
@@ -84,5 +85,6 @@ glibtop_get_proc_segment_p (glibtop *server,
*/
/* start_stack: address of the bottom of stack segment
*/
+#endif
}
diff --git a/sysdeps/names/prockernel.c b/sysdeps/names/prockernel.c
index e49f9b83..6f101b65 100644
--- a/sysdeps/names/prockernel.c
+++ b/sysdeps/names/prockernel.c
@@ -25,20 +25,21 @@
const char *glibtop_names_proc_kernel [GLIBTOP_MAX_PROC_KERNEL] =
{
"k_flags", "min_flt", "maj_flt", "cmin_flt", "cmaj_flt",
- "kstk_esp", "kstk_eip", "wchan"
+ "kstk_esp", "kstk_eip", "nwchan", "wchan"
};
const unsigned glibtop_types_proc_kernel [GLIBTOP_MAX_PROC_KERNEL] =
{
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
- GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG
+ GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_STRING
};
const char *glibtop_labels_proc_kernel [GLIBTOP_MAX_PROC_KERNEL] =
{
N_("K_Flags"), N_("Min_Flt"), N_("Maj_Flt"), N_("CMin_Flt"),
- N_("CMaj_Flt"), N_("KStk_ESP"), N_("KStk_EIP"), N_("WChan")
+ N_("CMaj_Flt"), N_("KStk_ESP"), N_("KStk_EIP"), N_("NWChan"),
+ N_("WChan")
};
const char *glibtop_descriptions_proc_kernel [GLIBTOP_MAX_PROC_KERNEL] =
@@ -69,9 +70,11 @@ const char *glibtop_descriptions_proc_kernel [GLIBTOP_MAX_PROC_KERNEL] =
"the kernel stack page for the process."),
/* KStk_EIP */
N_("The current EIP (32-bit instruction pointer)."),
- /* WChan */
+ /* NWChan */
N_("This is the \"channel\" in which the process is waiting. This "
"is the address of a system call, and can be looked up in a "
"namelist if you need a textual name. (If you have an up-to-date "
- "/etc/psdatabase, then try ps -l to see the WCHAN field in action)")
+ "/etc/psdatabase, then try ps -l to see the WCHAN field in action)"),
+ /* WChan */
+ N_("This is the textual name of the `nwchan' field.")
};