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

« back to all changes in this revision

Viewing changes to ksysguard/ksysguardd/Solaris/LoadAvg.c

  • 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
    KSysGuard, the KDE System Guard
 
3
   
 
4
        Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
 
5
 
 
6
        Solaris support by Torsten Kasch <tk@Genetik.Uni-Bielefeld.DE>
 
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/stat.h>
 
27
 
 
28
#include "config.h"
 
29
 
 
30
#ifdef HAVE_KSTAT
 
31
#include <kstat.h>
 
32
#endif
 
33
 
 
34
#include "ksysguardd.h"
 
35
#include "Command.h"
 
36
#include "LoadAvg.h"
 
37
 
 
38
double loadavg1 = 0.0;
 
39
double loadavg5 = 0.0;
 
40
double loadavg15 = 0.0;
 
41
 
 
42
void initLoadAvg( struct SensorModul* sm ) {
 
43
#ifdef HAVE_KSTAT
 
44
        registerMonitor( "cpu/loadavg1", "float",
 
45
                                        printLoadAvg1, printLoadAvg1Info, sm );
 
46
        registerMonitor( "cpu/loadavg5", "float",
 
47
                                        printLoadAvg5, printLoadAvg5Info, sm );
 
48
        registerMonitor( "cpu/loadavg15", "float",
 
49
                                        printLoadAvg15, printLoadAvg15Info, sm );
 
50
#endif
 
51
}
 
52
 
 
53
void exitLoadAvg( void ) {
 
54
}
 
55
 
 
56
int updateLoadAvg( void ) {
 
57
 
 
58
#ifdef HAVE_KSTAT
 
59
        kstat_ctl_t             *kctl;
 
60
        kstat_t                 *ksp;
 
61
        kstat_named_t           *kdata;
 
62
 
 
63
        /*
 
64
         *  get a kstat handle and update the user's kstat chain
 
65
         */
 
66
        if( (kctl = kstat_open()) == NULL )
 
67
                return( 0 );
 
68
        while( kstat_chain_update( kctl ) != 0 )
 
69
                ;
 
70
 
 
71
        /*
 
72
         *  traverse the kstat chain to find the appropriate statistics
 
73
         */
 
74
        if( (ksp = kstat_lookup( kctl, "unix", 0, "system_misc" )) == NULL )
 
75
                return( 0 );
 
76
        if( kstat_read( kctl, ksp, NULL ) == -1 )
 
77
                return( 0 );
 
78
 
 
79
        /*
 
80
         *  lookup the data
 
81
         */
 
82
         kdata = (kstat_named_t *) kstat_data_lookup( ksp, "avenrun_1min" );
 
83
         if( kdata != NULL )
 
84
                loadavg1 = LOAD( kdata->value.ui32 );
 
85
         kdata = (kstat_named_t *) kstat_data_lookup( ksp, "avenrun_5min" );
 
86
         if( kdata != NULL )
 
87
                loadavg5 = LOAD( kdata->value.ui32 );
 
88
         kdata = (kstat_named_t *) kstat_data_lookup( ksp, "avenrun_15min" );
 
89
         if( kdata != NULL )
 
90
                loadavg15 = LOAD( kdata->value.ui32 );
 
91
 
 
92
        kstat_close( kctl );
 
93
#endif /* ! HAVE_KSTAT */
 
94
 
 
95
        return( 0 );
 
96
}
 
97
 
 
98
void printLoadAvg1Info( const char *cmd ) {
 
99
        fprintf(CurrentClient, "avnrun 1min\t0\t0\n" );
 
100
}
 
101
 
 
102
void printLoadAvg1( const char *cmd ) {
 
103
        fprintf(CurrentClient, "%f\n", loadavg1 );
 
104
}
 
105
 
 
106
void printLoadAvg5Info( const char *cmd ) {
 
107
        fprintf(CurrentClient, "avnrun 5min\t0\t0\n" );
 
108
}
 
109
 
 
110
void printLoadAvg5( const char *cmd ) {
 
111
        fprintf(CurrentClient, "%f\n", loadavg5 );
 
112
}
 
113
 
 
114
void printLoadAvg15Info( const char *cmd ) {
 
115
        fprintf(CurrentClient, "avnrun 15min\t0\t0\n" );
 
116
}
 
117
 
 
118
void printLoadAvg15( const char *cmd ) {
 
119
        fprintf(CurrentClient, "%f\n", loadavg15 );
 
120
}