More profiling stuff.
This commit is contained in:
@@ -35,7 +35,7 @@ static const unsigned long _glibtop_sysdeps_cpu =
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
@@ -61,8 +61,12 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
sscanf (buffer, "cpu %lu %lu %lu %lu\n",
|
||||
&buf->user, &buf->nice, &buf->sys, &buf->idle);
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = skip_token (tmp); /* "cpu" */
|
||||
buf->user = strtoul (tmp, &tmp, 10);
|
||||
buf->nice = strtoul (tmp, &tmp, 10);
|
||||
buf->sys = strtoul (tmp, &tmp, 10);
|
||||
buf->idle = strtoul (tmp, &tmp, 10);
|
||||
|
||||
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||
|
||||
|
@@ -24,9 +24,22 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#if _IN_LIBGTOP
|
||||
|
||||
static inline char *
|
||||
skip_token(const char *p)
|
||||
{
|
||||
while (isspace(*p)) p++;
|
||||
while (*p && !isspace(*p)) p++;
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct _glibtop_machine glibtop_machine;
|
||||
|
||||
struct _glibtop_machine
|
||||
|
@@ -33,7 +33,7 @@ static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
void
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
@@ -59,9 +59,10 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
sscanf (buffer, "%lf %lf %lf\n",
|
||||
&buf->loadavg [0], &buf->loadavg [1], &buf->loadavg [2]);
|
||||
|
||||
buf->loadavg [0] = strtod (buffer, &tmp);
|
||||
buf->loadavg [1] = strtod (tmp, &tmp);
|
||||
buf->loadavg [2] = strtod (tmp, &tmp);
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_loadavg = fd;
|
||||
#else
|
||||
|
@@ -36,7 +36,7 @@ static const unsigned long _glibtop_sysdeps_mem =
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
@@ -62,9 +62,16 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
sscanf (buffer, "%*[^\n]\nMem: %lu %lu %lu %lu %lu %lu\n",
|
||||
&buf->total, &buf->used, &buf->free, &buf->shared,
|
||||
&buf->buffer, &buf->cached);
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = skip_token (tmp); /* "Mem:" */
|
||||
tmp = skip_token (tmp); /* total memory */
|
||||
|
||||
buf->total = strtoul (tmp, &tmp, 10);
|
||||
buf->used = strtoul (tmp, &tmp, 10);
|
||||
buf->free = strtoul (tmp, &tmp, 10);
|
||||
buf->shared = strtoul (tmp, &tmp, 10);
|
||||
buf->buffer = strtoul (tmp, &tmp, 10);
|
||||
buf->cached = strtoul (tmp, &tmp, 10);
|
||||
|
||||
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
|
||||
|
@@ -34,7 +34,7 @@ static unsigned long _glibtop_sysdeps_swap =
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
char buffer [BUFSIZ], *tmp;
|
||||
int fd = 0, ret;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
@@ -60,8 +60,13 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
glibtop_error_r (server, "read (%s): %s",
|
||||
FILENAME, strerror (errno));
|
||||
|
||||
sscanf (buffer, "%*[^\n]\n%*[^\n]\nSwap: %lu %lu %lu\n",
|
||||
&buf->total, &buf->used, &buf->free);
|
||||
tmp = strchr (buffer, '\n');
|
||||
tmp = strchr (tmp+1, '\n');
|
||||
|
||||
tmp = skip_token (tmp); /* "Swap:" */
|
||||
buf->total = strtoul (tmp, &tmp, 10);
|
||||
buf->used = strtoul (tmp, &tmp, 10);
|
||||
buf->free = strtoul (tmp, &tmp, 10);
|
||||
|
||||
#ifdef GLIBTOP_CACHE_OPEN
|
||||
server->machine.fd_meminfo = fd;
|
||||
|
Reference in New Issue
Block a user