Added test for end of string. (get_scaled): Cleaned.
* glibtop_server.h (skip_line): Added test for end of string. (get_scaled): Cleaned. * cpu.c (glibtop_get_cpu_s): * open.c (glibtop_open_s): Fixed SMP detection. Closes #142597. * uptime.c (glibtop_get_uptime_s): Added boot_time.
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
2004-05-19 Benoit Dejean <TazForEver@dlfp.org>
|
||||||
|
|
||||||
|
* glibtop_server.h (skip_line): Added test for end of string.
|
||||||
|
(get_scaled): Cleaned.
|
||||||
|
|
||||||
|
* cpu.c (glibtop_get_cpu_s):
|
||||||
|
* open.c (glibtop_open_s): Fixed SMP detection. Closes #142597.
|
||||||
|
|
||||||
|
* uptime.c (glibtop_get_uptime_s): Added boot_time.
|
||||||
|
|
||||||
2004-03-09 Bastien Nocera <hadess@hadess.net>
|
2004-03-09 Bastien Nocera <hadess@hadess.net>
|
||||||
|
|
||||||
* cpu.c: (glibtop_get_cpu_s): fixup CPU usage calculation on 2.6
|
* cpu.c: (glibtop_get_cpu_s): fixup CPU usage calculation on 2.6
|
||||||
|
@@ -54,8 +54,8 @@ void
|
|||||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p;
|
||||||
int fd, len, i;
|
int fd, len;
|
||||||
guint64 total;
|
guint i;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||||
|
|
||||||
@@ -73,6 +73,10 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
|||||||
|
|
||||||
buffer [len] = '\0';
|
buffer [len] = '\0';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GLOBAL
|
||||||
|
*/
|
||||||
|
|
||||||
p = skip_token (buffer); /* "cpu" */
|
p = skip_token (buffer); /* "cpu" */
|
||||||
|
|
||||||
buf->user = strtoull (p, &p, 0);
|
buf->user = strtoull (p, &p, 0);
|
||||||
@@ -85,20 +89,24 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
|||||||
buf->sys += strtoull(p, &p, 0); /* "irq" */
|
buf->sys += strtoull(p, &p, 0); /* "irq" */
|
||||||
buf->sys += strtoull(p, &p, 0); /* "softirq" */
|
buf->sys += strtoull(p, &p, 0); /* "softirq" */
|
||||||
|
|
||||||
total = buf->user;
|
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||||
total += buf->nice;
|
|
||||||
total += buf->sys;
|
|
||||||
total += buf->idle;
|
|
||||||
buf->total = total;
|
|
||||||
|
|
||||||
buf->frequency = 100;
|
buf->frequency = 100;
|
||||||
buf->flags = _glibtop_sysdeps_cpu;
|
buf->flags = _glibtop_sysdeps_cpu;
|
||||||
|
|
||||||
for (i = 0; i < server->ncpu; i++) {
|
/*
|
||||||
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
|
* PER CPU
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < GLIBTOP_NCPU && i < server->ncpu; i++) {
|
||||||
|
|
||||||
|
p = skip_line(p); /* move to ^ */
|
||||||
|
|
||||||
|
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
p += 6;
|
p = skip_token(p); /* "cpuN" */
|
||||||
|
|
||||||
buf->xcpu_user [i] = strtoull (p, &p, 0);
|
buf->xcpu_user [i] = strtoull (p, &p, 0);
|
||||||
buf->xcpu_nice [i] = strtoull (p, &p, 0);
|
buf->xcpu_nice [i] = strtoull (p, &p, 0);
|
||||||
buf->xcpu_sys [i] = strtoull (p, &p, 0);
|
buf->xcpu_sys [i] = strtoull (p, &p, 0);
|
||||||
@@ -109,13 +117,12 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
|||||||
buf->xcpu_sys [i] += strtoull(p, &p, 0); /* "irq" */
|
buf->xcpu_sys [i] += strtoull(p, &p, 0); /* "irq" */
|
||||||
buf->xcpu_sys [i] += strtoull(p, &p, 0); /* "softirq" */
|
buf->xcpu_sys [i] += strtoull(p, &p, 0); /* "softirq" */
|
||||||
|
|
||||||
total = buf->xcpu_user [i];
|
buf->xcpu_total[i] = buf->xcpu_user [i] \
|
||||||
total += buf->xcpu_nice [i];
|
+ buf->xcpu_nice [i] \
|
||||||
total += buf->xcpu_sys [i];
|
+ buf->xcpu_sys [i] \
|
||||||
total += buf->xcpu_idle [i];
|
+ buf->xcpu_idle [i];
|
||||||
|
|
||||||
buf->xcpu_total [i] = total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->flags |= _glibtop_sysdeps_cpu_smp;
|
if(i >= 2) /* ok, that's a real SMP */
|
||||||
|
buf->flags |= _glibtop_sysdeps_cpu_smp;
|
||||||
}
|
}
|
||||||
|
@@ -53,8 +53,8 @@ skip_multiple_token (const char *p, int count)
|
|||||||
static inline char *
|
static inline char *
|
||||||
skip_line (const char *p)
|
skip_line (const char *p)
|
||||||
{
|
{
|
||||||
while (*p != '\n') p++;
|
while (*p && *p != '\n') p++;
|
||||||
return (char *) ++p;
|
return (char *) (*p ? p+1 : p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned long long
|
static inline unsigned long long
|
||||||
@@ -62,11 +62,12 @@ get_scaled(const char *buffer, const char *key)
|
|||||||
{
|
{
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
char *next;
|
char *next;
|
||||||
|
const size_t len = strlen(key);
|
||||||
unsigned long long value = 0;
|
unsigned long long value = 0;
|
||||||
|
|
||||||
if ((ptr = strstr(buffer, key)))
|
if ((ptr = strstr(buffer, key)))
|
||||||
{
|
{
|
||||||
ptr += strlen(key);
|
ptr += len;
|
||||||
value = strtoull(ptr, &next, 0);
|
value = strtoull(ptr, &next, 0);
|
||||||
if (strchr(next, 'k'))
|
if (strchr(next, 'k'))
|
||||||
value *= 1024;
|
value *= 1024;
|
||||||
|
@@ -61,24 +61,14 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
|||||||
const unsigned long features,
|
const unsigned long features,
|
||||||
const unsigned flags)
|
const unsigned flags)
|
||||||
{
|
{
|
||||||
char buffer [BUFSIZ], *p;
|
char buffer [BUFSIZ], *p = buffer;
|
||||||
struct stat statb;
|
int fd, len;
|
||||||
int fd, len, i;
|
|
||||||
|
|
||||||
server->name = program_name;
|
server->name = program_name;
|
||||||
|
|
||||||
set_linux_version ();
|
set_linux_version ();
|
||||||
server->os_version_code = (unsigned long) linux_version_code;
|
server->os_version_code = (unsigned long) linux_version_code;
|
||||||
|
|
||||||
server->ncpu = 0;
|
|
||||||
|
|
||||||
/* On Linux 2.4.x, /proc/stat has "cpu" and "cpu0" entries even
|
|
||||||
* for non-SMP systems. Checking whether /proc/<pid>/cpu exists
|
|
||||||
* is a much better way to detect SMP. */
|
|
||||||
|
|
||||||
if (stat ("/proc/1/cpu", &statb))
|
|
||||||
return;
|
|
||||||
|
|
||||||
fd = open (FILENAME, O_RDONLY);
|
fd = open (FILENAME, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
glibtop_error_io_r (server, "open (%s)", FILENAME);
|
glibtop_error_io_r (server, "open (%s)", FILENAME);
|
||||||
@@ -90,17 +80,13 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
|||||||
close (fd);
|
close (fd);
|
||||||
|
|
||||||
buffer [len] = '\0';
|
buffer [len] = '\0';
|
||||||
|
|
||||||
p = skip_multiple_token (buffer, 5) + 1;
|
for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) {
|
||||||
|
|
||||||
for (i = 0; i < GLIBTOP_NCPU; i++) {
|
p = skip_line(p);
|
||||||
|
|
||||||
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
|
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
server->ncpu++;
|
|
||||||
|
|
||||||
p = skip_multiple_token (p, 5) + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <glibtop/error.h>
|
#include <glibtop/error.h>
|
||||||
#include <glibtop/uptime.h>
|
#include <glibtop/uptime.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
static unsigned long _glibtop_sysdeps_uptime =
|
static unsigned long _glibtop_sysdeps_uptime =
|
||||||
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
|
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
|
||||||
@@ -64,6 +65,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
|||||||
|
|
||||||
buf->uptime = strtod (buffer, &p);
|
buf->uptime = strtod (buffer, &p);
|
||||||
buf->idletime = strtod (p, &p);
|
buf->idletime = strtod (p, &p);
|
||||||
|
buf->boot_time = (guint64) time(NULL) - (guint64) buf->uptime;
|
||||||
|
|
||||||
buf->flags = _glibtop_sysdeps_uptime;
|
buf->flags = _glibtop_sysdeps_uptime;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user