Added first kstat based implementation for Solaris 7.
1999-03-19 Martin Baulig <martin@home-of-linux.org> Added first kstat based implementation for Solaris 7. * open.c (glibtop_open_s): Walk kstat list and save interesting kstats in the `server->machine'. * cpu.c: This can already provide `idle', `user' and `sys' with full SMP support. * swap.c: This can already provide `total', `used' and `free'.
This commit is contained in:
committed by
Martin Baulig
parent
dfc9e912b5
commit
5fcfc95280
@@ -1,3 +1,15 @@
|
||||
1999-03-19 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Added first kstat based implementation for Solaris 7.
|
||||
|
||||
* open.c (glibtop_open_s): Walk kstat list and save interesting
|
||||
kstats in the `server->machine'.
|
||||
|
||||
* cpu.c: This can already provide `idle', `user' and `sys' with
|
||||
full SMP support.
|
||||
|
||||
* swap.c: This can already provide `total', `used' and `free'.
|
||||
|
||||
1999-03-17 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Initial import of my Solaris 7 port.
|
||||
|
@@ -22,16 +22,21 @@
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu = 0;
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
|
||||
(1 << GLIBTOP_CPU_SYS) + (1 << GLIBTOP_CPU_IDLE) +
|
||||
(1 << GLIBTOP_XCPU_TOTAL) + (1 << GLIBTOP_XCPU_USER) +
|
||||
(1 << GLIBTOP_XCPU_SYS) + (1 << GLIBTOP_XCPU_IDLE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_cpu_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
@@ -39,5 +44,40 @@ glibtop_init_cpu_s (glibtop *server)
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
kstat_ctl_t *kc = server->machine.kc;
|
||||
cpu_stat_t cpu_stat;
|
||||
int cpu, ncpu;
|
||||
kid_t ret;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
ncpu = server->ncpu;
|
||||
if (ncpu > GLIBTOP_NCPU) ncpu = GLIBTOP_NCPU;
|
||||
|
||||
for (cpu = 0; cpu < ncpu; cpu++) {
|
||||
kstat_t *ksp = server->machine.cpu_stat_kstat [cpu];
|
||||
if (!ksp) continue;
|
||||
|
||||
ret = kstat_read (kc, ksp, &cpu_stat);
|
||||
|
||||
if (ret == -1) {
|
||||
glibtop_warn_io_r (server, "kstat_read (cpu_stat%d)", cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
buf->xcpu_idle [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->xcpu_user [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->xcpu_sys [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
|
||||
buf->xcpu_total [cpu] = buf->xcpu_idle [cpu] + buf->xcpu_user [cpu] +
|
||||
buf->xcpu_sys [cpu];
|
||||
|
||||
buf->idle += cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->user += cpu_stat.cpu_sysinfo.cpu [CPU_USER];
|
||||
buf->sys += cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
|
||||
}
|
||||
|
||||
buf->total = buf->idle + buf->user + buf->sys;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
}
|
||||
|
@@ -26,19 +26,27 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <procfs.h>
|
||||
#include <kstat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <kstat.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
typedef struct _glibtop_machine glibtop_machine;
|
||||
|
||||
struct _glibtop_machine
|
||||
{
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid;
|
||||
uid_t uid, euid;
|
||||
gid_t gid, egid;
|
||||
|
||||
kstat_ctl_t *kstat;
|
||||
kstat_ctl_t *kc;
|
||||
|
||||
kstat_t *vminfo_kstat;
|
||||
hrtime_t vminfo_snaptime;
|
||||
vminfo_t vminfo;
|
||||
|
||||
kstat_t *cpu_stat_kstat [64];
|
||||
};
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
@@ -29,10 +29,37 @@ void
|
||||
glibtop_open_s (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
server->name = program_name;
|
||||
kstat_t *ksp;
|
||||
|
||||
server->machine.kstat = kstat_open ();
|
||||
server->name = program_name;
|
||||
|
||||
if (!server->machine.kstat)
|
||||
glibtop_error_io_r (server, "kstat_open ()");
|
||||
server->machine.kc = kstat_open ();
|
||||
|
||||
for (ksp = server->machine.kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
|
||||
if (!strcmp (ksp->ks_class, "vm") && !strcmp (ksp->ks_name, "vminfo")) {
|
||||
server->machine.vminfo_kstat = ksp;
|
||||
kstat_read (server->machine.kc, ksp, &server->machine.vminfo);
|
||||
server->machine.vminfo_snaptime = ksp->ks_snaptime;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp (ksp->ks_class, "misc") && !strncmp (ksp->ks_name, "cpu_stat", 8)) {
|
||||
int cpu;
|
||||
|
||||
if ((sscanf (ksp->ks_name+8, "%d", &cpu) != 1) || (cpu > 63))
|
||||
continue;
|
||||
|
||||
if (cpu >= server->ncpu)
|
||||
server->ncpu = cpu+1;
|
||||
|
||||
server->machine.cpu_stat_kstat [cpu] = ksp;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!server->machine.kc)
|
||||
glibtop_error_io_r (server, "kstat_open ()");
|
||||
|
||||
fprintf (stderr, "Sleeping 2 seconds, please wait ...\n");
|
||||
sleep (2);
|
||||
}
|
||||
|
@@ -22,16 +22,21 @@
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/swap.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap = 0;
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap =
|
||||
(1 << GLIBTOP_SWAP_TOTAL) + (1 << GLIBTOP_SWAP_USED) +
|
||||
(1 << GLIBTOP_SWAP_FREE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_swap_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap;
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap;
|
||||
}
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
@@ -39,5 +44,37 @@ glibtop_init_swap_s (glibtop *server)
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
kstat_ctl_t *kc = server->machine.kc;
|
||||
kstat_t *ksp = server->machine.vminfo_kstat;
|
||||
u_int64_t swap_resv, swap_alloc, swap_avail, swap_free;
|
||||
vminfo_t vminfo;
|
||||
double rate;
|
||||
kid_t ret;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
if (!ksp) return;
|
||||
|
||||
ret = kstat_read (kc, ksp, &vminfo);
|
||||
|
||||
if (ret == -1) {
|
||||
glibtop_warn_io_r (server, "kstat_read (vminfo)");
|
||||
return;
|
||||
}
|
||||
|
||||
rate = (ksp->ks_snaptime - server->machine.vminfo_snaptime) / 1E+9;
|
||||
|
||||
swap_resv = (vminfo.swap_resv - server->machine.vminfo.swap_resv) / rate;
|
||||
swap_alloc = (vminfo.swap_alloc - server->machine.vminfo.swap_alloc) / rate;
|
||||
swap_avail = (vminfo.swap_avail - server->machine.vminfo.swap_avail) / rate;
|
||||
swap_free = (vminfo.swap_free - server->machine.vminfo.swap_free) / rate;
|
||||
|
||||
memcpy (&server->machine.vminfo, &vminfo, sizeof (vminfo_t));
|
||||
server->machine.vminfo_snaptime = ksp->ks_snaptime;
|
||||
|
||||
buf->total = swap_resv + swap_avail;
|
||||
buf->used = swap_alloc;
|
||||
buf->free = buf->total - buf->used;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
}
|
||||
|
Reference in New Issue
Block a user