Added implementation.

This commit is contained in:
Martin Baulig
1999-03-21 19:08:59 +00:00
parent b90d2c1c90
commit a429e9c3f9
11 changed files with 351 additions and 38 deletions

View File

@@ -9,9 +9,9 @@ libgtop_sysdeps_la_SOURCES = open.c close.c siglist.c cpu.c mem.c swap.c \
sem_limits.c proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c procargs.c procmap.c netload.c \
ppp.c
ppp.c procdata.c
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO)
include_HEADERS = glibtop_server.h
include_HEADERS = glibtop_server.h glibtop_private.h

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -24,14 +24,27 @@
#include <glibtop.h>
#include <glibtop/cpu.h>
static const unsigned long _glibtop_sysdeps_cpu = 0;
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_TOTAL) + (1 << GLIBTOP_CPU_USER) +
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
static const unsigned long _glibtop_sysdeps_cpu_smp =
(1 << GLIBTOP_XCPU_TOTAL) + (1 << GLIBTOP_XCPU_USER) +
(1 << GLIBTOP_XCPU_NICE) + (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;
if (server->ncpu)
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
}
/* Provides information about cpu usage. */
@@ -39,5 +52,35 @@ glibtop_init_cpu_s (glibtop *server)
void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
memset (buf, 0, sizeof (glibtop_cpu));
libgtop_stat_t stat;
int i;
memset (buf, 0, sizeof (glibtop_cpu));
if (glibtop_get_proc_data_stat_s (server, &stat))
return;
buf->user = stat.cpu.user;
buf->nice = stat.cpu.nice;
buf->sys = stat.cpu.sys;
buf->idle = stat.cpu.idle;
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
buf->frequency = stat.frequency;
buf->flags = _glibtop_sysdeps_cpu;
if (stat.ncpu) {
for (i = 0; i < GLIBTOP_NCPU; i++) {
buf->xcpu_user [i] = stat.xcpu [i].user;
buf->xcpu_nice [i] = stat.xcpu [i].nice;
buf->xcpu_sys [i] = stat.xcpu [i].sys;
buf->xcpu_idle [i] = stat.xcpu [i].idle;
buf->xcpu_total [i] = buf->xcpu_user [i] + buf->xcpu_nice [i] +
buf->xcpu_sys [i] + buf->xcpu_idle [i];
}
buf->flags |= _glibtop_sysdeps_cpu_smp;
}
}

View File

@@ -0,0 +1,44 @@
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
LibGTop is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LibGTop; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __GLIBTOP_PRIVATE_H__
#define __GLIBTOP_PRIVATE_H__
#include <glibtop.h>
#include <glibtop/error.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#undef LIBGTOP_VERSION
#include <linux/libgtop.h>
BEGIN_LIBGTOP_DECLS
int glibtop_get_proc_data_stat_s (glibtop *server, libgtop_stat_t *stat);
int glibtop_get_proc_data_mem_s (glibtop *server, libgtop_mem_t *mem);
int glibtop_get_proc_data_swap_s (glibtop *server, libgtop_swap_t *swap);
END_LIBGTOP_DECLS
#endif __GLIBTOP_PRIVATE_H__

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -24,14 +24,17 @@
#include <glibtop.h>
#include <glibtop/loadavg.h>
static const unsigned long _glibtop_sysdeps_loadavg = 0;
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG);
/* Init function. */
void
glibtop_init_loadavg_s (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
}
/* Provides load averange. */
@@ -39,5 +42,16 @@ glibtop_init_loadavg_s (glibtop *server)
void
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
memset (buf, 0, sizeof (glibtop_loadavg));
libgtop_stat_t stat;
memset (buf, 0, sizeof (glibtop_loadavg));
if (glibtop_get_proc_data_stat_s (server, &stat))
return;
buf->loadavg [0] = stat.loadavg [0];
buf->loadavg [1] = stat.loadavg [1];
buf->loadavg [2] = stat.loadavg [2];
buf->flags = _glibtop_sysdeps_loadavg;
}

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -24,14 +24,19 @@
#include <glibtop.h>
#include <glibtop/mem.h>
static const unsigned long _glibtop_sysdeps_mem = 0;
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_TOTAL) + (1 << GLIBTOP_MEM_USED) +
(1 << GLIBTOP_MEM_FREE) + (1 << GLIBTOP_MEM_SHARED) +
(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED);
/* Init function. */
void
glibtop_init_mem_s (glibtop *server)
{
server->sysdeps.mem = _glibtop_sysdeps_mem;
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
/* Provides information about memory usage. */
@@ -39,5 +44,19 @@ glibtop_init_mem_s (glibtop *server)
void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
memset (buf, 0, sizeof (glibtop_mem));
libgtop_mem_t mem;
memset (buf, 0, sizeof (glibtop_mem));
if (glibtop_get_proc_data_mem_s (server, &mem))
return;
buf->total = mem.totalram;
buf->used = mem.totalram - mem.freeram;
buf->free = mem.freeram;
buf->shared = mem.sharedram;
buf->buffer = mem.bufferram;
buf->cached = mem.cachedram;
buf->flags = _glibtop_sysdeps_mem;
}

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -21,17 +21,23 @@
Boston, MA 02111-1307, USA.
*/
#include <glibtop.h>
#include <glibtop/msg_limits.h>
static const unsigned long _glibtop_sysdeps_msg_limits = 0;
#include <sys/ipc.h>
#include <sys/msg.h>
static const unsigned long _glibtop_sysdeps_msg_limits =
(1 << GLIBTOP_IPC_MSGPOOL) + (1 << GLIBTOP_IPC_MSGMAP) +
(1 << GLIBTOP_IPC_MSGMAX) + (1 << GLIBTOP_IPC_MSGMNB) +
(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
(1 << GLIBTOP_IPC_MSGTQL);
/* Init function. */
void
glibtop_init_msg_limits_s (glibtop *server)
{
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
}
/* Provides information about sysv ipc limits. */
@@ -39,5 +45,21 @@ glibtop_init_msg_limits_s (glibtop *server)
void
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
memset (buf, 0, sizeof (glibtop_msg_limits));
struct msginfo msginfo;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_msg_limits));
buf->flags = _glibtop_sysdeps_msg_limits;
msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
buf->msgpool = msginfo.msgpool;
buf->msgmap = msginfo.msgmap;
buf->msgmax = msginfo.msgmax;
buf->msgmnb = msginfo.msgmnb;
buf->msgmni = msginfo.msgmni;
buf->msgssz = msginfo.msgssz;
buf->msgtql = msginfo.msgtql;
}

