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:
@@ -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>
|
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
|
||||||
|
|
||||||
* netload.c: (glibtop_get_netload_s): Implemented new IPv6 feature.
|
* netload.c: (glibtop_get_netload_s): Implemented new IPv6 feature.
|
||||||
|
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
/* gcc warning bug */
|
||||||
|
unsigned get_pageshift();
|
||||||
|
|
||||||
|
|
||||||
unsigned long long
|
unsigned long long
|
||||||
get_scaled(const char *buffer, const char *key)
|
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;
|
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;
|
||||||
|
}
|
||||||
|
@@ -24,9 +24,11 @@
|
|||||||
#ifndef __GLIBTOP_SERVER_H__
|
#ifndef __GLIBTOP_SERVER_H__
|
||||||
#define __GLIBTOP_SERVER_H__
|
#define __GLIBTOP_SERVER_H__
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@@ -34,6 +36,8 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||||
|
|
||||||
|
unsigned get_pageshift();
|
||||||
|
|
||||||
static inline char *
|
static inline char *
|
||||||
skip_token (const char *p)
|
skip_token (const char *p)
|
||||||
{
|
{
|
||||||
@@ -87,8 +91,7 @@ static inline char *
|
|||||||
proc_stat_after_cmd (char *p)
|
proc_stat_after_cmd (char *p)
|
||||||
{
|
{
|
||||||
p = strrchr (p, ')');
|
p = strrchr (p, ')');
|
||||||
if (!p) return p;
|
if (G_LIKELY(p))
|
||||||
|
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@@ -52,40 +52,35 @@ glibtop_init_ppp_s (glibtop *server)
|
|||||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static gboolean
|
||||||
get_ISDN_stats (glibtop *server, int *in, int *out)
|
get_ISDN_stats (glibtop *server, int *in, int *out)
|
||||||
{
|
{
|
||||||
unsigned long *isdn_stats, *ptr;
|
unsigned long isdn_stats[2 * ISDN_MAX_CHANNELS], *ptr;
|
||||||
int fd, i;
|
int fd;
|
||||||
|
|
||||||
*in = *out = 0;
|
*in = *out = 0;
|
||||||
|
|
||||||
isdn_stats = g_malloc (ISDN_MAX_CHANNELS * 2 * sizeof (unsigned long));
|
|
||||||
|
|
||||||
fd = open ("/dev/isdninfo", O_RDONLY);
|
fd = open ("/dev/isdninfo", O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
g_free (isdn_stats);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
|
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
|
||||||
g_free (isdn_stats);
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
return FALSE;
|
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++;
|
*in += *ptr++; *out += *ptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (isdn_stats);
|
|
||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_ISDN_on (glibtop *server, int *online)
|
static gboolean is_ISDN_on (glibtop *server, int *online)
|
||||||
{
|
{
|
||||||
FILE *f = 0;
|
FILE *f = 0;
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p;
|
||||||
|
@@ -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_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
(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. */
|
/* Init function. */
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_init_proc_mem_s (glibtop *server)
|
glibtop_init_proc_mem_s (glibtop *server)
|
||||||
{
|
{
|
||||||
register int pagesize;
|
|
||||||
|
|
||||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
||||||
_glibtop_sysdeps_proc_mem_statm;
|
_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. */
|
/* 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)
|
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p;
|
||||||
|
const unsigned pageshift = get_pageshift();
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
|
||||||
|
|
||||||
|
@@ -37,34 +37,13 @@ static const unsigned long _glibtop_sysdeps_proc_segment_statm =
|
|||||||
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
|
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
|
||||||
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
|
(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. */
|
/* Init function. */
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_init_proc_segment_s (glibtop *server)
|
glibtop_init_proc_segment_s (glibtop *server)
|
||||||
{
|
{
|
||||||
register int pagesize;
|
|
||||||
|
|
||||||
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
|
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
|
||||||
_glibtop_sysdeps_proc_segment_statm;
|
_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. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -74,6 +53,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
|||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p;
|
||||||
|
const unsigned pageshift = get_pageshift();
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
|||||||
buf->state = p [2];
|
buf->state = p [2];
|
||||||
|
|
||||||
p = skip_token (buffer); p++; /* pid */
|
p = skip_token (buffer); p++; /* pid */
|
||||||
if (*p++ != '(')
|
if (G_UNLIKELY(*p++ != '('))
|
||||||
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
|
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
|
||||||
|
|
||||||
g_strlcpy (buf->cmd, p, sizeof buf->cmd);
|
g_strlcpy (buf->cmd, p, sizeof buf->cmd);
|
||||||
|
@@ -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->priority = 2*15 - buf->priority;
|
||||||
buf->nice = 15 - buf->nice;
|
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 */
|
/* when tty wasn't full devno */
|
||||||
buf->tty = 4*0x100 + buf->tty;
|
buf->tty = 4*0x100 + buf->tty;
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ init_sysinfo (glibtop *server)
|
|||||||
ssize_t len;
|
ssize_t len;
|
||||||
char buffer [BUFSIZ];
|
char buffer [BUFSIZ];
|
||||||
|
|
||||||
if(sysinfo.flags) return;
|
if(G_LIKELY(sysinfo.flags)) return;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user