summaryrefslogtreecommitdiffstats
path: root/ksysguard/ksysguardd/Irix
diff options
context:
space:
mode:
Diffstat (limited to 'ksysguard/ksysguardd/Irix')
-rw-r--r--ksysguard/ksysguardd/Irix/LoadAvg.c78
-rw-r--r--ksysguard/ksysguardd/Irix/LoadAvg.h41
-rw-r--r--ksysguard/ksysguardd/Irix/Makefile.am4
-rw-r--r--ksysguard/ksysguardd/Irix/Memory.c128
-rw-r--r--ksysguard/ksysguardd/Irix/Memory.h46
-rw-r--r--ksysguard/ksysguardd/Irix/NetDev.c343
-rw-r--r--ksysguard/ksysguardd/Irix/NetDev.h35
-rw-r--r--ksysguard/ksysguardd/Irix/ProcessList.c462
-rw-r--r--ksysguard/ksysguardd/Irix/ProcessList.h43
-rw-r--r--ksysguard/ksysguardd/Irix/cpu.c262
-rw-r--r--ksysguard/ksysguardd/Irix/cpu.h43
11 files changed, 1485 insertions, 0 deletions
diff --git a/ksysguard/ksysguardd/Irix/LoadAvg.c b/ksysguard/ksysguardd/Irix/LoadAvg.c
new file mode 100644
index 000000000..92d284756
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/LoadAvg.c
@@ -0,0 +1,78 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Irix support by Carsten Kroll <CKroll@pinnaclesys.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/swap.h>
+
+#include "config.h"
+
+#include "ksysguardd.h"
+#include "Command.h"
+#include "LoadAvg.h"
+
+double loadavg1 = 0.0;
+double loadavg5 = 0.0;
+double loadavg15 = 0.0;
+
+void initLoadAvg(struct SensorModul* sm ) {
+ registerMonitor( "cpu/loadavg1", "float",
+ printLoadAvg1, printLoadAvg1Info, sm );
+ registerMonitor( "cpu/loadavg5", "float",
+ printLoadAvg5, printLoadAvg5Info, sm );
+ registerMonitor( "cpu/loadavg15", "float",
+ printLoadAvg15, printLoadAvg15Info, sm );
+}
+
+void exitLoadAvg( void ) {
+}
+
+int updateLoadAvg( void ) {
+
+ return( 0 );
+}
+
+void printLoadAvg1Info( const char *cmd ) {
+ fprintf(CurrentClient, "avnrun 1min\t0\t0\n" );
+}
+
+void printLoadAvg1( const char *cmd ) {
+ fprintf(CurrentClient, "%f\n", loadavg1 );
+}
+
+void printLoadAvg5Info( const char *cmd ) {
+ fprintf(CurrentClient, "avnrun 5min\t0\t0\n" );
+}
+
+void printLoadAvg5( const char *cmd ) {
+ fprintf(CurrentClient, "%f\n", loadavg5 );
+}
+
+void printLoadAvg15Info( const char *cmd ) {
+ fprintf(CurrentClient, "avnrun 15min\t0\t0\n" );
+}
+
+void printLoadAvg15( const char *cmd ) {
+ fprintf(CurrentClient, "%f\n", loadavg15 );
+}
diff --git a/ksysguard/ksysguardd/Irix/LoadAvg.h b/ksysguard/ksysguardd/Irix/LoadAvg.h
new file mode 100644
index 000000000..eea8ad82e
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/LoadAvg.h
@@ -0,0 +1,41 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _LoadAvg_h_
+#define _LoadAvg_h_
+
+#define LOAD(a) ((double)(a) / (1 << 8 ))
+
+void initLoadAvg(struct SensorModul* sm);
+void exitLoadAvg(void);
+
+int updateLoadAvg(void);
+
+void printLoadAvg1( const char *cmd );
+void printLoadAvg1Info( const char *cmd );
+void printLoadAvg5( const char *cmd );
+void printLoadAvg5Info( const char *cmd );
+void printLoadAvg15( const char *cmd );
+void printLoadAvg15Info( const char *cmd );
+
+#endif /* _LoadAvg_h_ */
diff --git a/ksysguard/ksysguardd/Irix/Makefile.am b/ksysguard/ksysguardd/Irix/Makefile.am
new file mode 100644
index 000000000..3c1997924
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/Makefile.am
@@ -0,0 +1,4 @@
+INCLUDES = -I$(srcdir)/../../CContLib -I..
+
+noinst_LIBRARIES = libksysguardd.a
+libksysguardd_a_SOURCES = Memory.c LoadAvg.c ProcessList.c NetDev.c cpu.c
diff --git a/ksysguard/ksysguardd/Irix/Memory.c b/ksysguard/ksysguardd/Irix/Memory.c
new file mode 100644
index 000000000..e88123ddd
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/Memory.c
@@ -0,0 +1,128 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/statfs.h>
+#include <sys/swap.h>
+#include <sys/sysmp.h>
+
+#include "config.h"
+
+#include "ksysguardd.h"
+#include "Command.h"
+#include "Memory.h"
+
+static int Dirty = 1;
+static t_memsize totalmem = (t_memsize) 0;
+static t_memsize freemem = (t_memsize) 0;
+static unsigned long totalswap = 0L,vswap = 0L;
+static unsigned long freeswap = 0L,bufmem = 0L ;
+
+void initMemory( struct SensorModul* sm ) {
+
+ registerMonitor( "mem/physical/free", "integer",
+ printMemFree, printMemFreeInfo, sm );
+ registerMonitor( "mem/physical/used", "integer",
+ printMemUsed, printMemUsedInfo, sm );
+ registerMonitor( "mem/swap/free", "integer",
+ printSwapFree, printSwapFreeInfo, sm );
+ registerMonitor( "mem/swap/used", "integer",
+ printSwapUsed, printSwapUsedInfo, sm );
+}
+
+void exitMemory( void ) {
+}
+
+int updateMemory( void ) {
+ struct statfs sf;
+ off_t val;
+ int pagesize = getpagesize();
+ struct rminfo rmi;
+ if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 )
+ return( -1 );
+ totalmem = rmi.physmem*pagesize/1024; // total physical memory (without swaps)
+ freemem = rmi.freemem*pagesize/1024; // total free physical memory (without swaps)
+ bufmem = rmi.bufmem *pagesize/1024;
+
+ statfs ("/proc", &sf,sizeof(sf),0);
+
+ swapctl(SC_GETSWAPVIRT,&val);
+ vswap = val >> 1;
+ swapctl(SC_GETSWAPTOT,&val);
+ totalswap = val >> 1;
+ swapctl(SC_GETFREESWAP,&val);
+ freeswap = val >> 1;
+
+ Dirty = 1;
+
+ return( 0 );
+}
+
+void printMemFreeInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Free Memory\t0\t%ld\tKB\n", freemem );
+}
+
+void printMemFree( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", freemem );
+}
+
+void printMemUsedInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Used Memory\t0\t%ld\tKB\n", totalmem - freemem );
+}
+
+void printMemUsed( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", totalmem - freemem );
+}
+
+void printSwapFreeInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Free Swap\t0\t%ld\tKB\n", freeswap );
+}
+
+void printSwapFree( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", freeswap );
+}
+void printSwapUsedInfo( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "Used Swap\t0\t%ld\tKB\n", totalswap - freeswap );
+}
+
+void printSwapUsed( const char *cmd ) {
+ if( Dirty )
+ updateMemory();
+ fprintf(CurrentClient, "%ld\n", totalswap - freeswap );
+}
diff --git a/ksysguard/ksysguardd/Irix/Memory.h b/ksysguard/ksysguardd/Irix/Memory.h
new file mode 100644
index 000000000..ac3677b13
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/Memory.h
@@ -0,0 +1,46 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _Memory_h_
+#define _Memory_h_
+
+typedef unsigned long t_memsize;
+
+void initMemory(struct SensorModul* sm);
+void exitMemory(void);
+
+int updateMemory(void);
+
+void printMemFree( const char *cmd );
+void printMemFreeInfo( const char *cmd );
+void printMemUsed( const char *cmd );
+void printMemUsedInfo( const char *cmd );
+void printMemBuff( const char *cmd);
+void printMemBuffInfo( const char *cmd);
+
+void printSwapFree( const char *cmd );
+void printSwapFreeInfo( const char *cmd );
+void printSwapUsed( const char *cmd );
+void printSwapUsedInfo( const char *cmd );
+
+#endif /* _Memory_h */
diff --git a/ksysguard/ksysguardd/Irix/NetDev.c b/ksysguard/ksysguardd/Irix/NetDev.c
new file mode 100644
index 000000000..80bc2b310
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/NetDev.c
@@ -0,0 +1,343 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+ Irix Support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/soioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/sysctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <invent.h>
+#include <strings.h>
+
+
+#include "Command.h"
+#include "ksysguardd.h"
+#include "NetDev.h"
+
+#ifdef __GNUC__
+#define LONGLONG long long
+#endif
+
+typedef struct {
+ char name[IFNAMSIZ];
+ u_long recBytes;
+ u_long recPacks;
+ u_long recErrs;
+ u_long recDrop;
+ u_long recMulticast;
+ u_long sentBytes;
+ u_long sentPacks;
+ u_long sentErrs;
+ u_long sentMulticast;
+ u_long sentColls;
+} NetDevInfo;
+
+#define MAXNETDEVS 32
+static NetDevInfo NetDevs[MAXNETDEVS];
+static NetDevInfo oNetDevs[MAXNETDEVS];
+static int NetDevCnt = 0;
+
+char **parseCommand(const char *cmd)
+{
+ char *tmp_cmd = strdup(cmd);
+ char *begin;
+ char *retval = malloc(sizeof(char *)*2);
+
+ begin = rindex(tmp_cmd, '/');
+ *begin = '\0';
+ begin++;
+ retval[1] = strdup(begin); // sensor
+
+ begin = rindex(tmp_cmd, '/');
+ *begin = '\0';
+ begin = rindex(tmp_cmd, '/');
+ begin++;
+ retval[0] = strdup(begin); // interface
+ free(tmp_cmd);
+
+ return retval;
+}
+
+/* ------------------------------ public part --------------------------- */
+
+void initNetDev(struct SensorModul* sm)
+{
+ int i;
+ char monitor[1024];
+
+ memset(NetDevs,0,sizeof(NetDevInfo)*MAXNETDEVS);
+ memset(oNetDevs,0,sizeof(NetDevInfo)*MAXNETDEVS);
+
+ updateNetDev();
+
+ for (i = 0; i < NetDevCnt; i++) {
+
+ sprintf(monitor,"network/interfaces/%s/receiver/packets", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, sm);
+ sprintf(monitor ,"network/interfaces/%s/receiver/errors", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, sm);
+ /*
+ [CK] I don't know how to get Bytes sent/received, if someone does please drop me a note.
+ sprintf(monitor,"network/interfaces/%s/receiver/data", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, sm);
+ sprintf(monitor,"network/interfaces/%s/receiver/drops", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, sm);
+ sprintf(monitor ,"network/interfaces/%s/receiver/multicast", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, sm);
+ */
+
+ sprintf(monitor,"network/interfaces/%s/transmitter/packets", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, sm);
+ sprintf(monitor,"network/interfaces/%s/transmitter/errors", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, sm);
+ /*
+ sprintf(monitor,"network/interfaces/%s/transmitter/data", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, sm);
+ sprintf(monitor,"network/interfaces/%s/transmitter/multicast", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, sm);
+ */
+ sprintf(monitor,"network/interfaces/%s/transmitter/collisions", NetDevs[i].name);
+ registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, sm);
+ }
+}
+
+void exitNetDev(void)
+{
+ int i;
+ char monitor[1024];
+
+ for (i = 0; i < NetDevCnt; i++) {
+ sprintf(monitor,"network/interfaces/%s/receiver/packets", NetDevs[i].name);
+ removeMonitor(monitor);
+ sprintf(monitor,"network/interfaces/%s/receiver/errors", NetDevs[i].name);
+ removeMonitor(monitor);
+/*
+ sprintf(monitor,"network/interfaces/%s/receiver/drops", NetDevs[i].name);
+ removeMonitor(monitor);
+ sprintf(monitor,"network/interfaces/%s/receiver/multicast", NetDevs[i].name);
+ removeMonitor(monitor);
+ sprintf(monitor,"network/interfaces/%s/receiver/data", NetDevs[i].name);
+ removeMonitor(monitor);
+*/
+
+ sprintf(monitor,"network/interfaces/%s/transmitter/packets", NetDevs[i].name);
+ removeMonitor(monitor);
+ sprintf(monitor,"network/interfaces/%s/transmitter/errors", NetDevs[i].name);
+ removeMonitor(monitor);
+/*
+ sprintf(monitor,"network/interfaces/%s/transmitter/data", NetDevs[i].name);
+ removeMonitor(monitor);
+ sprintf(monitor,"network/interfaces/%s/transmitter/multicast", NetDevs[i].name);
+ removeMonitor(monitor);
+*/
+ sprintf(monitor,"network/interfaces/%s/transmitter/collisions", NetDevs[i].name);
+ removeMonitor(monitor);
+
+ }
+}
+
+int updateNetDev(void)
+{
+ int name[6];
+ int num_iface=0, i;
+ char buf[MAXNETDEVS*sizeof(struct ifreq)];
+ size_t len;
+ int s;
+ struct ifconf ifc;
+ struct ifstats *istat;
+ struct timeval tv;
+ static LONGLONG timestamp=0;
+ register LONGLONG cts,elapsed;
+ //struct ipstat ips;
+
+ if ((s=socket(PF_INET,SOCK_DGRAM,0)) < 0){
+ print_error("socket creation failed");
+ return(-1);
+ }
+
+ ifc.ifc_len = sizeof (buf);
+ ifc.ifc_buf = buf;
+ if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) {
+ print_error("cannot get interface configuration");
+ return(-1);
+ }
+
+ gettimeofday(&tv, 0);
+ cts = ((LONGLONG)tv.tv_sec * 100 + (LONGLONG) tv.tv_usec / 10000);/* in 10 ms unit*/
+ elapsed = cts - timestamp;
+ timestamp=cts;
+
+ NetDevCnt=0;
+
+ for (i = 0; i < MAXNETDEVS; i++) {
+ if ( *ifc.ifc_req[i].ifr_name == 0) break;
+ if (ioctl(s, SIOCGIFSTATS, &ifc.ifc_req[i]) < 0) {
+ print_error("cannot get interface statistics");
+ return (-1);
+ }
+ istat=&ifc.ifc_req[i].ifr_stats;
+ //if ( ifc.ifc_req[i].ifr_flags & IFF_UP) {
+ strncpy(NetDevs[i].name,ifc.ifc_req[i].ifr_name, IFNAMSIZ);
+ NetDevs[i].name[IFNAMSIZ-1]='\0';
+ NetDevs[i].recBytes = (istat->ifs_ipackets - oNetDevs[i].recBytes) * 100 / elapsed;
+ NetDevs[i].recPacks = (istat->ifs_ipackets - oNetDevs[i].recPacks) * 100 / elapsed;
+ NetDevs[i].recErrs = istat->ifs_ierrors - oNetDevs[i].recErrs;
+ //NetDevs[i].recDrop = istat - oNetDevs[i].recDrop;
+ //NetDevs[i].recMulticast = istat - oNetDevs[i].recMulticast;
+ NetDevs[i].sentBytes = istat->ifs_opackets - oNetDevs[i].sentBytes;
+ NetDevs[i].sentPacks = (istat->ifs_opackets - oNetDevs[i].sentPacks) * 100 / elapsed;
+ NetDevs[i].sentErrs = (istat->ifs_oerrors - oNetDevs[i].sentErrs) * 100 / elapsed;
+ //NetDevs[i].sentMulticast = istat - NetDevs[i].sentMulticast;
+ NetDevs[i].sentColls = (istat->ifs_collisions - oNetDevs[i].sentColls) *100/elapsed;
+ /* save it for the next round */
+ oNetDevs[i].recBytes = istat->ifs_ipackets;
+ oNetDevs[i].recPacks = istat->ifs_ipackets;
+ oNetDevs[i].recErrs = istat->ifs_ierrors;
+ //oNetDevs[i].recDrop =
+ //oNetDevs[i].recMulticast =
+ oNetDevs[i].sentBytes = istat->ifs_opackets;
+ oNetDevs[i].sentPacks = istat->ifs_opackets;
+ oNetDevs[i].sentErrs = istat->ifs_oerrors;
+ //oNetDevs[i].sentMulticast =
+ oNetDevs[i].sentColls = istat->ifs_collisions;
+ //}
+ NetDevCnt++;
+ }
+ close(s);
+ return (0);
+}
+
+void printNetDevRecBytes(const char *cmd)
+{
+ int i;
+ char **retval;
+
+ retval = parseCommand(cmd);
+
+ if (retval == NULL)
+ return;
+
+ for (i = 0; i < NetDevCnt; i++) {
+ if (!strcmp(NetDevs[i].name, retval[0])) {
+ if (!strncmp(retval[1], "data", 4))
+ fprintf(CurrentClient, "%lu", NetDevs[i].recBytes);
+ if (!strncmp(retval[1], "packets", 7))
+ fprintf(CurrentClient, "%lu", NetDevs[i].recPacks);
+ if (!strncmp(retval[1], "errors", 6))
+ fprintf(CurrentClient, "%lu", NetDevs[i].recErrs);
+ if (!strncmp(retval[1], "drops", 5))
+ fprintf(CurrentClient, "%lu", NetDevs[i].recDrop);
+ if (!strncmp(retval[1], "multicast", 9))
+ fprintf(CurrentClient, "%lu", NetDevs[i].recMulticast);
+ }
+ }
+ free(retval[0]);
+ free(retval[1]);
+ free(retval);
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printNetDevRecBytesInfo(const char *cmd)
+{
+ char **retval;
+
+ retval = parseCommand(cmd);
+
+ if (retval == NULL)
+ return;
+
+ if (!strncmp(retval[1], "data", 4))
+ fprintf(CurrentClient, "Received Data\t0\t0\tkBytes/s\n");
+ if (!strncmp(retval[1], "packets", 7))
+ fprintf(CurrentClient, "Received Packets\t0\t0\t1/s\n");
+ if (!strncmp(retval[1], "errors", 6))
+ fprintf(CurrentClient, "Receiver Errors\t0\t0\t1/s\n");
+ if (!strncmp(retval[1], "drops", 5))
+ fprintf(CurrentClient, "Receiver Drops\t0\t0\t1/s\n");
+ if (!strncmp(retval[1], "multicast", 9))
+ fprintf(CurrentClient, "Received Multicast Packets\t0\t0\t1/s\n");
+
+ free(retval[0]);
+ free(retval[1]);
+ free(retval);
+}
+
+void printNetDevSentBytes(const char *cmd)
+{
+ int i;
+ char **retval;
+
+ retval = parseCommand(cmd);
+
+ if (retval == NULL)
+ return;
+
+ for (i = 0; i < NetDevCnt; i++) {
+ if (!strcmp(NetDevs[i].name, retval[0])) {
+ if (!strncmp(retval[1], "data", 4))
+ fprintf(CurrentClient, "%lu", NetDevs[i].sentBytes);
+ if (!strncmp(retval[1], "packets", 7))
+ fprintf(CurrentClient, "%lu", NetDevs[i].sentPacks);
+ if (!strncmp(retval[1], "errors", 6))
+ fprintf(CurrentClient, "%lu", NetDevs[i].sentErrs);
+ if (!strncmp(retval[1], "multicast", 9))
+ fprintf(CurrentClient, "%lu", NetDevs[i].sentMulticast);
+ if (!strncmp(retval[1], "collisions", 10))
+ fprintf(CurrentClient, "%lu", NetDevs[i].sentColls);
+ }
+ }
+ free(retval[0]);
+ free(retval[1]);
+ free(retval);
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printNetDevSentBytesInfo(const char *cmd)
+{
+ char **retval;
+
+ retval = parseCommand(cmd);
+
+ if (retval == NULL)
+ return;
+
+ if (!strncmp(retval[1], "data", 4))
+ fprintf(CurrentClient, "Sent Data\t0\t0\tkBytes/s\n");
+ if (!strncmp(retval[1], "packets", 7))
+ fprintf(CurrentClient, "Sent Packets\t0\t0\t1/s\n");
+ if (!strncmp(retval[1], "errors", 6))
+ fprintf(CurrentClient, "Transmitter Errors\t0\t0\t1/s\n");
+ if (!strncmp(retval[1], "multicast", 9))
+ fprintf(CurrentClient, "Sent Multicast Packets\t0\t0\t1/s\n");
+ if (!strncmp(retval[1], "collisions", 10))
+ fprintf(CurrentClient, "Transmitter Collisions\t0\t0\t1/s\n");
+
+ free(retval[0]);
+ free(retval[1]);
+ free(retval);
+}
diff --git a/ksysguard/ksysguardd/Irix/NetDev.h b/ksysguard/ksysguardd/Irix/NetDev.h
new file mode 100644
index 000000000..aa30166e9
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/NetDev.h
@@ -0,0 +1,35 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2001 Tobias Koenig <tokoe@kde.org>
+ Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _netdev_h_
+#define _netdev_h_
+
+void initNetDev(struct SensorModul* sm);
+void exitNetDev(void);
+
+int updateNetDev(void);
+
+void printNetDevRecBytes(const char* cmd);
+void printNetDevRecBytesInfo(const char* cmd);
+void printNetDevSentBytes(const char* cmd);
+void printNetDevSentBytesInfo(const char* cmd);
+
+#endif
diff --git a/ksysguard/ksysguardd/Irix/ProcessList.c b/ksysguard/ksysguardd/Irix/ProcessList.c
new file mode 100644
index 000000000..523d87d26
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/ProcessList.c
@@ -0,0 +1,462 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
+
+ Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <pwd.h>
+#include <sys/resource.h>
+#include <sys/procfs.h>
+#include <sys/statfs.h>
+#include <sys/sysmp.h>
+#include <sys/sysinfo.h>
+
+#include "ccont.h"
+#include "../../gui/SignalIDs.h"
+#include "ksysguardd.h"
+
+#include "Command.h"
+#include "ProcessList.h"
+
+#define BUFSIZE 1024
+#define KDEINITLEN strlen("kdeinit: ")
+
+typedef struct {
+ int alive; /* for "garbage collection" */
+ pid_t pid; /* process ID */
+ pid_t ppid; /* parent process ID */
+ uid_t uid; /* process owner (real UID) */
+ gid_t gid; /* process group (real GID) */
+ char *userName; /* process owner (name) */
+ int nThreads; /* # of threads in this process */
+ int Prio; /* scheduling priority */
+ size_t Size; /* total size of process image */
+ size_t RSSize; /* resident set size */
+ char State[8]; /* process state */
+ double Time; /* CPU time for the process in 100ms */
+ double Load; /* CPU load in % */
+ char Command[PRCOMSIZ];/* command name */
+ char CmdLine[PRARGSZ];/* command line */
+ double centStamp; /* timestamp for CPU load */
+} ProcessInfo;
+
+static CONTAINER ProcessList = 0;
+static unsigned ProcessCount = 0; /* # of processes */
+static DIR *procdir; /* handle for /proc */
+static int pagesz;
+
+#define KBYTES 1024
+
+/*
+ * lwpStateName() -- return string representation of process state
+ */
+char *lwpStateName( prpsinfo_t lwpinfo ) {
+
+ static char result[8];
+
+ switch( lwpinfo.pr_sname ) {
+ case 'S':
+ sprintf( result, "%s", "sleep" );
+ break;
+ case 'R':
+ sprintf( result, "%s", "run" );
+ break;
+ case 'Z':
+ sprintf( result, "%s", "zombie" );
+ break;
+ case 'T':
+ sprintf( result, "%s", "stop" );
+ break;
+ case 'I':
+ sprintf( result, "%s", "start" );
+ break;
+ case 'X':
+ sprintf( result, "%s", "wmem" );
+ case '0':
+ sprintf( result, "%s/%d", "cpu", (int) lwpinfo.pr_sonproc );
+ break;
+ default:
+ sprintf( result, "%s", "???" );
+ break;
+ }
+
+ return( result );
+}
+
+static void validateStr( char *string ) {
+
+ char *ptr = string;
+
+ /*
+ * remove all chars that might screw up communication
+ */
+ while( *ptr != '\0' ) {
+ if( *ptr == '\t' || *ptr == '\n' || *ptr == '\r' )
+ *ptr = ' ';
+ ptr++;
+ }
+ /*
+ * make sure there's at least one char
+ */
+ if( string[0] == '\0' )
+ strcpy( string, " " );
+}
+
+static int processCmp( void *p1, void *p2 ) {
+
+ return( ((ProcessInfo *) p1)->pid - ((ProcessInfo *) p2)->pid );
+}
+
+static ProcessInfo *findProcessInList( pid_t pid ) {
+
+ ProcessInfo key;
+ long index;
+
+ key.pid = pid;
+ if( (index = search_ctnr( ProcessList, processCmp, &key )) < 0 )
+ return( NULL );
+
+ return( get_ctnr( ProcessList, index ));
+}
+
+static int updateProcess( pid_t pid ) {
+ ProcessInfo *ps;
+ int fd;
+ char buf[BUFSIZE];
+ prpsinfo_t psinfo;
+ struct passwd *pw;
+ register double newCentStamp,timeDiff, usDiff,usTime;
+ struct timeval tv;
+
+ if( (ps = findProcessInList( pid )) == NULL ) {
+ if( (ps = (ProcessInfo *) malloc( sizeof( ProcessInfo )))
+ == NULL ) {
+ print_error( "cannot malloc()\n" );
+ return( -1 );
+ }
+ ps->pid = pid;
+ ps->userName = NULL;
+ ps->alive = 0;
+
+ gettimeofday(&tv, 0);
+ ps->centStamp = (double)tv.tv_sec * 100.0 + (double)tv.tv_usec / 10000.0;
+
+ push_ctnr( ProcessList, ps );
+ bsort_ctnr( ProcessList, processCmp );
+ }
+
+ sprintf( buf, "%s/pinfo/%ld", PROCDIR, pid );
+ if( (fd = open( buf, O_RDONLY )) < 0 ) {
+ /* process terminated */
+ return( -1 );
+ }
+
+
+
+ if( ioctl(fd,PIOCPSINFO,&psinfo) < 0) {
+ print_error( "cannot read psinfo from \"%s\"\n", buf );
+ close( fd );
+ return( -1 );
+ }
+ close( fd );
+
+ ps->ppid = psinfo.pr_ppid;
+ ps->uid = psinfo.pr_uid;
+ ps->gid = psinfo.pr_gid;
+
+ pw = getpwuid( psinfo.pr_uid );
+ if( ps->userName != NULL )
+ free( ps->userName );
+ ps->userName = strdup( pw->pw_name );
+
+ strncpy (ps->State,lwpStateName( psinfo ),8);
+ ps->State[7]='\0';
+
+
+ ps->Prio = psinfo.pr_pri;
+
+ gettimeofday(&tv, 0);
+ newCentStamp = (double)tv.tv_sec * 100.0 + (double) tv.tv_usec / 10000.0;
+ usTime = (double) psinfo.pr_time.tv_sec * 100.0 + (double)psinfo.pr_time.tv_nsec / 10000000.0;
+
+ timeDiff = newCentStamp - ps->centStamp;
+ usDiff = usTime - ps->Time;
+
+ if ((timeDiff > 0.0) && (usDiff >= 0.0))
+ {
+ ps->Load = (usDiff / timeDiff) * 100.0;
+ /* During startup we get bigger loads since the time diff
+ * cannot be correct. So we force it to 0. */
+ ps->Load = (ps->Load > 100.0) ? 0.0 : ps->Load;
+ }
+ else
+ ps->Load = 0.0;
+
+ ps->centStamp = newCentStamp;
+ ps->Time = usTime;
+
+ ps->Size = (psinfo.pr_size * pagesz)/KBYTES;
+ ps->RSSize = (psinfo.pr_rssize * pagesz)/KBYTES;
+
+ strncpy(ps->Command,psinfo.pr_fname,PRCOMSIZ);
+ ps->Command[PRCOMSIZ-1]='\0';
+
+ strncpy(ps->CmdLine,psinfo.pr_psargs,PRARGSZ);
+ ps->CmdLine[PRARGSZ-1]='\0';
+
+ validateStr( ps->Command );
+ validateStr( ps->CmdLine );
+
+ ps->alive = 1;
+ return( 0 );
+}
+
+static void cleanupProcessList( void ) {
+
+ ProcessInfo *ps;
+
+ ProcessCount = 0;
+ for( ps = first_ctnr( ProcessList ); ps; ps = next_ctnr( ProcessList )) {
+ if( ps->alive ) {
+ ps->alive = 0;
+ ProcessCount++;
+ } else {
+ free( remove_ctnr( ProcessList ));
+ }
+ }
+}
+
+void initProcessList( struct SensorModul* sm ) {
+
+ if( (procdir = opendir( PROCDIR )) == NULL ) {
+ print_error( "cannot open \"%s\" for reading\n", PROCDIR );
+ return;
+ }
+ pagesz=getpagesize();
+ ProcessList = new_ctnr();
+ updateProcessList();
+
+ /*
+ * register the supported monitors & commands
+ */
+ registerMonitor( "pscount", "integer",
+ printProcessCount, printProcessCountInfo, sm );
+ registerMonitor( "ps", "table",
+ printProcessList, printProcessListInfo, sm );
+
+ if (!RunAsDaemon)
+ {
+ registerCommand("kill", killProcess);
+ registerCommand("setpriority", setPriority);
+ }
+}
+
+void exitProcessList( void ) {
+
+ removeMonitor("ps");
+ removeMonitor("pscount");
+
+ if (!RunAsDaemon)
+ {
+ removeCommand("kill");
+ removeCommand("setpriority");
+ }
+
+ destr_ctnr( ProcessList, free );
+}
+
+int updateProcessList( void ) {
+
+ struct dirent *de;
+ struct statfs sf;
+
+ statfs("/proc/pinfo",&sf,sizeof(sf),0);
+ ProcessCount = sf.f_files;
+
+ rewinddir( procdir );
+ while( (de = readdir( procdir )) != NULL ) {
+ /*
+ * skip '.' and '..'
+ */
+ if( de->d_name[0] == '.' )
+ continue;
+
+ /*
+ * fetch the process info and insert it into the info table
+ */
+ updateProcess( (pid_t) atol( de->d_name ));
+ }
+ cleanupProcessList();
+
+ return( 0 );
+}
+
+void printProcessListInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Name\tPID\tPPID\tGID\tStatus\tUser"
+ "\tSize\tResident\t%% CPU\tPriority\tCommand\n" );
+ fprintf(CurrentClient, "s\td\td\td\ts\ts\tD\tD\tf\td\ts\n" );
+}
+
+void printProcessList( const char *cmd ) {
+
+ ProcessInfo *ps;
+
+ for( ps = first_ctnr( ProcessList ); ps; ps = next_ctnr( ProcessList )) {
+ fprintf(CurrentClient,
+ "%s\t%ld\t%ld\t%ld\t%s\t%s\t%d\t%d\t%.2f\t%d\t%s\n",
+ ps->Command,
+ (long) ps->pid,
+ (long) ps->ppid,
+ (long) ps->gid,
+ ps->State,
+ ps->userName,
+ ps->Size,
+ ps->RSSize,
+ ps->Load,
+ ps->Prio,
+ ps->CmdLine);
+ }
+
+ fprintf(CurrentClient, "\n");
+}
+
+void printProcessCount( const char *cmd ) {
+ fprintf(CurrentClient, "%d\n", ProcessCount );
+}
+
+void printProcessCountInfo( const char *cmd ) {
+ fprintf(CurrentClient, "Number of Processes\t0\t0\t\n" );
+}
+
+void killProcess( const char *cmd ) {
+
+ int sig, pid;
+
+ sscanf( cmd, "%*s %d %d", &pid, &sig );
+
+ switch( sig ) {
+ case MENU_ID_SIGABRT:
+ sig = SIGABRT;
+ break;
+ case MENU_ID_SIGALRM:
+ sig = SIGALRM;
+ break;
+ case MENU_ID_SIGCHLD:
+ sig = SIGCHLD;
+ break;
+ case MENU_ID_SIGCONT:
+ sig = SIGCONT;
+ break;
+ case MENU_ID_SIGFPE:
+ sig = SIGFPE;
+ break;
+ case MENU_ID_SIGHUP:
+ sig = SIGHUP;
+ break;
+ case MENU_ID_SIGILL:
+ sig = SIGILL;
+ break;
+ case MENU_ID_SIGINT:
+ sig = SIGINT;
+ break;
+ case MENU_ID_SIGKILL:
+ sig = SIGKILL;
+ break;
+ case MENU_ID_SIGPIPE:
+ sig = SIGPIPE;
+ break;
+ case MENU_ID_SIGQUIT:
+ sig = SIGQUIT;
+ break;
+ case MENU_ID_SIGSEGV:
+ sig = SIGSEGV;
+ break;
+ case MENU_ID_SIGSTOP:
+ sig = SIGSTOP;
+ break;
+ case MENU_ID_SIGTERM:
+ sig = SIGTERM;
+ break;
+ case MENU_ID_SIGTSTP:
+ sig = SIGTSTP;
+ break;
+ case MENU_ID_SIGTTIN:
+ sig = SIGTTIN;
+ break;
+ case MENU_ID_SIGTTOU:
+ sig = SIGTTOU;
+ break;
+ case MENU_ID_SIGUSR1:
+ sig = SIGUSR1;
+ break;
+ case MENU_ID_SIGUSR2:
+ sig = SIGUSR2;
+ break;
+ }
+ if( kill( (pid_t) pid, sig )) {
+ switch( errno ) {
+ case EINVAL:
+ fprintf(CurrentClient, "4\n" );
+ break;
+ case ESRCH:
+ fprintf(CurrentClient, "3\n" );
+ break;
+ case EPERM:
+ fprintf(CurrentClient, "2\n" );
+ break;
+ default:
+ fprintf(CurrentClient, "1\n" ); /* unknown error */
+ break;
+ }
+ } else
+ fprintf(CurrentClient, "0\n");
+}
+
+void setPriority( const char *cmd ) {
+ int pid, prio;
+
+ sscanf( cmd, "%*s %d %d", &pid, &prio );
+ if( setpriority( PRIO_PROCESS, pid, prio )) {
+ switch( errno ) {
+ case EINVAL:
+ fprintf(CurrentClient, "4\n" );
+ break;
+ case ESRCH:
+ fprintf(CurrentClient, "3\n" );
+ break;
+ case EPERM:
+ case EACCES:
+ fprintf(CurrentClient, "2\n" );
+ break;
+ default:
+ fprintf(CurrentClient, "1\n" ); /* unknown error */
+ break;
+ }
+ } else
+ fprintf(CurrentClient, "0\n");
+}
diff --git a/ksysguard/ksysguardd/Irix/ProcessList.h b/ksysguard/ksysguardd/Irix/ProcessList.h
new file mode 100644
index 000000000..5d949279e
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/ProcessList.h
@@ -0,0 +1,43 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _ProcessList_H_
+#define _ProcessList_H_
+
+#define PROCDIR "/proc"
+
+void initProcessList(struct SensorModul* sm);
+void exitProcessList(void);
+
+int updateProcessList(void);
+
+void printProcessList(const char*);
+void printProcessListInfo(const char*);
+
+void printProcessCount(const char* cmd);
+void printProcessCountInfo(const char* cmd);
+
+void killProcess(const char* cmd);
+void setPriority(const char* cmd);
+
+#endif
diff --git a/ksysguard/ksysguardd/Irix/cpu.c b/ksysguard/ksysguardd/Irix/cpu.c
new file mode 100644
index 000000000..9fdd25ab7
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/cpu.c
@@ -0,0 +1,262 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/sysmp.h>
+#include <sys/sysinfo.h>
+
+#include "cpu.h"
+#include "Command.h"
+#include "ksysguardd.h"
+
+#define CPUSTATES 6
+
+long percentages(int cnt, int *out, long *new, long *old, long *diffs);
+
+static int nCPUs=0;
+
+
+long cp_time[CPUSTATES];
+long cp_old[CPUSTATES];
+long cp_diff[CPUSTATES];
+int cpu_states[CPUSTATES];
+
+struct cpu_info{
+ long cp_time[CPUSTATES];
+ long cp_old[CPUSTATES];
+ long cp_diff[CPUSTATES];
+ int cpu_states[CPUSTATES];
+};
+
+static struct cpu_info *g_ci;
+
+/* returns the requested cpu number starting at 0*/
+int getID(const char *cmd){
+ int id;
+ sscanf(cmd + 7, "%d", &id);
+ return id-1;
+}
+
+void
+initCpuInfo(struct SensorModul* sm)
+{
+ char mname[50];
+ int i;
+ if (sysmp(MP_NPROCS,&nCPUs) < 0) nCPUs=0;
+ nCPUs++;
+ g_ci = malloc(sizeof(struct cpu_info) * nCPUs);
+ memset(g_ci,0,sizeof(struct cpu_info) * nCPUs);
+
+ registerMonitor("cpu/user", "integer", printCPUUser,
+ printCPUUserInfo, sm);
+ registerMonitor("cpu/sys", "integer", printCPUSys,
+ printCPUSysInfo, sm);
+ registerMonitor("cpu/idle", "integer", printCPUIdle,
+ printCPUIdleInfo, sm);
+
+ if (nCPUs > 1) for (i=0;i<nCPUs;i++){
+ /* indidividual CPU load */
+ sprintf(mname,"cpu/cpu%d/user",i+1);
+ registerMonitor(mname, "integer", printCPUxUser,
+ printCPUUserInfo, sm);
+ sprintf(mname,"cpu/cpu%d/sys",i+1);
+ registerMonitor(mname, "integer", printCPUxSys,
+ printCPUSysInfo, sm);
+ sprintf(mname,"cpu/cpu%d/idle",i+1);
+ registerMonitor(mname, "integer", printCPUxIdle,
+ printCPUIdleInfo, sm);
+ }
+
+ updateCpuInfo();
+}
+
+void
+exitCpuInfo(void)
+{
+ free(g_ci);
+}
+
+int
+updateCpuInfo(void)
+{
+ struct sysinfo si;
+ int rv=0;
+ int i;
+ /* overall summary */
+ if (sysmp(MP_SAGET,MPSA_SINFO,&si,sizeof(struct sysinfo)) >=0){
+ cp_time[CPU_IDLE] =si.cpu[CPU_IDLE];
+ cp_time[CPU_USER] =si.cpu[CPU_USER];
+ cp_time[CPU_KERNEL]=si.cpu[CPU_KERNEL];
+ cp_time[CPU_SXBRK] =si.cpu[CPU_SXBRK];
+ cp_time[CPU_INTR] =si.cpu[CPU_INTR];
+ cp_time[CPU_WAIT] =si.cpu[CPU_WAIT];
+ percentages(CPUSTATES,cpu_states,cp_time,cp_old,cp_diff);
+ }
+ /* individual CPU statistics*/
+ if (nCPUs > 1) for (i=0;i<nCPUs;i++){
+ if (sysmp(MP_SAGET1,MPSA_SINFO,&si,sizeof(struct sysinfo),i) >=0){
+ g_ci[i].cp_time[CPU_IDLE] =si.cpu[CPU_IDLE];
+ g_ci[i].cp_time[CPU_USER] =si.cpu[CPU_USER];
+ g_ci[i].cp_time[CPU_KERNEL]=si.cpu[CPU_KERNEL];
+ g_ci[i].cp_time[CPU_SXBRK] =si.cpu[CPU_SXBRK];
+ g_ci[i].cp_time[CPU_INTR] =si.cpu[CPU_INTR];
+ g_ci[i].cp_time[CPU_WAIT] =si.cpu[CPU_WAIT];
+ percentages(CPUSTATES, g_ci[i].cpu_states, g_ci[i].cp_time, g_ci[i].cp_old,g_ci[i].cp_diff);
+ }else{
+ rv =-1;
+ }
+ }
+ return (rv);
+}
+
+void
+printCPUUser(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CPU_USER]/10);
+}
+
+void
+printCPUUserInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU User Load\t0\t100\t%%\n");
+}
+
+void
+printCPUSys(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CPU_KERNEL]/10);
+}
+
+void
+printCPUSysInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU System Load\t0\t100\t%%\n");
+}
+
+void
+printCPUIdle(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", cpu_states[CPU_IDLE]/10);
+}
+
+void
+printCPUIdleInfo(const char* cmd)
+{
+ fprintf(CurrentClient, "CPU Idle Load\t0\t100\t%%\n");
+}
+/* same as above but for individual CPUs */
+void
+printCPUxUser(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", g_ci[getID(cmd)].cpu_states[CPU_USER]/10);
+}
+
+void
+printCPUxSys(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", g_ci[getID(cmd)].cpu_states[CPU_KERNEL]/10);
+}
+
+void
+printCPUxIdle(const char* cmd)
+{
+ fprintf(CurrentClient, "%d\n", g_ci[getID(cmd)].cpu_states[CPU_IDLE]/10);
+}
+
+
+/* The part ripped from top... */
+/*
+ * Top users/processes display for Unix
+ * Version 3
+ *
+ * This program may be freely redistributed,
+ * but this entire comment MUST remain intact.
+ *
+ * Copyright (c) 1984, 1989, William LeFebvre, Rice University
+ * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University
+ */
+
+/*
+ * percentages(cnt, out, new, old, diffs) - calculate percentage change
+ * between array "old" and "new", putting the percentages in "out".
+ * "cnt" is size of each array and "diffs" is used for scratch space.
+ * The array "old" is updated on each call.
+ * The routine assumes modulo arithmetic. This function is especially
+ * useful on BSD mchines for calculating cpu state percentages.
+ */
+
+long percentages(cnt, out, new, old, diffs)
+
+int cnt;
+int *out;
+register long *new;
+register long *old;
+long *diffs;
+
+{
+ register int i;
+ register long change;
+ register long total_change;
+ register long *dp;
+ long half_total;
+
+ /* initialization */
+ total_change = 0;
+ dp = diffs;
+
+ /* calculate changes for each state and the overall change */
+ for (i = 0; i < cnt; i++)
+ {
+ if ((change = *new - *old) < 0)
+ {
+ /* this only happens when the counter wraps */
+ change = (int)
+ ((unsigned long)*new-(unsigned long)*old);
+ }
+ total_change += (*dp++ = change);
+ *old++ = *new++;
+ }
+
+ /* avoid divide by zero potential */
+ if (total_change == 0)
+ {
+ total_change = 1;
+ }
+
+ /* calculate percentages based on overall change, rounding up */
+ half_total = total_change / 2l;
+
+ /* Do not divide by 0. Causes Floating point exception */
+ if(total_change) {
+ for (i = 0; i < cnt; i++)
+ {
+ *out++ = (int)((*diffs++ * 1000 + half_total) / total_change);
+ }
+ }
+
+ /* return the total in case the caller wants to use it */
+ return(total_change);
+}
diff --git a/ksysguard/ksysguardd/Irix/cpu.h b/ksysguard/ksysguardd/Irix/cpu.h
new file mode 100644
index 000000000..f61d12505
--- /dev/null
+++ b/ksysguard/ksysguardd/Irix/cpu.h
@@ -0,0 +1,43 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef _cpuinfo_h_
+#define _cpuinfo_h_
+
+void initCpuInfo(struct SensorModul* sm);
+void exitCpuInfo(void);
+
+int updateCpuInfo(void);
+
+void printCPUUser(const char* cmd);
+void printCPUUserInfo(const char* cmd);
+void printCPUSys(const char* cmd);
+void printCPUSysInfo(const char* cmd);
+void printCPUIdle(const char* cmd);
+void printCPUIdleInfo(const char* cmd);
+void printCPUxUser(const char* cmd);
+void printCPUxUserInfo(const char* cmd);
+void printCPUxSys(const char* cmd);
+void printCPUxSysInfo(const char* cmd);
+void printCPUxIdle(const char* cmd);
+void printCPUxIdleInfo(const char* cmd);
+
+#endif