67
sysdeps/kernel/procdata.c Normal file
View File

@@ -0,0 +1,67 @@
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
LibGTop is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LibGTop; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <glibtop.h>
#include <glibtop_private.h>
int
glibtop_get_proc_data_stat_s (glibtop *server, libgtop_stat_t *stat)
{
int name [2] = { CTL_LIBGTOP, LIBGTOP_STAT };
size_t size = sizeof (libgtop_stat_t);
if (sysctl (name, 2, stat, &size, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (libgtop/stat)");
return -1;
}
return 0;
}
int
glibtop_get_proc_data_mem_s (glibtop *server, libgtop_mem_t *mem)
{
int name [2] = { CTL_LIBGTOP, LIBGTOP_MEM };
size_t size = sizeof (libgtop_mem_t);
if (sysctl (name, 2, mem, &size, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (libgtop/mem)");
return -1;
}
return 0;
}
int
glibtop_get_proc_data_swap_s (glibtop *server, libgtop_swap_t *swap)
{
int name [2] = { CTL_LIBGTOP, LIBGTOP_SWAP };
size_t size = sizeof (libgtop_swap_t);
if (sysctl (name, 2, swap, &size, NULL, 0)) {
glibtop_warn_io_r (server, "sysctl (libgtop/swap)");
return -1;
}
return 0;
}

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -21,23 +21,66 @@
Boston, MA 02111-1307, USA.
*/
#include <glibtop.h>
#include <glibtop/sem_limits.h>
static const unsigned long _glibtop_sysdeps_sem_limits = 0;
#include <sys/ipc.h>
#include <sys/sem.h>
#ifdef _SEM_SEMUN_UNDEFINED
/* glibc 2.1 will no longer defines semun, instead it defines
* _SEM_SEMUN_UNDEFINED so users can define semun on their own.
* Thanks to Albert K T Hui <avatar@deva.net>. */
union semun
{
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
};
#endif
static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
(1 << GLIBTOP_IPC_SEMMSL) + (1 << GLIBTOP_IPC_SEMOPM) +
(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
(1 << GLIBTOP_IPC_SEMVMX) + (1 << GLIBTOP_IPC_SEMAEM);
/* Init function. */
void
glibtop_init_sem_limits_s (glibtop *server)
{
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
}
/* Provides information about sysv sem limits. */
/* Provides information about sysv ipc limits. */
void
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
{
memset (buf, 0, sizeof (glibtop_sem_limits));
struct seminfo seminfo;
union semun arg;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_sem_limits));
buf->flags = _glibtop_sysdeps_sem_limits;
arg.array = (ushort *) &seminfo;
semctl (0, 0, IPC_INFO, arg);
buf->semmap = seminfo.semmap;
buf->semmni = seminfo.semmni;
buf->semmns = seminfo.semmns;
buf->semmnu = seminfo.semmnu;
buf->semmsl = seminfo.semmsl;
buf->semopm = seminfo.semopm;
buf->semume = seminfo.semume;
buf->semusz = seminfo.semusz;
buf->semvmx = seminfo.semvmx;
buf->semaem = seminfo.semaem;
}

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -21,17 +21,22 @@
Boston, MA 02111-1307, USA.
*/
#include <glibtop.h>
#include <glibtop/shm_limits.h>
static const unsigned long _glibtop_sysdeps_shm_limits = 0;
#include <sys/ipc.h>
#include <sys/shm.h>
static unsigned long _glibtop_sysdeps_shm_limits =
(1 << GLIBTOP_IPC_SHMMAX) + (1 << GLIBTOP_IPC_SHMMIN) +
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
(1 << GLIBTOP_IPC_SHMALL);
/* Init function. */
void
glibtop_init_shm_limits_s (glibtop *server)
{
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
}
/* Provides information about sysv ipc limits. */
@@ -39,5 +44,19 @@ glibtop_init_shm_limits_s (glibtop *server)
void
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{
memset (buf, 0, sizeof (glibtop_shm_limits));
struct shminfo shminfo;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_shm_limits));
buf->flags = _glibtop_sysdeps_shm_limits;
shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
buf->shmmax = shminfo.shmmax;
buf->shmmin = shminfo.shmmin;
buf->shmmni = shminfo.shmmni;
buf->shmseg = shminfo.shmseg;
buf->shmall = shminfo.shmall;
}

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -24,14 +24,22 @@
#include <glibtop.h>
#include <glibtop/swap.h>
static const unsigned long _glibtop_sysdeps_swap = 0;
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_swap =
(1 << GLIBTOP_SWAP_TOTAL) + (1 << GLIBTOP_SWAP_USED) +
(1 << GLIBTOP_SWAP_FREE);
static const unsigned long _glibtop_sysdeps_swap_stat =
(1 << GLIBTOP_SWAP_PAGEIN) + (1 << GLIBTOP_SWAP_PAGEOUT);
/* Init function. */
void
glibtop_init_swap_s (glibtop *server)
{
server->sysdeps.swap = _glibtop_sysdeps_swap;
server->sysdeps.swap = _glibtop_sysdeps_swap |
_glibtop_sysdeps_swap_stat;
}
/* Provides information about swap usage. */
@@ -39,5 +47,25 @@ glibtop_init_swap_s (glibtop *server)
void
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{
memset (buf, 0, sizeof (glibtop_swap));
libgtop_stat_t stat;
libgtop_swap_t swap;
memset (buf, 0, sizeof (glibtop_swap));
if (glibtop_get_proc_data_swap_s (server, &swap))
return;
buf->total = swap.totalswap;
buf->free = swap.freeswap;
buf->used = swap.totalswap - swap.freeswap;
buf->flags = _glibtop_sysdeps_swap;
if (glibtop_get_proc_data_stat_s (server, &stat))
return;
buf->pagein = stat.pswpin;
buf->pageout = stat.pswpout;
buf->flags |= _glibtop_sysdeps_swap_stat;
}

View File

@@ -3,7 +3,7 @@
/* Copyright (C) 1998-99 Martin Baulig
This file is part of LibGTop 1.0.
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Contributed by Martin Baulig <martin@home-of-linux.org>, March 1999.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -24,14 +24,17 @@
#include <glibtop.h>
#include <glibtop/uptime.h>
static const unsigned long _glibtop_sysdeps_uptime = 0;
#include <glibtop_private.h>
static unsigned long _glibtop_sysdeps_uptime =
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
/* Init function. */
void
glibtop_init_uptime_s (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
}
/* Provides uptime and idle time. */
@@ -39,5 +42,16 @@ glibtop_init_uptime_s (glibtop *server)
void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
memset (buf, 0, sizeof (glibtop_uptime));
libgtop_stat_t stat;
unsigned long total;
memset (buf, 0, sizeof (glibtop_uptime));
if (glibtop_get_proc_data_stat_s (server, &stat))
return;
total = stat.cpu.user + stat.cpu.nice + stat.cpu.sys + stat.cpu.idle;
buf->uptime = (double) total / (double) stat.frequency;
buf->idletime = (double) stat.cpu.idle / (double) stat.frequency;
}