summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoît Dejean <bdejean@src.gnome.org>2004-06-18 07:24:58 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2004-06-18 07:24:58 +0000
commite12ac5f40c165bc5c1751b4f40d2569126483b79 (patch)
treebd7de0da3de691072477f3da9a7ebbc74ca836c6
parent34e322e7c26924b083da3355e127753c68baf8da (diff)
downloadlibgtop-e12ac5f40c165bc5c1751b4f40d2569126483b79.tar.gz
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.
-rw-r--r--sysdeps/linux/ChangeLog18
-rw-r--r--sysdeps/linux/glibtop_server.c21
-rw-r--r--sysdeps/linux/glibtop_server.h9
-rw-r--r--sysdeps/linux/loadavg.c4
-rw-r--r--sysdeps/linux/ppp.c21
-rw-r--r--sysdeps/linux/procmem.c21
-rw-r--r--sysdeps/linux/procsegment.c22
-rw-r--r--sysdeps/linux/procstate.c2
-rw-r--r--sysdeps/linux/procuid.c2
-rw-r--r--sysdeps/linux/sysinfo.c2
10 files changed, 60 insertions, 62 deletions
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog
index cd87c0ff..ea3cdebd 100644
--- a/sysdeps/linux/ChangeLog
+++ b/sysdeps/linux/ChangeLog
@@ -1,5 +1,23 @@
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.
2004-06-13 Benoît Dejean <tazforever@dlfp.org>
diff --git a/sysdeps/linux/glibtop_server.c b/sysdeps/linux/glibtop_server.c
index a33d39db..8260a5c7 100644
--- a/sysdeps/linux/glibtop_server.c
+++ b/sysdeps/linux/glibtop_server.c
@@ -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;
+}
diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h
index 0946cf1e..a522cefb 100644
--- a/sysdeps/linux/glibtop_server.h
+++ b/sysdeps/linux/glibtop_server.h
@@ -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;
}
diff --git a/sysdeps/linux/loadavg.c b/sysdeps/linux/loadavg.c
index 84622e41..ea639b6e 100644
--- a/sysdeps/linux/loadavg.c
+++ b/sysdeps/linux/loadavg.c
@@ -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))
diff --git a/sysdeps/linux/ppp.c b/sysdeps/linux/ppp.c
index 3f4ab222..baf02902 100644
--- a/sysdeps/linux/ppp.c
+++ b/sysdeps/linux/ppp.c
@@ -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;
diff --git a/sysdeps/linux/procmem.c b/sysdeps/linux/procmem.c
index 00f76b48..e2973b94 100644
--- a/sysdeps/linux/procmem.c
+++ b/sysdeps/linux/procmem.c
@@ -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);
diff --git a/sysdeps/linux/procsegment.c b/sysdeps/linux/procsegment.c
index 34d9a7b2..99d084bd 100644
--- a/sysdeps/linux/procsegment.c
+++ b/sysdeps/linux/procsegment.c
@@ -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);
diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c
index 71653639..d348ebc7 100644
--- a/sysdeps/linux/procstate.c
+++ b/sysdeps/linux/procstate.c
@@ -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);
diff --git a/sysdeps/linux/procuid.c b/sysdeps/linux/procuid.c
index de041a9e..d4dc61b2 100644
--- a/sysdeps/linux/procuid.c
+++ b/sysdeps/linux/procuid.c
@@ -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;
diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c
index d74b5fa1..667a1b51 100644
--- a/sysdeps/linux/sysinfo.c
+++ b/sysdeps/linux/sysinfo.c
@@ -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);