summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@src.gnome.org>1998-05-24 16:16:59 +0000
committerMartin Baulig <martin@src.gnome.org>1998-05-24 16:16:59 +0000
commit15caaaf34f82764466d6efcdbacc1ec0ba18d1cb (patch)
tree3a0b11f5869d03afcb8137ca8cdee397d674d969
parentff3aced01e1776ecb6e95f20e31b51d72aa3e057 (diff)
downloadlibgtop-15caaaf34f82764466d6efcdbacc1ec0ba18d1cb.tar.gz
added memory statistics.
* sysdeps/sun4/{open.c, mem.c, glibtop_machine.h}: added memory statistics.
-rw-r--r--ChangeLog8
-rw-r--r--sysdeps/sun4/glibtop_machine.h9
-rw-r--r--sysdeps/sun4/mem.c55
-rw-r--r--sysdeps/sun4/open.c37
4 files changed, 108 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 0eb85899..bb6195bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+1998-05-24 Martin Baulig <martin@home-of-linux.org>
+
+ * sysdeps/sun4/{open.c, mem.c, glibtop_machine.h}: added
+ memory statistics.
+
+ * include/glibtop/mem.h (_glibtop_mem): added `locked'
+ member to this structure for SunOS.
+
1998-05-23 Martin Baulig <martin@home-of-linux.org>
* sysdeps/sun4/{open.c, cpu.c}: Started porting.
diff --git a/sysdeps/sun4/glibtop_machine.h b/sysdeps/sun4/glibtop_machine.h
index 3fbb0251..8fb3d133 100644
--- a/sysdeps/sun4/glibtop_machine.h
+++ b/sysdeps/sun4/glibtop_machine.h
@@ -44,6 +44,8 @@
#include <sys/syscall.h>
#endif
+__BEGIN_DECLS
+
/* Older versions of SunOS don't have a typedef for pid_t.
Hopefully this will catch all those cases without causing other problems.
*/
@@ -67,7 +69,8 @@ typedef int pid_t;
#define X_MP_TIME 10
#endif
-__BEGIN_DECLS
+/* Log base 2 of 1024 is 10 (2^10 == 1024) */
+#define LOG1024 10
typedef struct _glibtop_machine glibtop_machine;
@@ -77,6 +80,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 */
+ unsigned long pages, epages;
+ struct page *physpage;
+ int bytesize, count;
+ int pageshift; /* log base 2 of the pagesize */
kvm_t *kd;
};
diff --git a/sysdeps/sun4/mem.c b/sysdeps/sun4/mem.c
index 0410e2dd..d6a67788 100644
--- a/sysdeps/sun4/mem.c
+++ b/sysdeps/sun4/mem.c
@@ -22,10 +22,65 @@
#include <config.h>
#include <glibtop/mem.h>
+static const unsigned long _glibtop_sysdeps_mem =
+(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
+(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_LOCKED);
+
+/* define pagetok in terms of pageshift */
+
+#define pagetok(size) ((size) << server->machine.pageshift)
+
/* Provides information about memory usage. */
void
glibtop_get_mem__r (glibtop *server, glibtop_mem *buf)
{
memset (buf, 0, sizeof (glibtop_mem));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the array of physpage descriptors */
+
+ (void) _glibtop_getkval (server, server->machine.pages,
+ (int *) server->machine.physpage,
+ server->machine.bytesize,
+ "array _page");
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+
+ { /* sum memory statistics */
+ register struct page *pp;
+ register int cnt;
+ register int inuse;
+ register int free;
+ register int locked;
+
+ /* bop thru the array counting page types */
+
+ pp = server->machine.physpage;
+ inuse = free = locked = 0;
+ for (cnt = server->machine.count; --cnt >= 0; pp++) {
+ if (pp->p_free)
+ free++;
+ else if (pp->p_lock || pp->p_keepcnt > 0)
+ locked++;
+ else
+ inuse++;
+ }
+
+ /* convert memory stats to Kbytes */
+
+ buf->total = pagetok (inuse + free);
+ buf->used = pagetok (inuse);
+ buf->free = pagetok (free);
+ buf->locked = pagetok (locked);
+
+ buf->flags = _glibtop_sysdeps_mem;
+ }
}
diff --git a/sysdeps/sun4/open.c b/sysdeps/sun4/open.c
index 94cc5a44..1944cdf7 100644
--- a/sysdeps/sun4/open.c
+++ b/sysdeps/sun4/open.c
@@ -21,6 +21,7 @@
#include <glibtop.h>
#include <glibtop/open.h>
+#include <glibtop/xmalloc.h>
struct nlist _glibtop_nlist[] = {
#ifdef i386
@@ -58,6 +59,8 @@ struct nlist _glibtop_nlist[] = {
void
glibtop_open (glibtop *server, const char *program_name)
{
+ register int pagesize;
+
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
memset (server, 0, sizeof (glibtop));
@@ -108,7 +111,41 @@ glibtop_open (glibtop *server, const char *program_name)
if ((server->machine.nlist_count > 0) &&
(_glibtop_check_nlist (server, _glibtop_nlist) > 0))
_exit (1);
+
+ /* This are for the memory statistics. */
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_PAGES].n_value,
+ (int *)(&server->machine.pages),
+ sizeof (server->machine.pages),
+ _glibtop_nlist[X_PAGES].n_name);
+
+ (void) _glibtop_getkval (server, _glibtop_nlist[X_EPAGES].n_value,
+ (int *)(&server->machine.epages),
+ sizeof (server->machine.epages),
+ _glibtop_nlist[X_EPAGES].n_name);
+
+ server->machine.bytesize = server->machine.epages -
+ server->machine.pages;
+ server->machine.count = server->machine.bytesize / sizeof (struct page);
+
+ server->machine.physpage =
+ (struct page *) glibtop_malloc__r (server, server->machine.bytesize);
+
+ /* get the page size with "getpagesize" and calculate pageshift from it */
+
+ pagesize = getpagesize();
+
+ server->machine.pageshift = 0;
+
+ while (pagesize > 1) {
+ server->machine.pageshift++;
+ pagesize >>= 1;
+ }
+
+ /* we only need the amount of log(2)1024 for our conversion */
+
+ server->machine.pageshift -= LOG1024;
+
/* Drop priviledges. */
if (setreuid (server->machine.euid, server->machine.uid))