diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2005-12-13 09:15:49 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2005-12-13 09:15:49 +0000 |
commit | 806a8160263c9046e7fa4232a4eaf896ff80c6d1 (patch) | |
tree | dfa9c7d9c0f6fdb06a3fa6f127767c62aec61bb1 /sysdeps | |
parent | ba7355df9ec7bb5f1df2146d2e1d8009d97eb1f6 (diff) | |
download | libgtop-806a8160263c9046e7fa4232a4eaf896ff80c6d1.tar.gz |
Fixed server->ncpu usage (SMP handling). Need more testing.
* cpu.c: (glibtop_get_cpu_s):
* glibtop_private.c: (get_scaled), (check_cpu_line):
* glibtop_private.h:
* open.c: (glibtop_open_s):
* proctime.c: (glibtop_get_proc_time_s):
Fixed server->ncpu usage (SMP handling). Need more testing.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/linux/ChangeLog | 10 | ||||
-rw-r--r-- | sysdeps/linux/cpu.c | 8 | ||||
-rw-r--r-- | sysdeps/linux/glibtop_private.c | 20 | ||||
-rw-r--r-- | sysdeps/linux/glibtop_private.h | 21 | ||||
-rw-r--r-- | sysdeps/linux/open.c | 10 | ||||
-rw-r--r-- | sysdeps/linux/proctime.c | 7 |
6 files changed, 64 insertions, 12 deletions
diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index d75a5161..a3820660 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,13 @@ +2005-12-13 Benoît Dejean <benoit@placenet.org> + + * cpu.c: (glibtop_get_cpu_s): + * glibtop_private.c: (get_scaled), (check_cpu_line): + * glibtop_private.h: + * open.c: (glibtop_open_s): + * proctime.c: (glibtop_get_proc_time_s): + + Fixed server->ncpu usage (SMP handling). Need more testing. + 2005-12-12 Benoît Dejean <benoit@placenet.org> * procmap.c: (add_smaps), (glibtop_get_proc_map_s): diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c index eb13ab9d..d973c77f 100644 --- a/sysdeps/linux/cpu.c +++ b/sysdeps/linux/cpu.c @@ -110,11 +110,11 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) * PER CPU */ - for (i = 0; i < GLIBTOP_NCPU && i < server->ncpu; i++) { + for (i = 0; i <= server->ncpu; i++) { p = skip_line(p); /* move to ^ */ - if (strncmp (p, "cpu", 3) || !isdigit (p [3])) + if (!check_cpu_line_warn(server, p, i)) break; p = skip_token(p); /* "cpuN" */ @@ -141,14 +141,14 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) } } - if(i >= 2) /* ok, that's a real SMP */ + if(server->ncpu) /* ok, that's a real SMP */ buf->flags |= _glibtop_sysdeps_cpu_smp; if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0)) { buf->flags |= _glibtop_sysdeps_cpu_2_6; - if(i >= 2) /* ok, that's a real SMP */ + if(server->ncpu) /* ok, that's a real SMP */ buf->flags |= _glibtop_sysdeps_cpu_smp_2_6; } } diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c index 62314aea..1ae9e8a0 100644 --- a/sysdeps/linux/glibtop_private.c +++ b/sysdeps/linux/glibtop_private.c @@ -21,7 +21,7 @@ get_scaled(const char *buffer, const char *key) char *next; unsigned long long value = 0; - if ((ptr = strstr(buffer, key))) + if (G_LIKELY((ptr = strstr(buffer, key)))) { ptr += strlen(key); value = strtoull(ptr, &next, 0); @@ -29,7 +29,10 @@ get_scaled(const char *buffer, const char *key) value *= 1024; else if (strchr(next, 'M')) value *= 1024 * 1024; - } + } else + g_warning("Could not read key '%s' in buffer '%s'", + key, buffer); + return value; } @@ -147,3 +150,16 @@ get_page_size(void) return pagesize; } + + + +gboolean +check_cpu_line(glibtop *server, const char *line, unsigned i) +{ + char start[10]; + + g_snprintf(start, sizeof start, "cpu%u", i); + + return g_str_has_prefix(line, start); +} + diff --git a/sysdeps/linux/glibtop_private.h b/sysdeps/linux/glibtop_private.h index ac22af7b..2f01d793 100644 --- a/sysdeps/linux/glibtop_private.h +++ b/sysdeps/linux/glibtop_private.h @@ -21,6 +21,7 @@ #define __LINUX__GLIBTOP_PRIVATE_H__ #include <glibtop.h> +#include <glibtop/error.h> #include <glib.h> @@ -121,6 +122,26 @@ size_t get_page_size(void) G_GNUC_INTERNAL; +gboolean +check_cpu_line(glibtop *server, const char *line, unsigned n) G_GNUC_INTERNAL; + + +static inline gboolean +check_cpu_line_warn(glibtop *server, const char *line, unsigned i) +{ + gboolean ret; + + ret = check_cpu_line(server, line, i); + + if (G_UNLIKELY(!ret)) + glibtop_warn_io_r(server, + "'%s' does not start with 'cpu%u'", + line, i); + + return ret; +} + + G_END_DECLS #endif /* __LINUX__GLIBTOP_PRIVATE_H__ */ diff --git a/sysdeps/linux/open.c b/sysdeps/linux/open.c index c3d8e171..a947b12c 100644 --- a/sysdeps/linux/open.c +++ b/sysdeps/linux/open.c @@ -77,12 +77,16 @@ glibtop_open_s (glibtop *server, const char *program_name, file_to_buffer(server, buffer, FILENAME); - for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) { + p = skip_line(p); /* cpu */ - p = skip_line(p); + for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) { - if (strncmp (p, "cpu", 3) || !isdigit (p [3])) + if (!check_cpu_line(server, p, server->ncpu)) { + server->ncpu--; break; + } + + p = skip_line(p); } #ifdef DEBUG diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c index 5da0e806..6c27c3dc 100644 --- a/sysdeps/linux/proctime.c +++ b/sysdeps/linux/proctime.c @@ -122,11 +122,12 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid) p = skip_multiple_token (p, 3); - for (i = 0; i < GLIBTOP_NCPU; i++) { - if (strncmp (p+1, "cpu", 3) || !isdigit (p [4])) + for (i = 0; i <= server->ncpu; i++) { + + if (!check_cpu_line_warn(server, p + 1, i)) break; - p += 6; + p = skip_token(p); buf->xcpu_utime [i] = strtoull (p, &p, 0); buf->xcpu_stime [i] = strtoull (p, &p, 0); } |