add more spacing
[personal-kdebase.git] / apps / kinfocenter / memory / memory_netbsd.cpp
blob67a9a9e21bf2e206873bc2f32b771c5686252b9c
2 #include <sys/param.h>
3 #if __NetBSD_Version__ > 103080000
4 #define UVM
5 #endif
6 #if defined(__OpenBSD__)
7 #define UVM
8 #endif
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <sys/sysctl.h>
14 #ifdef UVM
15 #include <uvm/uvm_extern.h>
16 #else
17 #include <vm/vm_swap.h>
18 #endif
20 void KCMMemory::fetchValues()
22 int mib[2];
23 size_t len;
24 #ifdef UVM
25 #if __NetBSD_Version__ > 106000000
26 struct uvmexp_sysctl uvmexp;
27 #else
28 struct uvmexp uvmexp;
29 #endif
30 #else
31 struct swapent *swaplist;
32 int64_t nswap, rnswap, totalswap, freeswap, usedswap;
33 #endif
34 #if __NetBSD_Version__ > 106170000 /* 1.6Q+ */
35 quad_t memory;
36 #else
37 int memory;
38 #endif
40 /* memory */
41 #if __NetBSD_Version__ > 106170000 /* 1.6Q+ */
42 mib[0] = CTL_HW;
43 mib[1] = HW_PHYSMEM64;
44 #else
45 mib[0] = CTL_HW;
46 mib[1] = HW_PHYSMEM;
47 #endif
48 len = sizeof(memory);
49 if( sysctl(mib,2,&memory,&len,NULL,0)< 0 )
50 memoryInfos[TOTAL_MEM] = NO_MEMORY_INFO;
51 else
52 memoryInfos[TOTAL_MEM] = memory;
54 #ifdef UVM
55 mib[0] = CTL_VM;
56 #if __NetBSD_Version__ > 106000000
57 mib[1] = VM_UVMEXP2;
58 #else
59 mib[1] = VM_UVMEXP;
60 #endif
61 len = sizeof(uvmexp);
62 if ( sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0 ) {
63 memoryInfos[FREE_MEM] = NO_MEMORY_INFO;
64 memoryInfos[ACTIVE_MEM] = NO_MEMORY_INFO;
65 memoryInfos[INACTIVE_MEM] = NO_MEMORY_INFO;
66 memoryInfos[SWAP_MEM] = NO_MEMORY_INFO;
67 memoryInfos[FREESWAP_MEM] = NO_MEMORY_INFO;
68 memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
69 } else {
70 t_memsize pgsz = MEMORY(uvmexp.pagesize);
71 memoryInfos[FREE_MEM] = pgsz * uvmexp.free;
72 memoryInfos[ACTIVE_MEM] = pgsz * uvmexp.active;
73 memoryInfos[INACTIVE_MEM] = pgsz * uvmexp.inactive;
74 memoryInfos[SWAP_MEM] = pgsz * uvmexp.swpages;
75 memoryInfos[FREESWAP_MEM] = pgsz * (uvmexp.swpages - uvmexp.swpginuse);
76 #if __NetBSD_Version__ > 106000000
77 memoryInfos[CACHED_MEM] = pgsz * (uvmexp.filepages + uvmexp.execpages);
78 #else
79 memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
80 #endif
82 #else
83 memoryInfos[FREE_MEM] = NO_MEMORY_INFO;
84 memoryInfos[ACTIVE_MEM] = NO_MEMORY_INFO;
85 memoryInfos[INACTIVE_MEM] = NO_MEMORY_INFO;
87 /* swap */
88 totalswap = freeswap = usedswap = 0;
89 nswap = swapctl(SWAP_NSWAP,0,0);
90 if ( nswap > 0 ) {
91 if ( (swaplist = (struct swapent *)malloc(nswap * sizeof(*swaplist))) ) {
92 rnswap = swapctl(SWAP_STATS,swaplist,nswap);
93 if ( rnswap < 0 || rnswap > nswap )
94 totalswap = freeswap = -1; /* Error */
95 else {
96 while ( rnswap-- > 0 ) {
97 totalswap += swaplist[rnswap].se_nblks;
98 usedswap += swaplist[rnswap].se_inuse;
100 freeswap = totalswap - usedswap;
102 } else
103 totalswap = freeswap = -1; /* Error */
105 if ( totalswap == -1 ) {
106 memoryInfos[SWAP_MEM] = NO_MEMORY_INFO;
107 memoryInfos[FREESWAP_MEM] = NO_MEMORY_INFO;
108 } else {
109 memoryInfos[SWAP_MEM] = MEMORY(totalswap);
110 memoryInfos[FREESWAP_MEM] = MEMORY(freeswap);
113 #endif