Peano 4
Loading...
Searching...
No Matches
LogFilter.cpp
Go to the documentation of this file.
1#include "tarch/Assertions.h"
2
3#include "tarch/mpi/Rank.h"
4
5#include <sstream>
6#include <iostream>
7#include "LogFilter.h"
8
9#if defined(UseLikwid)
10#include <likwid.h>
11#endif
12
14
20
21const std::string tarch::logging::LogFilter::FilterListEntry::AlwaysOn = "always-on";
22
25
26tarch::logging::LogFilter::FilterListEntry::FilterListEntry( const std::string& targetName, bool isBlackListEntry ):
27 _targetName(targetName),
28 _rank(AnyRank),
29 _namespaceName(""),
30 _isBlackEntry(isBlackListEntry),
31 _programPhase(AlwaysOn) {
32 assertion1( targetName==TargetWarning or targetName==TargetInfo or targetName==TargetDebug or targetName==TargetAll or targetName==TargetTrace, targetName );
33}
34
35tarch::logging::LogFilter::FilterListEntry::FilterListEntry( const std::string& targetName, int rank, const std::string& className, bool isBlackListEntry, const std::string& programPhase ):
36 _targetName(targetName),
37 _rank(rank),
38 _namespaceName(className),
39 _isBlackEntry(isBlackListEntry),
40 _programPhase(programPhase) {
41 assertion1( targetName==TargetWarning or targetName==TargetInfo or targetName==TargetDebug or targetName==TargetAll or targetName==TargetTrace, targetName );
42}
43
45 std::ostringstream msg;
46 msg << "(";
47 msg << "target:" << _targetName << ",";
48 msg << _namespaceName << ",";
49 #ifdef Parallel
50 msg << "rank:" << _rank;
51 msg << ",";
52 #endif
53 if (_isBlackEntry) {
54 msg << "blacklist-entry";
55 }
56 else {
57 msg << "whitelist-entry";
58 }
59 msg << ",phase:" << _programPhase;
60 msg << ")";
61 return msg.str();
62}
63
65 return _rank < b._rank
66 or _namespaceName < b._namespaceName
67 or _targetName < b._targetName
68 or _programPhase < b._programPhase;
69}
70
72 return _rank == b._rank
73 and _namespaceName == b._namespaceName
74 and _targetName == b._targetName
75 and _programPhase == b._programPhase;
76}
77
81
83 _activeProgramPhase("undef") {
85 #if defined(UseLikwid)
86 likwid_markerInit();
87 likwid_markerStartRegion( _activeProgramPhase.c_str() );
88 #endif
89}
90
92 #if defined(UseLikwid)
93 likwid_markerStopRegion( _activeProgramPhase.c_str() );
94 likwid_markerClose();
95 #endif
96}
97
99 if (_filterlist.empty()) {
100 std::cout << "filter list is empty" << std::endl;
101 } else {
102 std::cout << "filter list is not empty and contains " << _filterlist.size() << " entries" << std::endl;
103 for (FilterList::const_iterator p = _filterlist.begin(); p!=_filterlist.end(); p++ ) {
104 std::cout << p->toString() << std::endl;
105 }
106 }
107}
108
110 static LogFilter* _singleton = new LogFilter();
111 return *_singleton;
112}
113
114void tarch::logging::LogFilter::switchProgramPhase(const std::string& activeProgramPhase) {
115 #if PeanoDebug>=4
116 std::cout << "switch program phase to " << activeProgramPhase << " and, hence, activate potentially different filter set" << std::endl;
117 #endif
118
119 _activeProgramPhase = activeProgramPhase;
120
121 #if defined(UseLikwid)
122 likwid_markerStopRegion( _activeProgramPhase.c_str() );
123 likwid_markerStartRegion( _activeProgramPhase.c_str() );
124 #endif
125}
126
127bool tarch::logging::LogFilter::writeDebug([[maybe_unused]] const std::string& className) {
128 #if PeanoDebug>=4
129 return !filterOut(FilterListEntry::TargetDebug,className);
130 #else
131 return false;
132 #endif
133}
134
135bool tarch::logging::LogFilter::writeInfo(const std::string& className) {
136 return !filterOut(FilterListEntry::TargetInfo,className);
137}
138
139bool tarch::logging::LogFilter::writeWarning(const std::string& className) {
140 return !filterOut(FilterListEntry::TargetWarning,className);
141}
142
143bool tarch::logging::LogFilter::writeTrace([[maybe_unused]] const std::string& className) {
144 #if PeanoDebug>=1
145 const bool result = !filterOut(FilterListEntry::TargetTrace,className);
146 return result;
147 #else
148 return false;
149 #endif
150}
151
153 for (FilterList::const_iterator p = entries.begin(); p!=entries.end(); p++ ) {
154 addFilterListEntry(*p);
155 }
156}
157
159 _filterlist.clear();
160}
161
163 const std::string& targetName,
164 const std::string& className
165) {
166 bool result = false;
167 bool foundRule = false;
168 int lengthActive = 0;
169 for (FilterList::const_iterator p = _filterlist.begin(); p!=_filterlist.end(); p++ ) {
170 int length = static_cast<int>(p->_namespaceName.size());
171 if ( length >= lengthActive ) {
172 if (
173 ( targetName == p->_targetName or p->_targetName==FilterListEntry::TargetAll )
174 and
175 ( _activeProgramPhase.find( p->_programPhase,0 )==0 or p->_programPhase==FilterListEntry::AlwaysOn )
176 and
177 ( className.find(p->_namespaceName,0)==0 )
178 #ifdef Parallel
179 and
180 (p->_rank == FilterListEntry::AnyRank || p->_rank == tarch::mpi::Rank::getInstance().getRank())
181 #endif
182 ) {
183 lengthActive = length;
184 result = p->_isBlackEntry;
185 foundRule = true;
186 }
187 }
188 }
189
190 if (!foundRule) {
191 std::cerr << "did not find filter rule for target \"" << targetName << "\" and class \"" << className << "\" on rank " << tarch::mpi::Rank::getInstance().getRank() << std::endl;
192 }
193 return result;
194}
195
197 if (_filterlist.count(entry)!=0) {
198 std::cerr << "tried to insert log filter " << entry.toString() << " multiple times" << std::endl;
199 assertion(false);
200 } else {
201 _filterlist.insert( entry );
202 }
203}
#define assertion1(expr, param)
#define assertion(expr)
bool operator==(const swift2::TaskNumber &lhs, const swift2::TaskNumber &rhs)
Peano4's log filter is used by every single log instance.
Definition LogFilter.h:20
void addFilterListEntry(const FilterListEntry &entry)
Add one filter list entry.
bool writeInfo(const std::string &trace)
std::set< FilterListEntry > FilterList
Definition LogFilter.h:89
bool writeWarning(const std::string &trace)
bool writeDebug(const std::string &trace)
void printFilterListToCout() const
Definition LogFilter.cpp:98
void switchProgramPhase(const std::string &activeProgramPhase)
void addFilterListEntries(const FilterList &entries)
LogFilter()
By default, everything is on.
Definition LogFilter.cpp:82
std::string _activeProgramPhase
Definition LogFilter.h:22
bool writeTrace(const std::string &trace)
static LogFilter & getInstance()
bool filterOut(const std::string &targetName, const std::string &className)
May not be const as it might write a warning itself.
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
int getRank() const
Return rank of this node.
Definition Rank.cpp:528
Represents one entry of the filter list.
Definition LogFilter.h:30
static const std::string TargetTrace
Definition LogFilter.h:36
static const std::string TargetDebug
Definition LogFilter.h:35
static const std::string TargetInfo
Definition LogFilter.h:34
bool operator!=(const FilterListEntry &b) const
Definition LogFilter.cpp:78
bool operator<(const FilterListEntry &b) const
Definition LogFilter.cpp:64
static const std::string TargetAll
Definition LogFilter.h:33
static const std::string AlwaysOn
Definition LogFilter.h:39
static const std::string TargetWarning
Definition LogFilter.h:37
FilterListEntry(const std::string &targetName="", bool isBlackListEntry=false)
Construct filter list entry for one target without any.
Definition LogFilter.cpp:26
bool operator==(const FilterListEntry &b) const
Definition LogFilter.cpp:71