~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/memory/memory_solaris.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  memory_solaris.cpp
 
3
 *
 
4
 *  Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
 
5
 */
 
6
 
 
7
#include <unistd.h>
 
8
#include <stdlib.h>
 
9
#include <kstat.h>
 
10
 
 
11
/* Stop <sys/swap.h> from crapping out on 32-bit architectures. */
 
12
 
 
13
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
 
14
# undef _FILE_OFFSET_BITS
 
15
# define _FILE_OFFSET_BITS 32
 
16
#endif
 
17
 
 
18
#include <sys/stat.h>
 
19
#include <sys/swap.h>
 
20
#include <vm/anon.h>
 
21
 
 
22
#define PAGETOK(a) (( (t_memsize) sysconf( _SC_PAGESIZE )) *  (t_memsize) a)
 
23
 
 
24
void KCMMemory::fetchValues() {
 
25
 
 
26
        kstat_ctl_t     *kctl;
 
27
        kstat_t         *ksp;
 
28
        kstat_named_t   *kdata;
 
29
 
 
30
        /*
 
31
         *  get a kstat handle first and update the user's kstat chain
 
32
         */
 
33
        if( (kctl = kstat_open()) == NULL )
 
34
                return;
 
35
        while( kstat_chain_update( kctl ) != 0 )
 
36
                ;
 
37
 
 
38
        /*
 
39
         *  traverse the kstat chain to find the appropriate kstat
 
40
         */
 
41
        if( (ksp = kstat_lookup( kctl, "unix", 0, "system_pages" )) == NULL )
 
42
                return;
 
43
 
 
44
        if( kstat_read( kctl, ksp, NULL ) == -1 )
 
45
                return;
 
46
 
 
47
        /*
 
48
         *  lookup the data
 
49
         */
 
50
#if 0
 
51
        kdata = (kstat_named_t *) kstat_data_lookup( ksp, "physmem" );
 
52
        if( kdata != NULL ) {
 
53
                memoryInfos[TOTAL_MEM] = PAGETOK(kdata->value.ui32);
 
54
        }
 
55
#endif
 
56
        memoryInfos[TOTAL_MEM] = PAGETOK(sysconf(_SC_PHYS_PAGES));
 
57
 
 
58
        kdata = (kstat_named_t *) kstat_data_lookup( ksp, "freemem" );
 
59
        if( kdata != NULL )
 
60
                memoryInfos[FREE_MEM] = PAGETOK(kdata->value.ui32);
 
61
#ifdef __GNUC__
 
62
#warning "FIXME: memoryInfos[CACHED_MEM]"
 
63
#endif  
 
64
        memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram
 
65
          
 
66
        kstat_close( kctl );
 
67
 
 
68
        /*
 
69
         *  Swap Info
 
70
         */
 
71
 
 
72
        struct anoninfo         am_swap;
 
73
        long                    swaptotal;
 
74
        long                    swapfree;
 
75
        long                    swapused;
 
76
 
 
77
        swaptotal = swapused = swapfree = 0L;
 
78
 
 
79
        /*
 
80
         *  Retrieve overall swap information from anonymous memory structure -
 
81
         *  which is the same way "swap -s" retrieves it's statistics.
 
82
         *
 
83
         *  swapctl(SC_LIST, void *arg) does not return what we are looking for.
 
84
         */
 
85
 
 
86
        if (swapctl(SC_AINFO, &am_swap) == -1)
 
87
                return;
 
88
 
 
89
        swaptotal = am_swap.ani_max;
 
90
        swapused = am_swap.ani_resv;
 
91
        swapfree = swaptotal - swapused;
 
92
 
 
93
        memoryInfos[SWAP_MEM]     = PAGETOK(swaptotal);
 
94
        memoryInfos[FREESWAP_MEM] = PAGETOK(swapfree);
 
95
}