"Fossies" - the Fresh Open Source Software Archive 
Member "xosview-1.23/irix65/loadmeter.cc" (11 Jul 2020, 3434 Bytes) of package /linux/misc/xosview-1.23.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "loadmeter.cc" see the
Fossies "Dox" file reference documentation.
1 //
2 // Copyright (c) 1994, 1995 by Mike Romberg ( romberg@fsl.noaa.gov )
3 //
4 // This file may be distributed under terms of the GPL
5 //
6 // Most of this code was written by Werner Fink <werner@suse.de>.
7 // Only small changes were made on my part (M.R.)
8 // Small changes for Irix 6.5 port Stefan Eilemann <eilemann@gmail.com>
9 //
10
11 #include "loadmeter.h"
12 #include "xosview.h"
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <iostream>
16
17 #ifndef FSCALE
18 #define FSCALE (1 << 8)
19 #endif
20
21 using namespace std;
22
23 LoadMeter::LoadMeter(XOSView *parent)
24 : FieldMeterGraph( parent, 2, "LOAD", "PROCS/MIN", 1, 1, 0 )
25 {
26 lastalarmstate = -1;
27 total_ = 2.0;
28
29 if (gethostname (hostname, 255) != 0) {
30 perror ("gethostname");
31 parent_->done(1);
32 return;
33 }
34 }
35
36 LoadMeter::~LoadMeter(void)
37 {
38 }
39
40 void LoadMeter::checkResources(void)
41 {
42 FieldMeterGraph::checkResources();
43
44 procloadcol_ = parent_->allocColor(parent_->getResource( "loadProcColor" ));
45 warnloadcol_ = parent_->allocColor(parent_->getResource( "loadWarnColor" ));
46 critloadcol_ = parent_->allocColor(parent_->getResource( "loadCritColor" ));
47
48 setfieldcolor(0, parent_->getResource( "loadProcColor" ));
49 setfieldcolor(1, parent_->getResource("loadIdleColor"));
50 priority_ = atoi (parent_->getResource("loadPriority"));
51 useGraph_ = parent_->isResourceTrue("loadGraph");
52 dodecay_ = parent_->isResourceTrue( "loadDecay" );
53 SetUsedFormat(parent_->getResource("loadUsedFormat"));
54
55 warnThreshold = atoi (parent_->getResource("loadWarnThreshold"));
56 critThreshold = atoi (parent_->getResource("loadCritThreshold"));
57
58
59 if (dodecay_){
60 // Warning: Since the loadmeter changes scale occasionally, old
61 // decay values need to be rescaled. However, if they are rescaled,
62 // they could go off the edge of the screen. Thus, for now, to
63 // prevent this whole problem, the load meter can not be a decay
64 // meter. The load is a decaying average kind of thing anyway,
65 // so having a decaying load average is redundant.
66 std::cerr << "Warning: The loadmeter can not be configured as a decay\n"
67 << " meter. See the source code (" <<__FILE__<< ") for further\n"
68 << " details.\n";
69 dodecay_ = 0;
70 }
71 }
72
73 void LoadMeter::checkevent(void)
74 {
75 getloadinfo();
76 drawfields();
77 }
78
79 void LoadMeter::getloadinfo(void)
80 {
81 if (rstat (hostname, &res) != 0) {
82 std::cerr << hostname <<endl;
83 perror ("rstat");
84 return;
85 }
86
87 fields_[0] = (float) res.avenrun[0]/FSCALE;
88
89 if ( fields_[0] < warnThreshold )
90 alarmstate = 0;
91 else
92 if ( fields_[0] >= critThreshold )
93 alarmstate = 2;
94 else
95 alarmstate = 1;
96
97 if ( alarmstate != lastalarmstate )
98 {
99 if ( alarmstate == 0 )
100 setfieldcolor( 0, procloadcol_ );
101 else
102 if ( alarmstate == 1 )
103 setfieldcolor( 0, warnloadcol_ );
104 else
105 setfieldcolor( 0, critloadcol_ );
106 drawlegend();
107 lastalarmstate = alarmstate;
108 }
109
110 if ( fields_[0]*5.0<total_ )
111 total_ = fields_[0];
112 else
113 if ( fields_[0]>total_ )
114 total_ = fields_[0]*5.0;
115
116 if ( total_ < 1.0)
117 total_ = 1.0;
118
119 fields_[1] = (float) (total_ - fields_[0]);
120
121 setUsed(fields_[0], (float) 1.0);
122 }