summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorBenoît Dejean <bdejean@src.gnome.org>2004-08-03 11:40:37 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2004-08-03 11:40:37 +0000
commit808a2d48ac98f8c277428db939e975941c0e4aff (patch)
treec4acbfc768efce29e962710782b0cb4459121496 /sysdeps
parent5b39a4831df592857c4faea787a9d2bd0a767a14 (diff)
downloadlibgtop-808a2d48ac98f8c277428db939e975941c0e4aff.tar.gz
Added next_token(). Changed skip_token(), i hope it won't break any bad
* glibtop_server.h: Added next_token(). Changed skip_token(), i hope it won't break any bad code. * procstate.c: (glibtop_get_proc_state_s): Used next_token. * proctime.c: (glibtop_get_proc_time_s): Implemented .start_time the way it ought to be. Clean ups.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/linux/ChangeLog8
-rw-r--r--sysdeps/linux/glibtop_server.h9
-rw-r--r--sysdeps/linux/procstate.c9
-rw-r--r--sysdeps/linux/proctime.c33
4 files changed, 52 insertions, 7 deletions
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog
index b0e03dc5..c023faa7 100644
--- a/sysdeps/linux/ChangeLog
+++ b/sysdeps/linux/ChangeLog
@@ -1,3 +1,11 @@
+2004-08-03 Benoît Dejean <tazforever@dlfp.org>
+
+ * glibtop_server.h: Added next_token(). Changed skip_token(),
+ i hope it won't break any bad code.
+ * procstate.c: (glibtop_get_proc_state_s): Used next_token.
+ * proctime.c: (glibtop_get_proc_time_s): Implemented .start_time
+ the way it ought to be. Clean ups
+
2004-07-22 Benoît Dejean <tazforever@dlfp.org>
* netload.c: (glibtop_get_netload_s): Fixed leak.
diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h
index 69143fe4..80796c20 100644
--- a/sysdeps/linux/glibtop_server.h
+++ b/sysdeps/linux/glibtop_server.h
@@ -41,12 +41,19 @@ G_BEGIN_DECLS
unsigned get_pageshift();
+static inline char*
+next_token(const char *p)
+{
+ while (isspace(*p)) p++;
+ return (char*) p;
+}
static inline char *
skip_token (const char *p)
{
- while (isspace(*p)) p++;
+ p = next_token(p);
while (*p && !isspace(*p)) p++;
+ p = next_token(p);
return (char *)p;
}
diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c
index cc171c0b..bf4380f9 100644
--- a/sysdeps/linux/procstate.c
+++ b/sysdeps/linux/procstate.c
@@ -72,16 +72,15 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
buf->flags = _glibtop_sysdeps_proc_state_uid;
- sprintf (buffer, "/proc/%d", pid);
-
/* Now we read the remaining fields. */
if (proc_stat_to_buffer (buffer, pid))
return;
- p = strrchr (buffer, ')'); *p = '\0';
+ p = proc_stat_after_cmd(buffer);
+ p = next_token(p);
- switch(p[2])
+ switch(*p)
{
case 'R':
buf->state = GLIBTOP_PROCESS_RUNNING;
@@ -112,7 +111,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
break;
}
- p = skip_token (buffer); p++; /* pid */
+ p = skip_token (buffer); /* pid */
if (G_UNLIKELY(*p++ != '('))
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c
index f7da99f2..d32f9e45 100644
--- a/sysdeps/linux/proctime.c
+++ b/sysdeps/linux/proctime.c
@@ -24,6 +24,7 @@
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/proctime.h>
+#include <glibtop/uptime.h>
static const unsigned long _glibtop_sysdeps_proc_time =
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) +
@@ -65,6 +66,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
p = skip_multiple_token (p, 11);
+ /* clock_t (1/100 s) */
buf->utime = strtoull (p, &p, 0);
buf->stime = strtoull (p, &p, 0);
buf->cutime = strtoull (p, &p, 0);
@@ -76,7 +78,36 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
// lets skip it (using previous skip_multiple_token)
// buf->timeout = strtoull (p, &p, 0);
buf->it_real_value = strtoull (p, &p, 0);
- buf->start_time = strtoull (p, &p, 0);
+
+ /* seconds since epoch */
+ {
+ /* Linux provides start_time as clock_t representing
+ the start of <pid> after boot_time.
+ Let's use glibtop_get_uptime to get boot_time.
+ But i'm not sure if this is safe
+
+ See libgtop documentation.
+
+ #ifdef __KERNEL__
+ ...
+ *
+ * Have the 32 bit jiffies value wrap 5 minutes after boot
+ * so jiffies wrap bugs show up earlier.
+ *
+ #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
+ ...
+ #endif
+
+ start_time may be incremented by INITIAL_JIFFIES, so start_time
+ may be not be exact. You may also get wrong start_time if your
+ system clock is not synchronised with you hardware clock.
+ 'man hwclock'
+ */
+ glibtop_uptime up;
+ glibtop_get_uptime_s(server, &up);
+
+ buf->start_time = up.boot_time + strtoull (p, &p, 0) / 100;
+ }
buf->frequency = 100;