added memory statistics.

* sysdeps/sun4/{open.c, mem.c, glibtop_machine.h}: added
memory statistics.
This commit is contained in:
Martin Baulig
1998-05-24 16:16:59 +00:00
parent ff3aced01e
commit 15caaaf34f
4 changed files with 108 additions and 1 deletions

View File

@@ -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.

View File

@@ -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;
};

View File

@@ -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;
}
}

View File

@@ -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));
@@ -109,6 +112,40 @@ glibtop_open (glibtop *server, const char *program_name)
(_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))