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

« back to all changes in this revision

Viewing changes to kinfocenter/Modules/memory/memory_fbsd.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
#include <sys/types.h>
 
2
#include <sys/sysctl.h>
 
3
#include <sys/vmmeter.h>
 
4
 
 
5
#include <vm/vm_param.h>
 
6
#include <kvm.h>
 
7
 
 
8
#include <fcntl.h>
 
9
#include <paths.h>
 
10
#include <unistd.h>
 
11
 
 
12
void KCMMemory::fetchValues()
 
13
{
 
14
    /* Stuff for sysctl */
 
15
    size_t len;
 
16
 
 
17
    unsigned long memory;
 
18
    len = sizeof(memory);
 
19
    sysctlbyname("hw.physmem", &memory, &len, NULL, 0);
 
20
  
 
21
    // Numerical values
 
22
 
 
23
    // total physical memory (without swap space)
 
24
    memoryInfos[TOTAL_MEM] = MEMORY(memory);
 
25
 
 
26
    unsigned int cached;
 
27
    len = sizeof(cached);
 
28
    if (sysctlbyname("vm.stats.vm.v_cache_count", &cached, &len, NULL, 0) == -1 || !len)
 
29
        memoryInfos[CACHED_MEM] = NO_MEMORY_INFO;
 
30
    else
 
31
        memoryInfos[CACHED_MEM] = MEMORY(cached) * PAGE_SIZE;
 
32
 
 
33
    unsigned int free;
 
34
    len = sizeof(free);
 
35
    if (sysctlbyname("vm.stats.vm.v_free_count", &free, &len, NULL, 0) == -1 || !len)
 
36
        memoryInfos[FREE_MEM] = NO_MEMORY_INFO;
 
37
    else
 
38
        memoryInfos[FREE_MEM] = MEMORY(free) * PAGE_SIZE;
 
39
 
 
40
    // added by Brad Hughes bhughes@trolltech.com
 
41
    struct vmtotal vmem;
 
42
 
 
43
    len = sizeof(vmem);
 
44
    if (sysctlbyname("vm.vmtotal", &vmem, &len, NULL, 0) == -1 || !len)
 
45
        memoryInfos[SHARED_MEM] = NO_MEMORY_INFO;
 
46
    else
 
47
         memoryInfos[SHARED_MEM] = MEMORY(vmem.t_armshr) * PAGE_SIZE;
 
48
 
 
49
    long buffers;
 
50
    len = sizeof(buffers);
 
51
    if ((sysctlbyname("vfs.bufspace", &buffers, &len, NULL, 0) == -1) || !len)
 
52
        memoryInfos[BUFFER_MEM] = NO_MEMORY_INFO;
 
53
    else
 
54
        memoryInfos[BUFFER_MEM] = MEMORY(buffers);
 
55
 
 
56
    struct kvm_swap swap[1];
 
57
    kvm_t *kvm_handle;
 
58
    kvm_handle = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
 
59
 
 
60
    if (kvm_handle != NULL && kvm_getswapinfo(kvm_handle, swap, 1, 0) != -1) {
 
61
        memoryInfos[SWAP_MEM]     = MEMORY(swap[0].ksw_total) * PAGE_SIZE;
 
62
        memoryInfos[FREESWAP_MEM] = MEMORY(swap[0].ksw_total - swap[0].ksw_used) * PAGE_SIZE;
 
63
    }
 
64
 
 
65
    if (kvm_handle != NULL)
 
66
        kvm_close(kvm_handle);
 
67
}