ls1-MarDyn
ls1-MarDyn molecular dynamics code
SysMon.h
Go to the documentation of this file.
1
6#ifndef SYSMON_H
7#define SYSMON_H
8
9/*#define ENABLE_MPI*/
10
11#ifdef _POSIX_VERSION
12#define SYSMON_ENABLE_SYSCONF
13#endif
14#ifdef __linux__
15#define SYSMON_ENABLE_SYSINFO
16#endif
17#define SYSMON_ENABLE_MALLINFO
18#define SYSMON_ENABLE_PROCMEMINFO
19#define SYSMON_ENABLE_PROCVMSTAT
20#define SYSMON_ENABLE_PROCLOADAVG
21#define SYSMON_ENABLE_PROCSELFSTATM
22#define SYSMON_ENABLE_PROCSELFSCHED
23//#define SYSMON_ENABLE_PROCSELFSCHEDSTAT
24#define SYSMON_ENABLE_PROCSELFSTATUS
25
26#include <string>
27#include <vector>
28#include <list>
29#include <set>
30#include <map>
31#include <iostream>
32#include <utility>
33
34#include <cmath>
35
36
37#ifdef ENABLE_MPI
38#include <mpi.h>
39#endif
40
41#ifdef SYSMON_ENABLE_SYSCONF
42#include <unistd.h> // sysconf, sync; see http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
43#endif
44
45#ifdef SYSMON_ENABLE_SYSINFO
46#include <sys/sysinfo.h>
47#endif
48
49#ifdef SYSMON_ENABLE_MALLINFO
50#include <malloc.h> // mallinfo
51#endif
52
53
54#include "Expression.h"
55
56// SysMon ------------------------------------------------------------------------------------------
57class SysMon{
58public:
59 typedef double Tvalue;
60#ifdef MPI_VERSION
61 static const MPI_Datatype mpiTvalue;
62 static const int mpiRootRank;
63#endif
64
65private: // Singleton
66 static SysMon* s_sysmoninstance;
67 SysMon(const SysMon&);
68#ifdef MPI_VERSION
69 SysMon(MPI_Comm mpicomm=MPI_COMM_WORLD) : _mpicomm(mpicomm) { _variableset=new Expression::VariableSet(); }
70#else
71 SysMon() { _variableset=new Expression::VariableSet(); }
72#endif
73 ~~SysMon() { clear(); delete(_variableset); s_sysmoninstance=NULL; }
74
75public:
76 static SysMon* getSysMon()
77 {
78 if(s_sysmoninstance==NULL)
79 s_sysmoninstance = new SysMon();
80 return s_sysmoninstance;
81 }
82
83 void clear();
84 int addExpression(const std::string& exprstr);
85 int addExpression(const std::string& exprstr, const std::string& label)
86 { int idx=addExpression(exprstr); if(idx>=0) _expressions.back().setLabel(label); return idx; }
87 unsigned int numExpressions() { return _expressions.size(); }
88 void updateExpressionValues(bool resetMinMax=false);
89 int getExpressionIndex(const std::string& label) const;
90 Tvalue getExpressionValue(unsigned int index) const
91 { if(index<_values.size()) return _values[index]; else return Tvalue(); }
92 std::pair<Tvalue,Tvalue> getExpressionMinMaxPeakValues(unsigned int index) const
93 { if(index*2+1<_valuesMaxMinPeak.size()) return std::make_pair(_valuesMaxMinPeak[index*2],_valuesMaxMinPeak[index*2+1]); else return std::make_pair(0,0); }
94#ifdef MPI_VERSION
95 std::pair<Tvalue,Tvalue> getExpressionMinMaxValues(unsigned int index) const;
96#endif
97 void writeExpressionValues(std::ostream& ostrm=std::cout
98 , std::string header=std::string()
99 , std::string lineprefix=std::string()
100 , std::string sep=std::string("\t")
101 , std::string eol=std::string("\n")
102 ) const;
103 std::string InfoString(std::string header=std::string()
104 , std::string lineprefix=std::string()
105 , std::string sep=std::string("\t")
106 , std::string eol=std::string("\n")
107 ) const
108 {
109 std::ostringstream oss;
110 writeExpressionValues(oss,header,lineprefix,sep,eol);
111 return oss.str();
112 }
113 operator std::string() const { return InfoString(); }
114
115private:
116 Expression::VariableSet* _variableset;
117 std::list<Expression> _expressions;
118 std::vector<Tvalue> _values;
119 std::vector<bool> _initMinMax;
120 // *valuesMaxMin* stores for each value (i) the
121 // maximum (2*i) and negative minimum (=maximum of negative value) (2*i+1)
122 std::vector<Tvalue> _valuesMaxMinPeak;
123#ifdef MPI_VERSION
124 std::vector<Tvalue> _valuesMaxMin;
125 MPI_Comm _mpicomm;
126#endif
127
128private:
129 unsigned int updateVariables_sysconf();
130 unsigned int updateVariables_sysinfo();
131 unsigned int updateVariables_mallinfo();
132 unsigned int updateVariables_procmeminfo();
133 unsigned int updateVariables_procvmstat();
134 unsigned int updateVariables_procloadavg();
135 unsigned int updateVariables_procselfstatm();
136 unsigned int updateVariables_procselfschedstat();
137 unsigned int updateVariables_procselfsched();
138 unsigned int updateVariables_procselfstatus();
139};
140// ------------------------------------------------------------------------------------------ SysMon
141
142
143inline std::ostream& operator << (std::ostream& ostrm, const SysMon& s)
144{
145 s.writeExpressionValues(ostrm);
146 return ostrm;
147}
148
149#endif
Expression (tree) with variables.
Definition: Expression.h:240
Definition: SysMon.h:57
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270