libmesh_logging.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_LIBMESH_LOGGING_H
21 #define LIBMESH_LIBMESH_LOGGING_H
22 
23 
24 // The library configuration options
25 #include "libmesh/libmesh_common.h"
26 
27 #include "libmesh/perf_log.h"
28 
29 // Two-level macro substitution trick, used to construct a unique
30 // variable name for a given line.
31 #define TOKENPASTE(x, y) x ## y
32 #define TOKENPASTE2(x, y) TOKENPASTE(x, y)
33 
34 namespace libMesh
35 {
36 
37 
38 // Forward declaration, required when included
39 // in perf_log.{C,h} because the preceding
40 // #include "libmesh/perf_log.h" is ineffective.
41 // Multiple inclusion avoidance problem...
42 // LIBMESH_PERF_LOG_H already #define'd, but the
43 // class has not been declared yet!.
44 class PerfLog;
45 
50 extern PerfLog perflog;
51 
52 
64 struct PerfItem
65 {
66  PerfItem(const char * label,
67  const char * header,
68  bool enabled=true) :
69  _label(label),
70  _header(header),
71  _enabled(enabled)
72  {
73  if (_enabled)
74  libMesh::perflog.fast_push(label, header);
75  }
76 
78  {
79  if (_enabled)
81  }
82 
83 private:
84  const char * _label;
85  const char * _header;
86  bool _enabled;
87 };
88 
89 
90 
91 } // namespace libMesh
92 
93 
94 
95 // Macros for performance logging. This allows us
96 // to add performance monitors to the code without
97 // impacting performance when performance logging
98 // is disabled.
99 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
100 
101 # define START_LOG(a,b) { libMesh::perflog.push(a,b); }
102 # define STOP_LOG(a,b) { libMesh::perflog.pop(a,b); }
103 #ifdef LIBMESH_ENABLE_DEPRECATED
104 # define PALIBMESH_USE_LOG(a,b) { libmesh_deprecated(); }
105 # define RESTART_LOG(a,b) { libmesh_deprecated(); }
106 #endif
107 # define LOG_SCOPE(a,b) libMesh::PerfItem TOKENPASTE2(perf_item_, __LINE__)(a,b);
108 # define LOG_SCOPE_IF(a,b,enabled) libMesh::PerfItem TOKENPASTE2(perf_item_, __LINE__)(a,b,enabled);
109 
110 #else
111 
112 # define START_LOG(a,b) {}
113 # define STOP_LOG(a,b) {}
114 # define PALIBMESH_USE_LOG(a,b) {}
115 # define RESTART_LOG(a,b) {}
116 # define LOG_SCOPE(a,b) {}
117 # define LOG_SCOPE_IF(a,b,enabled) {}
118 
119 #endif
120 
121 
122 
123 
124 
125 #endif // LIBMESH_LIBMESH_LOGGING_H
void fast_push(const char *label, const char *header="")
Definition: perf_log.h:466
PerfLog perflog("libMesh", #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING true #else false #endif)
const char * _header
Responsible for timing and summarizing events.
Definition: perf_log.h:125
void fast_pop(const char *label, const char *header="")
Definition: perf_log.h:486
PerfItem(const char *label, const char *header, bool enabled=true)
const char * _label