Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksysguard / ksysguardd / NetBSD / Memory.c
blob18a3e24b0d81175bdb4cac101746f285de0f75ef
1 /*
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.
23 #include <fcntl.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/param.h>
29 #include <sys/sysctl.h>
30 #include <sys/types.h>
31 #include <sys/vmmeter.h>
32 #include <unistd.h>
33 /* Everything post 1.5.x uses uvm/uvm_* includes */
34 #if __NetBSD_Version__ >= 105010000
35 #include <uvm/uvm_param.h>
36 #else
37 #include <vm/vm_param.h>
38 #endif
40 #include "Command.h"
41 #include "Memory.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;
56 void
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);
70 void
71 exitMemory(void)
75 int
76 updateMemory(void)
79 #define ARRLEN(X) (sizeof(X)/sizeof(X[0]))
80 size_t len;
83 static int mib[]={ CTL_HW, HW_PHYSMEM };
85 len = sizeof(Total);
86 sysctl(mib, ARRLEN(mib), &Total, &len, NULL, 0);
87 Total >>= 10;
91 struct uvmexp_sysctl x;
92 static int mib[] = { CTL_VM, VM_UVMEXP2 };
94 len = sizeof(x);
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;
110 return 0;
113 void
114 printMFree(const char* cmd)
116 fprintf(CurrentClient, "%d\n", MFree);
119 void
120 printMFreeInfo(const char* cmd)
122 fprintf(CurrentClient, "Free Memory\t0\t%d\tKB\n", Total);
125 void
126 printUsed(const char* cmd)
128 fprintf(CurrentClient, "%d\n", Used);
131 void
132 printUsedInfo(const char* cmd)
134 fprintf(CurrentClient, "Used Memory\t0\t%d\tKB\n", Total);
137 void
138 printActive(const char* cmd)
140 fprintf(CurrentClient, "%d\n", Active);
143 void
144 printActiveInfo(const char* cmd)
146 fprintf(CurrentClient, "Active Memory\t0\t%d\tKB\n", Total);
149 void
150 printInactive(const char* cmd)
152 fprintf(CurrentClient, "%d\n", Inactive);
155 void
156 printInactiveInfo(const char* cmd)
158 fprintf(CurrentClient, "Inactive Memory\t0\t%d\tKB\n", Total);
161 void
162 printWired(const char* cmd)
164 fprintf(CurrentClient, "%d\n", Wired);
167 void
168 printWiredInfo(const char* cmd)
170 fprintf(CurrentClient, "Wired Memory\t0\t%d\tKB\n", Total);
173 void
174 printExecpages(const char* cmd)
176 fprintf(CurrentClient, "%d\n", Execpages);
179 void
180 printExecpagesInfo(const char* cmd)
182 fprintf(CurrentClient, "Exec Pages\t0\t%d\tKB\n", Total);
185 void
186 printFilepages(const char* cmd)
188 fprintf(CurrentClient, "%d\n", Filepages);
191 void
192 printFilepagesInfo(const char* cmd)
194 fprintf(CurrentClient, "File Pages\t0\t%d\tKB\n", Total);
197 void
198 printSwapUsed(const char* cmd)
200 fprintf(CurrentClient, "%d\n", SUsed);
203 void
204 printSwapUsedInfo(const char* cmd)
206 fprintf(CurrentClient, "Used Swap Memory\t0\t%d\tKB\n", STotal);
209 void
210 printSwapFree(const char* cmd)
212 fprintf(CurrentClient, "%d\n", SFree);
215 void
216 printSwapFreeInfo(const char* cmd)
218 fprintf(CurrentClient, "Free Swap Memory\t0\t%d\tKB\n", STotal);