1998-08-12 Martin Baulig <martin@home-of-linux.org> * features: New directory. * gnome-hackers.sgml: Updated documentation.
41 lines
1004 B
Plaintext
41 lines
1004 B
Plaintext
#include <glibtop.h>
|
|
#include <glibtop/error.h>
|
|
#include <glibtop/uptime.h>
|
|
|
|
#include <glibtop/cpu.h>
|
|
|
|
#include <glibtop_suid.h>
|
|
|
|
static const unsigned long _glibtop_sysdeps_uptime =
|
|
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
|
|
|
|
static const unsigned long _required_cpu_flags =
|
|
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_IDLE) +
|
|
(1 << GLIBTOP_CPU_FREQUENCY);
|
|
|
|
void
|
|
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
|
{
|
|
glibtop_cpu cpu;
|
|
|
|
glibtop_init_p (server, GLIBTOP_SYSDEPS_UPTIME, 0);
|
|
|
|
memset (buf, 0, sizeof (glibtop_uptime));
|
|
|
|
/* We simply calculate it from the CPU usage. */
|
|
|
|
glibtop_get_cpu_p (server, &cpu);
|
|
|
|
/* Make sure all required fields are present. */
|
|
|
|
if ((cpu.flags & _required_cpu_flags) != _required_cpu_flags)
|
|
return;
|
|
|
|
/* Calculate values. */
|
|
|
|
buf->uptime = (double) cpu.total / (double) cpu.frequency;
|
|
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
|
|
|
|
buf->flags = _glibtop_sysdeps_uptime;
|
|
}
|