~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kcontrol/infocenter/info/memory_fbsd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <sys/types.h>
 
3
#include <sys/sysctl.h>
 
4
#include <sys/vmmeter.h>
 
5
 
 
6
#include <vm/vm_param.h>
 
7
 
 
8
#include <stdlib.h>
 
9
#include <stdio.h>
 
10
#include <unistd.h>
 
11
 
 
12
void KMemoryWidget::update()
 
13
{
 
14
    char blah[10], buf[80], *used_str, *total_str;
 
15
    /* Stuff for sysctl */
 
16
    int memory;
 
17
    size_t len;
 
18
    /* Stuff for swap display */
 
19
    int used, total, _free;
 
20
    FILE *pipe;
 
21
 
 
22
    len=sizeof(memory);
 
23
    sysctlbyname("hw.physmem", &memory, &len, NULL, 0);
 
24
  
 
25
    snprintf(blah, 10, "%d", memory);
 
26
    // Numerical values
 
27
 
 
28
    // total physical memory (without swap space)
 
29
    Memory_Info[TOTAL_MEM] = MEMORY(memory);
 
30
 
 
31
    // added by Brad Hughes bhughes@trolltech.com
 
32
    struct vmtotal vmem;
 
33
#ifdef __GNUC__ 
 
34
    #warning "FIXME: Memory_Info[CACHED_MEM]"
 
35
#endif    
 
36
    Memory_Info[CACHED_MEM] = NO_MEMORY_INFO;
 
37
 
 
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.
 
43
 
 
44
    len = sizeof(vmem);
 
45
    if (sysctlbyname("vm.vmmeter", &vmem, &len, NULL, 0) == 0) 
 
46
        Memory_Info[SHARED_MEM]   = MEMORY(vmem.t_armshr) * PAGE_SIZE;
 
47
    else 
 
48
        Memory_Info[SHARED_MEM]   = NO_MEMORY_INFO;
 
49
 
 
50
    int buffers;
 
51
    len = sizeof (buffers);
 
52
    if ((sysctlbyname("vfs.bufspace", &buffers, &len, NULL, 0) == -1) || !len)
 
53
        Memory_Info[BUFFER_MEM]   = NO_MEMORY_INFO;
 
54
    else
 
55
        Memory_Info[BUFFER_MEM]   = MEMORY(buffers);
 
56
 
 
57
    // total free physical memory (without swap space)
 
58
    int free;
 
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;
 
62
    else
 
63
        Memory_Info[FREE_MEM]     = MEMORY(free) * getpagesize();
 
64
 
 
65
    // Q&D hack for swap display. Borrowed from xsysinfo-1.4
 
66
    if ((pipe = popen("/usr/sbin/pstat -ks", "r")) == NULL) {
 
67
        used = total = 1;
 
68
        return;
 
69
    }
 
70
 
 
71
    fgets(buf, sizeof(buf), pipe);
 
72
    fgets(buf, sizeof(buf), pipe);
 
73
    fgets(buf, sizeof(buf), pipe);
 
74
    fgets(buf, sizeof(buf), pipe);
 
75
    pclose(pipe);
 
76
 
 
77
    strtok(buf, " ");
 
78
    total_str = strtok(NULL, " ");
 
79
    used_str = strtok(NULL, " ");
 
80
    used = atoi(used_str);
 
81
    total = atoi(total_str);
 
82
 
 
83
    _free=total-used;
 
84
 
 
85
    // total size of all swap-partitions
 
86
    Memory_Info[SWAP_MEM] = MEMORY(total) * 1024;
 
87
 
 
88
    // free memory in swap-partitions
 
89
    Memory_Info[FREESWAP_MEM] = MEMORY(_free) * 1024;
 
90
}