blob: a82b830d43b0dde5dd0523919f6893d4b37d23c9 (
plain)
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
|
/*
* memory_solaris.cpp
*
* Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
*/
#include <unistd.h>
#include <stdlib.h>
#include <kstat.h>
/* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
# undef _FILE_OFFSET_BITS
# define _FILE_OFFSET_BITS 32
#endif
#include <sys/stat.h>
#include <sys/swap.h>
#include <vm/anon.h>
#define PAGETOK(a) (( (t_memsize) sysconf( _SC_PAGESIZE )) * (t_memsize) a)
void KMemoryWidget::update() {
kstat_ctl_t *kctl;
kstat_t *ksp;
kstat_named_t *kdata;
/*
* get a kstat handle first and update the user's kstat chain
*/
if( (kctl = kstat_open()) == NULL )
return;
while( kstat_chain_update( kctl ) != 0 )
;
/*
* traverse the kstat chain to find the appropriate kstat
*/
if( (ksp = kstat_lookup( kctl, "unix", 0, "system_pages" )) == NULL )
return;
if( kstat_read( kctl, ksp, NULL ) == -1 )
return;
/*
* lookup the data
*/
#if 0
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "physmem" );
if( kdata != NULL ) {
Memory_Info[TOTAL_MEM] = PAGETOK(kdata->value.ui32);
}
#endif
Memory_Info[TOTAL_MEM] = PAGETOK(sysconf(_SC_PHYS_PAGES));
kdata = (kstat_named_t *) kstat_data_lookup( ksp, "freemem" );
if( kdata != NULL )
Memory_Info[FREE_MEM] = PAGETOK(kdata->value.ui32);
#warning "FIXME: Memory_Info[CACHED_MEM]"
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
kstat_close( kctl );
/*
* Swap Info
*/
struct anoninfo am_swap;
long swaptotal;
long swapfree;
long swapused;
swaptotal = swapused = swapfree = 0L;
/*
* Retrieve overall swap information from anonymous memory structure -
* which is the same way "swap -s" retrieves it's statistics.
*
* swapctl(SC_LIST, void *arg) does not return what we are looking for.
*/
if (swapctl(SC_AINFO, &am_swap) == -1)
return;
swaptotal = am_swap.ani_max;
swapused = am_swap.ani_resv;
swapfree = swaptotal - swapused;
Memory_Info[SWAP_MEM] = PAGETOK(swaptotal);
Memory_Info[FREESWAP_MEM] = PAGETOK(swapfree);
}
|