Huge (k)FreeBSD update. (k)FreeBSD support is freebsd/ Other BSD are in
2007-02-18 Benoît Dejean <benoit@placenet.org> * configure.in: * libgtop-sysdeps.m4: * sysdeps/Makefile.am: Huge (k)FreeBSD update. (k)FreeBSD support is freebsd/ Other BSD are in bsd/ Patch by Joe Marcus Clarke <marcus@freebsd.org> Alexander Nedotsukov <bland@FreeBSD.org> Closes #407693. svn path=/trunk/; revision=2557
This commit is contained in:
committed by
Benoît Dejean
parent
747438e334
commit
5a15e409cf
@@ -28,19 +28,23 @@
|
||||
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
#include <glibtop_suid.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_uptime =
|
||||
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
|
||||
(1L << GLIBTOP_UPTIME_UPTIME);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_idletime =
|
||||
(1L << GLIBTOP_UPTIME_IDLETIME);
|
||||
|
||||
static const unsigned long _required_cpu_flags =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_IDLE) +
|
||||
(1L << GLIBTOP_CPU_IDLE) +
|
||||
(1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_uptime_p (glibtop *server)
|
||||
glibtop_init_uptime_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||
}
|
||||
@@ -48,14 +52,17 @@ glibtop_init_uptime_p (glibtop *server)
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
void
|
||||
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
time_t now;
|
||||
time_t uptime;
|
||||
int mib[2];
|
||||
struct timeval boottime;
|
||||
size_t size;
|
||||
glibtop_cpu cpu;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_BOOTTIME;
|
||||
@@ -64,20 +71,10 @@ glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
||||
boottime.tv_sec != 0) {
|
||||
time(&now);
|
||||
buf->uptime = now - boottime.tv_sec;
|
||||
/* XXX: don't know a useful value to put here. */
|
||||
buf->idletime = 0;
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
}
|
||||
#else
|
||||
glibtop_cpu cpu;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_UPTIME), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
/* We simply calculate it from the CPU usage. */
|
||||
|
||||
glibtop_get_cpu_p (server, &cpu);
|
||||
glibtop_get_cpu_s (server, &cpu);
|
||||
|
||||
/* Make sure all required fields are present. */
|
||||
|
||||
@@ -86,9 +83,8 @@ glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
||||
|
||||
/* Calculate values. */
|
||||
|
||||
buf->uptime = (double) cpu.total / (double) cpu.frequency;
|
||||
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
|
||||
buf->idletime /= (double) (server->ncpu + 1);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
#endif
|
||||
buf->flags |= _glibtop_sysdeps_idletime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user