"Fossies" - the Fresh Open Source Software Archive 
Member "xosview-1.23/gnu/pagemeter.cc" (11 Jul 2020, 2277 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 "pagemeter.cc" see the
Fossies "Dox" file reference documentation.
1 //
2 // Copyright (c) 1996, 2004 by Massimiliano Ghilardi ( ghilardi@cibs.sns.it )
3 // 2007 by Samuel Thibault ( samuel.thibault@ens-lyon.org )
4 //
5 // This file may be distributed under terms of the GPL
6 //
7
8 #include "pagemeter.h"
9 #include "xosview.h"
10 #include <fstream>
11 #include <stdlib.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <error.h>
16
17 extern "C" {
18 #include <mach/mach_traps.h>
19 #include <mach/mach_interface.h>
20 }
21
22 PageMeter::PageMeter( XOSView *parent, float max )
23 : FieldMeterGraph( parent, 3, "PAGE", "IN/OUT/IDLE" ) {
24 for ( int i = 0 ; i < 2 ; i++ )
25 for ( int j = 0 ; j < 2 ; j++ )
26 pageinfo_[j][i] = 0;
27
28 maxspeed_ = max;
29 pageindex_ = 0;
30 }
31
32 PageMeter::~PageMeter( void ){
33 }
34
35 void PageMeter::checkResources( void ){
36 FieldMeterGraph::checkResources();
37
38 setfieldcolor( 0, parent_->getResource( "pageInColor" ) );
39 setfieldcolor( 1, parent_->getResource( "pageOutColor" ) );
40 setfieldcolor( 2, parent_->getResource( "pageIdleColor" ) );
41 priority_ = atoi (parent_->getResource( "pagePriority" ) );
42 maxspeed_ *= priority_ / 10.0;
43 dodecay_ = parent_->isResourceTrue( "pageDecay" );
44 useGraph_ = parent_->isResourceTrue( "pageGraph" );
45 SetUsedFormat (parent_->getResource("pageUsedFormat"));
46 }
47
48 void PageMeter::checkevent( void ){
49 getpageinfo();
50 drawfields();
51 }
52
53 void PageMeter::updateinfo(void)
54 {
55 int oldindex = (pageindex_+1)%2;
56 for ( int i = 0; i < 2; i++ )
57 {
58 if ( pageinfo_[oldindex][i] == 0 )
59 pageinfo_[oldindex][i] = pageinfo_[pageindex_][i];
60
61 fields_[i] = pageinfo_[pageindex_][i] - pageinfo_[oldindex][i];
62 total_ += fields_[i];
63 }
64
65 if ( total_ > maxspeed_ )
66 fields_[2] = 0.0;
67 else
68 {
69 fields_[2] = maxspeed_ - total_;
70 total_ = maxspeed_;
71 }
72
73 setUsed (total_ - fields_[2], maxspeed_);
74 pageindex_ = (pageindex_ + 1) % 2;
75 }
76
77 void PageMeter::getpageinfo(void) {
78 struct vm_statistics vmstats;
79
80 total_ = 0;
81 kern_return_t err;
82
83 err = vm_statistics (mach_task_self(), &vmstats);
84 if (err) {
85 error (0, err, "vm_statistics");
86 parent_->done(1);
87 return;
88 }
89
90 pageinfo_[pageindex_][0] = vmstats.pageins;
91 pageinfo_[pageindex_][1] = vmstats.pageouts;
92
93 updateinfo();
94 }