1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
$NetBSD: patch-ao,v 1.3 1999/07/15 08:46:23 tron Exp $
--- /dev/null Fri Jan 29 20:07:16 1999
+++ kcontrol/info/memory_netbsd.cpp Fri Jan 29 20:04:24 1999
@@ -0,0 +1,93 @@
+#include <sys/param.h>
+#if __NetBSD_Version__ > 103080000
+#define UVM
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <vm/vm_swap.h>
+#ifdef UVM
+#include <uvm/uvm_extern.h>
+#endif
+
+void KMemoryWidget::update()
+{
+ struct swapent *swaplist;
+ int mib[2], memory, nswap, rnswap, totalswap, freeswap, usedswap;
+ size_t len;
+#ifdef UVM
+ struct uvmexp uvmexp;
+#endif
+
+ /* memory */
+ mib[0] = CTL_HW;
+ mib[1] = HW_PHYSMEM;
+ len = sizeof(memory);
+ if( sysctl(mib,2,&memory,&len,NULL,0)< 0 )
+ totalMem->setText(klocale->translate("Problem in determining"));
+ else
+ totalMem->setText(format(memory));
+
+#ifdef UVM
+ mib[0] = CTL_VM;
+ mib[1] = VM_UVMEXP;
+ len = sizeof(uvmexp);
+ if ( sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0 )
+ {
+ freeMem->setText(klocale->translate("Problem in determining"));
+ activeMem->setText(klocale->translate("Problem in determining"));
+ inactiveMem->setText(klocale->translate("Problem in determining"));
+ swapMem->setText(klocale->translate("Problem in determining"));
+ freeSwapMem->setText(klocale->translate("Problem in determining"));
+ }
+ else
+ {
+ freeMem->setText(format((long)uvmexp.free * uvmexp.pagesize));
+ activeMem->setText(format((long)uvmexp.active * uvmexp.pagesize));
+ inactiveMem->setText(format((long)uvmexp.inactive * uvmexp.pagesize));
+ swapMem->setText(format((long)uvmexp.swpages * uvmexp.pagesize));
+ freeSwapMem->setText(format((long)(uvmexp.swpages - uvmexp.swpginuse) *
+ uvmexp.pagesize));
+ }
+#else
+ freeMem->setText(klocale->translate("Not calculated"));
+ activeMem->setText(klocale->translate("Not calculated"));
+ inactiveMem->setText(klocale->translate("Not calculated"));
+
+ /* swap */
+ totalswap = freeswap = usedswap = 0;
+ nswap = swapctl(SWAP_NSWAP,0,0);
+ if ( nswap > 0 )
+ {
+ if ( (swaplist = (struct swapent *)malloc(nswap * sizeof(*swaplist))) )
+ {
+ rnswap = swapctl(SWAP_STATS,swaplist,nswap);
+ if ( rnswap < 0 || rnswap > nswap )
+ totalswap = freeswap = -1; /* Error */
+ else
+ {
+ while ( rnswap-- > 0 )
+ {
+ totalswap += swaplist[rnswap].se_nblks;
+ usedswap += swaplist[rnswap].se_inuse;
+ }
+ freeswap = totalswap - usedswap;
+ }
+ }
+ else
+ totalswap = freeswap = -1; /* Error */
+ if ( totalswap == -1 )
+ {
+ swapMem->setText(klocale->translate("Problem in determining"));
+ freeSwapMem->setText(klocale->translate("Problem in determining"));
+ }
+ else
+ { /* Cast to long for LP64 hosts */
+ swapMem->setText(format(dbtob((long)totalswap)));
+ freeSwapMem->setText(format(dbtob((long)freeswap)));
+ }
+ }
+#endif
+}
|