committing patch from Sebastien Bacher <seb128@debian.org> for Linux 2.6

2003-10-20  Bastien Nocera  <hadess@hadess.net>

	* glibtop_server.h:
	* mem.c: (glibtop_get_mem_s):
	* swap.c: (glibtop_get_swap_s): committing patch from Sebastien
	Bacher <seb128@debian.org> for Linux 2.6 support (Closes: #104747)
This commit is contained in:
Bastien Nocera
2003-10-20 20:41:16 +00:00
committed by Bastien Nocera
parent b2283f7c79
commit 33fb22edd3
4 changed files with 39 additions and 19 deletions

View File

@@ -1,3 +1,10 @@
2003-10-20 Bastien Nocera <hadess@hadess.net>
* glibtop_server.h:
* mem.c: (glibtop_get_mem_s):
* swap.c: (glibtop_get_swap_s): committing patch from Sebastien
Bacher <seb128@debian.org> for Linux 2.6 support (Closes: #104747)
2003-10-20 Bastien Nocera <hadess@hadess.net>
* cpu.c: (glibtop_get_cpu_s):

View File

@@ -57,6 +57,25 @@ skip_line (const char *p)
return (char *) ++p;
}
static inline unsigned long
get_scaled(const char *buffer, const char *key)
{
const char *ptr;
char *next;
unsigned long value = 0;
if ((ptr = strstr(buffer, key)))
{
ptr += strlen(key);
value = strtoul(ptr, &next, 0);
if (strchr(next, 'k'))
value *= 1024;
else if (strchr(next, 'M'))
value *= 1024 * 1024;
}
return value;
}
static inline int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{

View File

@@ -65,17 +65,13 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
buffer [len] = '\0';
p = skip_line (buffer);
p = skip_token (p); /* "Mem:" */
buf->total = strtoul (p, &p, 0);
buf->used = strtoul (p, &p, 0);
buf->free = strtoul (p, &p, 0);
buf->shared = strtoul (p, &p, 0);
buf->buffer = strtoul (p, &p, 0);
buf->cached = strtoul (p, &p, 0);
buf->total = get_scaled(buffer, "MemTotal:");
buf->used = get_scaled(buffer, "Active:");
buf->free = get_scaled(buffer, "MemFree:");
buf->shared = get_scaled(buffer, "Mapped:");
buf->buffer = get_scaled(buffer, "Buffers:");
buf->cached = get_scaled(buffer, "Cached:");
buf->user = buf->total - buf->free - buf->cached - buf->buffer;
buf->flags = _glibtop_sysdeps_mem;
}

View File

@@ -70,13 +70,11 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
buffer [len] = '\0';
p = skip_line (buffer);
p = skip_line (p);
p = skip_token (p); /* "Swap:" */
/* Kernel 2.6 with multiple lines */
buf->total = strtoul (p, &p, 0);
buf->used = strtoul (p, &p, 0);
buf->free = strtoul (p, &p, 0);
buf->total = get_scaled(buffer, "SwapTotal:");
buf->free = get_scaled(buffer, "SwapFree:");
buf->used = buf->total - buf->free;
buf->flags = _glibtop_sysdeps_swap;