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.
26 #include <sys/types.h>
27 #include <sys/statfs.h>
29 #include <sys/sysmp.h>
33 #include "ksysguardd.h"
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 ) {
61 int pagesize
= getpagesize();
63 if( sysmp(MP_SAGET
, MPSA_RMINFO
, &rmi
, sizeof(rmi
)) == -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
);
73 swapctl(SC_GETSWAPTOT
,&val
);
75 swapctl(SC_GETFREESWAP
,&val
);
83 void printMemFreeInfo( const char *cmd
) {
86 fprintf(CurrentClient
, "Free Memory\t0\t%ld\tKB\n", freemem
);
89 void printMemFree( const char *cmd
) {
92 fprintf(CurrentClient
, "%ld\n", freemem
);
95 void printMemUsedInfo( const char *cmd
) {
98 fprintf(CurrentClient
, "Used Memory\t0\t%ld\tKB\n", totalmem
- freemem
);
101 void printMemUsed( const char *cmd
) {
104 fprintf(CurrentClient
, "%ld\n", totalmem
- freemem
);
107 void printSwapFreeInfo( const char *cmd
) {
110 fprintf(CurrentClient
, "Free Swap\t0\t%ld\tKB\n", freeswap
);
113 void printSwapFree( const char *cmd
) {
116 fprintf(CurrentClient
, "%ld\n", freeswap
);
118 void printSwapUsedInfo( const char *cmd
) {
121 fprintf(CurrentClient
, "Used Swap\t0\t%ld\tKB\n", totalswap
- freeswap
);
124 void printSwapUsed( const char *cmd
) {
127 fprintf(CurrentClient
, "%ld\n", totalswap
- freeswap
);