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

« back to all changes in this revision

Viewing changes to ksysguard/ksysguardd/Irix/Memory.c

  • 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
    KSysGuard, the KDE System Guard
 
3
   
 
4
        Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
 
5
        
 
6
        Irix support by Carsten Kroll <ckroll@pinnaclesys.com>
 
7
    
 
8
    This program is free software; you can redistribute it and/or
 
9
    modify it under the terms of version 2 of the GNU General Public
 
10
    License as published by the Free Software Foundation.
 
11
 
 
12
    This program is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
    GNU General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU General Public License
 
18
    along with this program; if not, write to the Free Software
 
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
 
 
21
*/
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <unistd.h>
 
26
#include <sys/types.h>
 
27
#include <sys/statfs.h>
 
28
#include <sys/swap.h>
 
29
#include <sys/sysmp.h>
 
30
 
 
31
#include "config.h"
 
32
 
 
33
#include "ksysguardd.h"
 
34
#include "Command.h"
 
35
#include "Memory.h"
 
36
 
 
37
static int Dirty = 1;
 
38
static t_memsize totalmem = (t_memsize) 0;
 
39
static t_memsize freemem = (t_memsize) 0;
 
40
static unsigned long totalswap = 0L,vswap = 0L;
 
41
static unsigned long freeswap  = 0L,bufmem = 0L ;
 
42
 
 
43
void initMemory( struct SensorModul* sm ) {
 
44
 
 
45
        registerMonitor( "mem/physical/free", "integer",
 
46
                                        printMemFree, printMemFreeInfo, sm );
 
47
        registerMonitor( "mem/physical/used", "integer",
 
48
                                        printMemUsed, printMemUsedInfo, sm );
 
49
        registerMonitor( "mem/swap/free", "integer",
 
50
                                        printSwapFree, printSwapFreeInfo, sm );
 
51
        registerMonitor( "mem/swap/used", "integer",
 
52
                                        printSwapUsed, printSwapUsedInfo, sm );
 
53
}
 
54
 
 
55
void exitMemory( void ) {
 
56
}
 
57
 
 
58
int updateMemory( void ) {
 
59
        struct statfs sf;
 
60
        off_t val;
 
61
        int pagesize = getpagesize();
 
62
        struct rminfo rmi;
 
63
        if( sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) == -1 )
 
64
                return( -1 );
 
65
        totalmem  = rmi.physmem*pagesize/1024; // total physical memory (without swaps)
 
66
        freemem   = rmi.freemem*pagesize/1024; // total free physical memory (without swaps)
 
67
        bufmem    = rmi.bufmem *pagesize/1024;
 
68
 
 
69
        statfs ("/proc", &sf,sizeof(sf),0);
 
70
 
 
71
        swapctl(SC_GETSWAPVIRT,&val);
 
72
        vswap = val >> 1;
 
73
        swapctl(SC_GETSWAPTOT,&val);
 
74
        totalswap = val >> 1;
 
75
        swapctl(SC_GETFREESWAP,&val);
 
76
        freeswap = val >> 1;
 
77
 
 
78
        Dirty = 1;
 
79
 
 
80
        return( 0 );
 
81
}
 
82
 
 
83
void printMemFreeInfo( const char *cmd ) {
 
84
        if( Dirty )
 
85
                updateMemory();
 
86
        fprintf(CurrentClient, "Free Memory\t0\t%ld\tKB\n", freemem );
 
87
}
 
88
 
 
89
void printMemFree( const char *cmd ) {
 
90
        if( Dirty )
 
91
                updateMemory();
 
92
        fprintf(CurrentClient, "%ld\n", freemem );
 
93
}
 
94
 
 
95
void printMemUsedInfo( const char *cmd ) {
 
96
        if( Dirty )
 
97
                updateMemory();
 
98
        fprintf(CurrentClient, "Used Memory\t0\t%ld\tKB\n", totalmem - freemem );
 
99
}
 
100
 
 
101
void printMemUsed( const char *cmd ) {
 
102
        if( Dirty )
 
103
                updateMemory();
 
104
        fprintf(CurrentClient, "%ld\n", totalmem - freemem );
 
105
}
 
106
 
 
107
void printSwapFreeInfo( const char *cmd ) {
 
108
        if( Dirty )
 
109
                updateMemory();
 
110
        fprintf(CurrentClient, "Free Swap\t0\t%ld\tKB\n", freeswap );
 
111
}
 
112
 
 
113
void printSwapFree( const char *cmd ) {
 
114
        if( Dirty )
 
115
                updateMemory();
 
116
        fprintf(CurrentClient, "%ld\n", freeswap );
 
117
}
 
118
void printSwapUsedInfo( const char *cmd ) {
 
119
        if( Dirty )
 
120
                updateMemory();
 
121
        fprintf(CurrentClient, "Used Swap\t0\t%ld\tKB\n", totalswap - freeswap );
 
122
}
 
123
 
 
124
void printSwapUsed( const char *cmd ) {
 
125
        if( Dirty )
 
126
                updateMemory();
 
127
        fprintf(CurrentClient, "%ld\n", totalswap - freeswap );
 
128
}