3
#include <sys/sysctl.h>
4
#include <sys/vmmeter.h>
6
#include <vm/vm_param.h>
12
void KMemoryWidget::update()
14
char blah[10], buf[80], *used_str, *total_str;
15
/* Stuff for sysctl */
18
/* Stuff for swap display */
19
int used, total, _free;
23
sysctlbyname("hw.physmem", &memory, &len, NULL, 0);
25
snprintf(blah, 10, "%d", memory);
28
// total physical memory (without swap space)
29
Memory_Info[TOTAL_MEM] = MEMORY(memory);
31
// added by Brad Hughes bhughes@trolltech.com
34
#warning "FIXME: Memory_Info[CACHED_MEM]"
36
Memory_Info[CACHED_MEM] = NO_MEMORY_INFO;
38
// The sysctls don't work in a nice manner under FreeBSD v2.2.x
39
// so we assume that if sysctlbyname doesn't return what we
40
// prefer, assume it's the old data types. FreeBSD prior
41
// to 4.0-R isn't supported by the rest of KDE, so what is
42
// this code doing here.
45
if (sysctlbyname("vm.vmmeter", &vmem, &len, NULL, 0) == 0)
46
Memory_Info[SHARED_MEM] = MEMORY(vmem.t_armshr) * PAGE_SIZE;
48
Memory_Info[SHARED_MEM] = NO_MEMORY_INFO;
51
len = sizeof (buffers);
52
if ((sysctlbyname("vfs.bufspace", &buffers, &len, NULL, 0) == -1) || !len)
53
Memory_Info[BUFFER_MEM] = NO_MEMORY_INFO;
55
Memory_Info[BUFFER_MEM] = MEMORY(buffers);
57
// total free physical memory (without swap space)
59
len = sizeof (buffers);
60
if ((sysctlbyname("vm.stats.vm.v_free_count", &free, &len, NULL, 0) == -1) || !len)
61
Memory_Info[FREE_MEM] = NO_MEMORY_INFO;
63
Memory_Info[FREE_MEM] = MEMORY(free) * getpagesize();
65
// Q&D hack for swap display. Borrowed from xsysinfo-1.4
66
if ((pipe = popen("/usr/sbin/pstat -ks", "r")) == NULL) {
71
fgets(buf, sizeof(buf), pipe);
72
fgets(buf, sizeof(buf), pipe);
73
fgets(buf, sizeof(buf), pipe);
74
fgets(buf, sizeof(buf), pipe);
78
total_str = strtok(NULL, " ");
79
used_str = strtok(NULL, " ");
80
used = atoi(used_str);
81
total = atoi(total_str);
85
// total size of all swap-partitions
86
Memory_Info[SWAP_MEM] = MEMORY(total) * 1024;
88
// free memory in swap-partitions
89
Memory_Info[FREESWAP_MEM] = MEMORY(_free) * 1024;