add more spacing
[personal-kdebase.git] / apps / kinfocenter / memory / memory_tru64.cpp
blobf10934e88adf174087eff26fa82f6b2e930ddf0c
1 /*
2 * This is memory_tru64.cpp to retrieve memory information under Tru64/Alpha.
4 * Implemented by Tom Leitner, Tom@radar.tu-graz.ac.at
6 * WARNING: This module requires linking with -lmach
8 * This routine is based on m_decosf1.c from the "top" program written by:
10 * AUTHOR: Anthony Baxter, <anthony@aaii.oz.au>
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <sys/socket.h>
17 #include <sys/mbuf.h>
18 #include <net/route.h>
19 #include <sys/table.h>
20 extern "C" {
21 #include <mach/mach_traps.h>
23 #include <mach/vm_statistics.h>
25 #define pagetob(size) (MEMORY(1024L) * ((long) (size) << (long) pageshift))
26 #define LOG1024 10
28 extern "C" void vm_statistics(task_t, vm_statistics_data_t*);
30 void KCMMemory::fetchValues()
32 int pageshift; /* log base 2 of the pagesize */
33 register int pagesize;
34 vm_statistics_data_t vmstats;
35 int swap_pages=0,swap_free=0,i;
36 struct tbl_swapinfo swbuf;
38 /* get the page size with "getpagesize" and calculate pageshift from it */
40 pagesize = getpagesize();
41 pageshift = 0;
42 while (pagesize > 1) {
43 pageshift++;
44 pagesize >>= 1;
47 /* we only need the amount of log(2)1024 for our conversion */
49 pageshift -= LOG1024;
51 /* memory information */
52 /* this is possibly bogus - we work out total # pages by */
53 /* adding up the free, active, inactive, wired down, and */
54 /* zero filled. Anyone who knows a better way, TELL ME! */
55 /* Change: don't use zero filled. */
57 (void) ::vm_statistics(::task_self(), &vmstats);
59 /* thanks DEC for the table() command. No thanks at all for */
60 /* omitting the man page for it from OSF/1 1.2, and failing */
61 /* to document SWAPINFO in the 1.3 man page. Lets hear it for */
62 /* include files. */
64 i=0;
65 while(table(TBL_SWAPINFO,i,&swbuf,1,sizeof(struct tbl_swapinfo))>0) {
66 swap_pages += swbuf.size;
67 swap_free += swbuf.free;
68 i++;
70 memoryInfos[TOTAL_MEM] = pagetob((vmstats.free_count +
71 vmstats.active_count +
72 vmstats.inactive_count +
73 vmstats.wire_count));
74 memoryInfos[FREE_MEM] = pagetob(vmstats.free_count);
75 memoryInfos[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
76 memoryInfos[BUFFER_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
77 #ifdef __GNUC__
78 #warning "FIXME: memoryInfos[CACHED_MEM]"
79 #endif
80 memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; /* cached memory in ram */
81 memoryInfos[SWAP_MEM] = pagetob(swap_pages);
82 memoryInfos[FREESWAP_MEM] = pagetob(swap_free);