|
Packit Service |
407539 |
/* Copyright (C) 1998-99 Martin Baulig
|
|
Packit Service |
407539 |
This file is part of LibGTop 1.0.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is free software; you can redistribute it and/or modify it
|
|
Packit Service |
407539 |
under the terms of the GNU General Public License as published by
|
|
Packit Service |
407539 |
the Free Software Foundation; either version 2 of the License,
|
|
Packit Service |
407539 |
or (at your option) any later version.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
407539 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit Service |
407539 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
Packit Service |
407539 |
for more details.
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
407539 |
along with LibGTop; see the file COPYING. If not, write to the
|
|
Packit Service |
407539 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit Service |
407539 |
Boston, MA 02110-1301, USA.
|
|
Packit Service |
407539 |
*/
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <config.h>
|
|
Packit Service |
407539 |
#include <glibtop.h>
|
|
Packit Service |
407539 |
#include <glibtop/cpu.h>
|
|
Packit Service |
407539 |
#include <glibtop/uptime.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <glibtop_suid.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
#include <time.h>
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
static const unsigned long _glibtop_sysdeps_uptime =
|
|
Packit Service |
407539 |
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Provides uptime and idle time. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
void
|
|
Packit Service |
407539 |
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
|
|
Packit Service |
407539 |
{
|
|
Packit Service |
407539 |
glibtop_cpu cpu;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_UPTIME), 0);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Get currect cpu usage. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
glibtop_get_cpu_p (server, &cpu);
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Make sure all required fields are present. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
if (((cpu.flags & (1 << GLIBTOP_CPU_TOTAL)) == 0) ||
|
|
Packit Service |
407539 |
((cpu.flags & (1 << GLIBTOP_CPU_IDLE)) == 0) ||
|
|
Packit Service |
407539 |
((cpu.flags & (1 << GLIBTOP_CPU_FREQUENCY)) == 0) ||
|
|
Packit Service |
407539 |
(cpu.frequency == 0))
|
|
Packit Service |
407539 |
return;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
/* Simply calculate uptime and idle time from
|
|
Packit Service |
407539 |
* cpu usage. */
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
buf->uptime = (double) cpu.total / (double) cpu.frequency;
|
|
Packit Service |
407539 |
buf->idletime = (double) cpu.idle / (double) cpu.frequency;
|
|
Packit Service |
407539 |
buf->boot_time = (guint64) time(NULL) - (guint64) buf->uptime;
|
|
Packit Service |
407539 |
|
|
Packit Service |
407539 |
buf->flags = _glibtop_sysdeps_uptime;
|
|
Packit Service |
407539 |
}
|