Whitespace cleanup.

* loadavg.c: (glibtop_get_loadavg_s): Whitespace cleanup.

        * ppp.c: (get_ISDN_stats), (is_ISDN_on): Replace g_malloc by an
        array.

        * glibtop_server.c: (get_pageshift):
        * glibtop_server.h:
        * procmem.c: (glibtop_init_proc_mem_s), (glibtop_get_proc_mem_s):
        * procsegment.c: (glibtop_init_proc_segment_s),
        (glibtop_get_proc_segment_s): Moved the pageshift calculation to
        glibtop_server.[ch]

        * procstate.c: (glibtop_get_proc_state_s):
        * procuid.c: (glibtop_get_proc_uid_s):
        * sysinfo.c: (init_sysinfo): Minor cleanups.
This commit is contained in:
Benoît Dejean
2004-06-18 07:24:58 +00:00
parent 34e322e7c2
commit e12ac5f40c
10 changed files with 60 additions and 62 deletions

View File

@@ -1,3 +1,21 @@
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* loadavg.c: (glibtop_get_loadavg_s): Whitespace cleanup.
* ppp.c: (get_ISDN_stats), (is_ISDN_on): Replace g_malloc by an
array.
* glibtop_server.c: (get_pageshift):
* glibtop_server.h:
* procmem.c: (glibtop_init_proc_mem_s), (glibtop_get_proc_mem_s):
* procsegment.c: (glibtop_init_proc_segment_s),
(glibtop_get_proc_segment_s): Moved the pageshift calculation to
glibtop_server.[ch]
* procstate.c: (glibtop_get_proc_state_s):
* procuid.c: (glibtop_get_proc_uid_s):
* sysinfo.c: (init_sysinfo): Minor cleanups.
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* netload.c: (glibtop_get_netload_s): Implemented new IPv6 feature.

View File

@@ -7,6 +7,9 @@
#include <fcntl.h>
/* gcc warning bug */
unsigned get_pageshift();
unsigned long long
get_scaled(const char *buffer, const char *key)
@@ -50,3 +53,21 @@ proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
return 0;
}
#warning "Ignore the following warning"
unsigned get_pageshift()
{
static unsigned pageshift = 0;
if(G_UNLIKELY(!pageshift))
{
register unsigned pagesize = getpagesize();
while( pagesize > 1 )
{
pagesize >>= 1;
pageshift++;
}
}
return pageshift;
}

View File

@@ -24,9 +24,11 @@
#ifndef __GLIBTOP_SERVER_H__
#define __GLIBTOP_SERVER_H__
#include <glib.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
G_BEGIN_DECLS
@@ -34,6 +36,8 @@ G_BEGIN_DECLS
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
unsigned get_pageshift();
static inline char *
skip_token (const char *p)
{
@@ -87,9 +91,8 @@ static inline char *
proc_stat_after_cmd (char *p)
{
p = strrchr (p, ')');
if (!p) return p;
*p++ = '\0';
if (G_LIKELY(p))
*p++ = '\0';
return p;
}

View File

@@ -73,12 +73,12 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
buf->flags = _glibtop_sysdeps_loadavg;
while (isspace(*p)) p++;
while (isspace(*p)) p++;
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
old = p;
while (*p) {
while (*p) {
if (*p == '/')
break;
if (!isdigit (*p))

View File

@@ -52,40 +52,35 @@ glibtop_init_ppp_s (glibtop *server)
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
}
static int
static gboolean
get_ISDN_stats (glibtop *server, int *in, int *out)
{
unsigned long *isdn_stats, *ptr;
int fd, i;
unsigned long isdn_stats[2 * ISDN_MAX_CHANNELS], *ptr;
int fd;
*in = *out = 0;
isdn_stats = g_malloc (ISDN_MAX_CHANNELS * 2 * sizeof (unsigned long));
fd = open ("/dev/isdninfo", O_RDONLY);
if (fd < 0) {
g_free (isdn_stats);
return FALSE;
}
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
g_free (isdn_stats);
close (fd);
close(fd);
return FALSE;
}
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
for (ptr = isdn_stats;
ptr != (isdn_stats + G_N_ELEMENTS(isdn_stats));
/* NOOP */) {
*in += *ptr++; *out += *ptr++;
}
g_free (isdn_stats);
close (fd);
return TRUE;
}
static int is_ISDN_on (glibtop *server, int *online)
static gboolean is_ISDN_on (glibtop *server, int *online)
{
FILE *f = 0;
char buffer [BUFSIZ], *p;

View File

@@ -33,34 +33,14 @@ static const unsigned long _glibtop_sysdeps_proc_mem_statm =
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
(1L << GLIBTOP_PROC_MEM_SHARE);
#ifndef LOG1024
#define LOG1024 10
#endif
/* these are for getting the memory statistics */
static int pageshift = 0; /* log base 2 of the pagesize */
/* define pagetok in terms of pageshift */
#define pagetok(size) ((size) << pageshift)
/* Init function. */
void
glibtop_init_proc_mem_s (glibtop *server)
{
register int pagesize;
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
_glibtop_sysdeps_proc_mem_statm;
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
}
/* Provides detailed information about a process. */
@@ -69,6 +49,7 @@ void
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
const unsigned pageshift = get_pageshift();
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);

View File

@@ -37,34 +37,13 @@ static const unsigned long _glibtop_sysdeps_proc_segment_statm =
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
#ifndef LOG1024
#define LOG1024 10
#endif
/* these are for getting the memory statistics */
static int pageshift = 0; /* log base 2 of the pagesize */
/* define pagetok in terms of pageshift */
#define pagetok(size) ((size) << pageshift)
/* Init function. */
void
glibtop_init_proc_segment_s (glibtop *server)
{
register int pagesize;
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
_glibtop_sysdeps_proc_segment_statm;
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
}
/* Provides detailed information about a process. */
@@ -74,6 +53,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
char buffer [BUFSIZ], *p;
const unsigned pageshift = get_pageshift();
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);

View File

@@ -83,7 +83,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
buf->state = p [2];
p = skip_token (buffer); p++; /* pid */
if (*p++ != '(')
if (G_UNLIKELY(*p++ != '('))
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
g_strlcpy (buf->cmd, p, sizeof buf->cmd);

View File

@@ -117,7 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;
}
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
else if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
/* when tty wasn't full devno */
buf->tty = 4*0x100 + buf->tty;

View File

@@ -40,7 +40,7 @@ init_sysinfo (glibtop *server)
ssize_t len;
char buffer [BUFSIZ];
if(sysinfo.flags) return;
if(G_LIKELY(sysinfo.flags)) return;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);