2 KSysGuard, the KDE System Guard
4 Copyright (c) 1999-2000 Hans Petter Bieker <bieker@kde.org>
5 Copyright (c) 1999 Chris Schlaeger <cs@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
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.
28 #include <sys/param.h>
29 #include <sys/sysctl.h>
30 #include <sys/types.h>
31 #include <sys/vmmeter.h>
33 /* Everything post 1.5.x uses uvm/uvm_* includes */
34 #if __NetBSD_Version__ >= 105010000
35 #include <uvm/uvm_param.h>
37 #include <vm/vm_param.h>
42 #include "ksysguardd.h"
44 static size_t Total
= 0;
45 static size_t MFree
= 0;
46 static size_t Used
= 0;
47 static size_t Active
= 0;
48 static size_t Inactive
= 0;
49 static size_t Wired
= 0;
50 static size_t Execpages
= 0;
51 static size_t Filepages
= 0;
52 static size_t STotal
= 0;
53 static size_t SFree
= 0;
54 static size_t SUsed
= 0;
57 initMemory(struct SensorModul
* sm
)
59 registerMonitor("mem/physical/free", "integer", printMFree
, printMFreeInfo
, sm
);
60 registerMonitor("mem/physical/used", "integer", printUsed
, printUsedInfo
, sm
);
61 registerMonitor("mem/physical/active", "integer", printActive
, printActiveInfo
, sm
);
62 registerMonitor("mem/physical/inactive", "integer", printInactive
, printInactiveInfo
, sm
);
63 registerMonitor("mem/physical/wired", "integer", printWired
, printWiredInfo
, sm
);
64 registerMonitor("mem/physical/execpages", "integer", printExecpages
, printExecpagesInfo
, sm
);
65 registerMonitor("mem/physical/filepages", "integer", printFilepages
, printFilepagesInfo
, sm
);
66 registerMonitor("mem/swap/free", "integer", printSwapFree
, printSwapFreeInfo
, sm
);
67 registerMonitor("mem/swap/used", "integer", printSwapUsed
, printSwapUsedInfo
, sm
);
79 #define ARRLEN(X) (sizeof(X)/sizeof(X[0]))
83 static int mib
[]={ CTL_HW
, HW_PHYSMEM
};
86 sysctl(mib
, ARRLEN(mib
), &Total
, &len
, NULL
, 0);
91 struct uvmexp_sysctl x
;
92 static int mib
[] = { CTL_VM
, VM_UVMEXP2
};
95 STotal
= SUsed
= SFree
= -1;
96 Active
= Inactive
= Wired
= Execpages
= Filepages
= MFree
= Used
= -1;
97 if (-1 < sysctl(mib
, ARRLEN(mib
), &x
, &len
, NULL
, 0)) {
98 STotal
= (x
.pagesize
*x
.swpages
) >> 10;
99 SUsed
= (x
.pagesize
*x
.swpginuse
) >> 10;
100 SFree
= STotal
- SUsed
;
101 MFree
= (x
.free
* x
.pagesize
) >> 10;
102 Active
= (x
.active
* x
.pagesize
) >> 10;
103 Inactive
= (x
.inactive
* x
.pagesize
) >> 10;
104 Wired
= (x
.wired
* x
.pagesize
) >> 10;
105 Execpages
= (x
.execpages
* x
.pagesize
) >> 10;
106 Filepages
= (x
.filepages
* x
.pagesize
) >> 10;
107 Used
= Total
- MFree
;
114 printMFree(const char* cmd
)
116 fprintf(CurrentClient
, "%d\n", MFree
);
120 printMFreeInfo(const char* cmd
)
122 fprintf(CurrentClient
, "Free Memory\t0\t%d\tKB\n", Total
);
126 printUsed(const char* cmd
)
128 fprintf(CurrentClient
, "%d\n", Used
);
132 printUsedInfo(const char* cmd
)
134 fprintf(CurrentClient
, "Used Memory\t0\t%d\tKB\n", Total
);
138 printActive(const char* cmd
)
140 fprintf(CurrentClient
, "%d\n", Active
);
144 printActiveInfo(const char* cmd
)
146 fprintf(CurrentClient
, "Active Memory\t0\t%d\tKB\n", Total
);
150 printInactive(const char* cmd
)
152 fprintf(CurrentClient
, "%d\n", Inactive
);
156 printInactiveInfo(const char* cmd
)
158 fprintf(CurrentClient
, "Inactive Memory\t0\t%d\tKB\n", Total
);
162 printWired(const char* cmd
)
164 fprintf(CurrentClient
, "%d\n", Wired
);
168 printWiredInfo(const char* cmd
)
170 fprintf(CurrentClient
, "Wired Memory\t0\t%d\tKB\n", Total
);
174 printExecpages(const char* cmd
)
176 fprintf(CurrentClient
, "%d\n", Execpages
);
180 printExecpagesInfo(const char* cmd
)
182 fprintf(CurrentClient
, "Exec Pages\t0\t%d\tKB\n", Total
);
186 printFilepages(const char* cmd
)
188 fprintf(CurrentClient
, "%d\n", Filepages
);
192 printFilepagesInfo(const char* cmd
)
194 fprintf(CurrentClient
, "File Pages\t0\t%d\tKB\n", Total
);
198 printSwapUsed(const char* cmd
)
200 fprintf(CurrentClient
, "%d\n", SUsed
);
204 printSwapUsedInfo(const char* cmd
)
206 fprintf(CurrentClient
, "Used Swap Memory\t0\t%d\tKB\n", STotal
);
210 printSwapFree(const char* cmd
)
212 fprintf(CurrentClient
, "%d\n", SFree
);
216 printSwapFreeInfo(const char* cmd
)
218 fprintf(CurrentClient
, "Free Swap Memory\t0\t%d\tKB\n", STotal
);