Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / kinfocenter / info / memory_solaris.cpp
blobc191aeb0fcd346faeef2c8dc325abf285c2670d8
1 /*
2 * memory_solaris.cpp
4 * Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
5 */
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <kstat.h>
11 /* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
13 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
14 # undef _FILE_OFFSET_BITS
15 # define _FILE_OFFSET_BITS 32
16 #endif
18 #include <sys/stat.h>
19 #include <sys/swap.h>
20 #include <vm/anon.h>
22 #define PAGETOK(a) (( (t_memsize) sysconf( _SC_PAGESIZE )) * (t_memsize) a)
24 void KMemoryWidget::fetchValues() {
26 kstat_ctl_t *kctl;
27 kstat_t *ksp;
28 kstat_named_t *kdata;
31 * get a kstat handle first and update the user's kstat chain
33 if( (kctl = kstat_open()) == NULL )
34 return;
35 while( kstat_chain_update( kctl ) != 0 )
39 * traverse the kstat chain to find the appropriate kstat
41 if( (ksp = kstat_lookup( kctl, "unix", 0, "system_pages" )) == NULL )
42 return;
44 if( kstat_read( kctl, ksp, NULL ) == -1 )
45 return;
48 * lookup the data
50 #if 0
51 kdata = (kstat_named_t *) kstat_data_lookup( ksp, "physmem" );
52 if( kdata != NULL ) {
53 Memory_Info[TOTAL_MEM] = PAGETOK(kdata->value.ui32);
55 #endif
56 Memory_Info[TOTAL_MEM] = PAGETOK(sysconf(_SC_PHYS_PAGES));
58 kdata = (kstat_named_t *) kstat_data_lookup( ksp, "freemem" );
59 if( kdata != NULL )
60 Memory_Info[FREE_MEM] = PAGETOK(kdata->value.ui32);
61 #ifdef __GNUC__
62 #warning "FIXME: Memory_Info[CACHED_MEM]"
63 #endif
64 Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
66 kstat_close( kctl );
69 * Swap Info
72 struct anoninfo am_swap;
73 long swaptotal;
74 long swapfree;
75 long swapused;
77 swaptotal = swapused = swapfree = 0L;
80 * Retrieve overall swap information from anonymous memory structure -
81 * which is the same way "swap -s" retrieves it's statistics.
83 * swapctl(SC_LIST, void *arg) does not return what we are looking for.
86 if (swapctl(SC_AINFO, &am_swap) == -1)
87 return;
89 swaptotal = am_swap.ani_max;
90 swapused = am_swap.ani_resv;
91 swapfree = swaptotal - swapused;
93 Memory_Info[SWAP_MEM] = PAGETOK(swaptotal);
94 Memory_Info[FREESWAP_MEM] = PAGETOK(swapfree);