3
Copyright 1999 Helge Deller deller@gmx.de
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License or (at your option) version 3 or any later version
9
accepted by the membership of KDE e.V. (or its successor approved
10
by the membership of KDE e.V.), which shall act as a proxy
11
defined in Section 14 of version 3 of the license.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include <sys/param.h>
25
#include <sys/pstat.h>
28
#define MAX_SWAP_AREAS 16
30
void KCMMemory::fetchValues()
33
unsigned long total_mem, total_free,
34
total_physical, total_swap, free_physical,
35
used_physical, used_swap, free_swap;
37
struct pst_static pststatic;
38
struct pst_dynamic stats;
39
struct pst_vminfo vmstats;
40
unsigned long fields_[4];
41
struct pst_swapinfo swapinfo;
43
pstat_getstatic( &pststatic, sizeof( struct pst_static ), (size_t)1, 0);
44
total_physical = pststatic.physical_memory;
45
page_size = (int)pststatic.page_size;
47
pstat_getdynamic(&stats, sizeof( pst_dynamic ), (size_t)1, 0);
48
pstat_getvminfo(&vmstats, sizeof(vmstats), (size_t)1, 0);
50
fields_[0] = stats.psd_rmtxt + stats.psd_arm; // TEXT
51
fields_[1] = stats.psd_rm - stats.psd_rmtxt; // USED
52
fields_[2] = total_physical - fields_[0] - fields_[1] - stats.psd_free; //OTHER
53
fields_[3] = stats.psd_free; // FREE
55
used_physical = (total_physical - fields_[3]) * page_size;
56
total_physical *= page_size;
57
free_physical = (total_physical - used_physical);
60
/* Now check the SWAP-AREAS !! */
62
total_swap = free_swap = 0;
64
for (i = 0 ; i < MAX_SWAP_AREAS ; i++)
66
pstat_getswap(&swapinfo, sizeof(swapinfo), (size_t)1, i);
67
if (swapinfo.pss_idx == (unsigned)i)
69
swapinfo.pss_nfpgs *= 4; // nfpgs is in 512 Byte Blocks....
70
if (swapinfo.pss_nblksenabled == 0) // == 0 ??
71
swapinfo.pss_nblksenabled = swapinfo.pss_nfpgs;
72
total_swap += (((unsigned long)swapinfo.pss_nblksenabled) * 1024);
73
free_swap += (((unsigned long)swapinfo.pss_nfpgs ) * 1024);
77
used_swap = total_swap - free_swap;
80
/* Now display the results */
82
total_mem = total_physical; // + total_swap;
83
total_free = (total_physical - used_physical);// + free_swap;
85
memoryInfos[TOTAL_MEM] = MEMORY(total_mem); // total physical memory (without swaps)
86
memoryInfos[FREE_MEM] = MEMORY(total_free);// total free physical memory (without swaps)
87
memoryInfos[SHARED_MEM] = NO_MEMORY_INFO; /* FIXME ?? */
88
memoryInfos[BUFFER_MEM] = MEMORY(fields_[2])*page_size; /* FIXME ?? */
89
memoryInfos[SWAP_MEM] = MEMORY(total_swap); // total size of all swap-partitions
90
memoryInfos[FREESWAP_MEM] = MEMORY(free_swap); // free memory in swap-partitions
92
#warning "FIXME: memoryInfos[CACHED_MEM]"
94
memoryInfos[CACHED_MEM] = NO_MEMORY_INFO; // cached memory in ram