Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksysguard / ksysguardd / Irix / Memory.c
blobe88123ddd426ad0bf48d196ff25e7fb0fb874f00
1 /*
2 KSysGuard, the KDE System Guard
4 Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
6 Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of version 2 of the GNU General Public
10 License as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <sys/statfs.h>
28 #include <sys/swap.h>
29 #include <sys/sysmp.h>
31 #include "config.h"
33 #include "ksysguardd.h"
34 #include "Command.h"
35 #include "Memory.h"
37 static int Dirty = 1;
38 static t_memsize totalmem = (t_memsize) 0;
39 static t_memsize freemem = (t_memsize) 0;
40 static unsigned long totalswap = 0L,vswap = 0L;
41 static unsigned long freeswap = 0L,bufmem = 0L ;
43 void initMemory( struct SensorModul* sm ) {
45 registerMonitor( "mem/physical/free", "integer",
46 printMemFree, printMemFreeInfo, sm );
47 registerMonitor( "mem/physical/used", "integer",
48 printMemUsed, printMemUsedInfo, sm );
49 registerMonitor( "mem/swap/free", "integer",
50 printSwapFree, printSwapFreeInfo, sm );
51 registerMonitor( "mem/swap/used", "integer",
52 printSwapUsed, printSwapUsedInfo, sm );
55 void exitMemory( void ) {
58 int updateMemory( void ) {
59 struct statfs sf;
60 off_t val;
61 int pagesize = getpagesize();
62 struct rminfo rmi;
63 if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 )
64 return( -1 );
65 totalmem = rmi.physmem*pagesize/1024; // total physical memory (without swaps)
66 freemem = rmi.freemem*pagesize/1024; // total free physical memory (without swaps)
67 bufmem = rmi.bufmem *pagesize/1024;
69 statfs ("/proc", &sf,sizeof(sf),0);
71 swapctl(SC_GETSWAPVIRT,&val);
72 vswap = val >> 1;
73 swapctl(SC_GETSWAPTOT,&val);
74 totalswap = val >> 1;
75 swapctl(SC_GETFREESWAP,&val);
76 freeswap = val >> 1;
78 Dirty = 1;
80 return( 0 );
83 void printMemFreeInfo( const char *cmd ) {
84 if( Dirty )
85 updateMemory();
86 fprintf(CurrentClient, "Free Memory\t0\t%ld\tKB\n", freemem );
89 void printMemFree( const char *cmd ) {
90 if( Dirty )
91 updateMemory();
92 fprintf(CurrentClient, "%ld\n", freemem );
95 void printMemUsedInfo( const char *cmd ) {
96 if( Dirty )
97 updateMemory();
98 fprintf(CurrentClient, "Used Memory\t0\t%ld\tKB\n", totalmem - freemem );
101 void printMemUsed( const char *cmd ) {
102 if( Dirty )
103 updateMemory();
104 fprintf(CurrentClient, "%ld\n", totalmem - freemem );
107 void printSwapFreeInfo( const char *cmd ) {
108 if( Dirty )
109 updateMemory();
110 fprintf(CurrentClient, "Free Swap\t0\t%ld\tKB\n", freeswap );
113 void printSwapFree( const char *cmd ) {
114 if( Dirty )
115 updateMemory();
116 fprintf(CurrentClient, "%ld\n", freeswap );
118 void printSwapUsedInfo( const char *cmd ) {
119 if( Dirty )
120 updateMemory();
121 fprintf(CurrentClient, "Used Swap\t0\t%ld\tKB\n", totalswap - freeswap );
124 void printSwapUsed( const char *cmd ) {
125 if( Dirty )
126 updateMemory();
127 fprintf(CurrentClient, "%ld\n", totalswap - freeswap );