ug4
profiler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__COMMON__PROFILER__
34 #define __H__UG__COMMON__PROFILER__
35 
36 // if cpu-frequency adaption is enabled
37 #ifdef UG_CPU_FREQ
38  #include "freq_adapt.h"
39  #define CPU_FREQ_BEGIN_AUTO_END(id, file, line) \
40  static unsigned long __freq__##id = FreqAdaptValues::freq(file, line); \
41  AutoFreqAdaptNode __node__freq__##id((__freq__##id));
42 
43  #define CPU_FREQ_END() \
44  FreqAdaptNodeManager::release_latest();
45 #else
46  #define CPU_FREQ_BEGIN_AUTO_END(name, file, line)
47  #define CPU_FREQ_END()
48 #endif
49 
50 
51 // if some profiler is enabled
52 #ifdef UG_PROFILER
53 
54 #include <vector>
55 #include "profilenode_management.h"
56 #include "shiny_call_logging.h"
57 
58 
59 #ifdef UG_PROFILER_SHINY
60 
61 // this is just a wrapper-include for the shiny-profiler by Aidin Abedi
62  #define SHINY_PROFILER TRUE
63  #include "src/ShinyManager.h"
64  #include "src/ShinyNode.h"
65 
66 
68  #define PROFILE_BEGIN_AUTO_END(id, name, group, file, line) \
69  \
70  CPU_FREQ_BEGIN_AUTO_END(id, file, line); \
71  AutoProfileNode id; \
72  static Shiny::ProfileZone __ShinyZone_##id = { \
73  NULL, Shiny::ProfileZone::STATE_HIDDEN, name, \
74  group, file, line, \
75  { { 0, 0 }, { 0, 0 }, { 0, 0 } } \
76  }; \
77  { \
78  static Shiny::ProfileNodeCache cache = \
79  &Shiny::ProfileNode::_dummy; \
80  \
81  Shiny::ProfileManager::instance._beginNode(&cache, &__ShinyZone_##id);\
82  }\
83  PROFILE_LOG_CALL_START()
84 
85 
90  #define PROFILE_BEGIN(name) \
91  PROFILE_BEGIN_AUTO_END(apn_##name, #name, NULL, __FILE__, __LINE__)
92 
94  #define PROFILE_END() \
95  ProfileNodeManager::release_latest(); \
96  CPU_FREQ_END();
97 
99  #define PROFILE_FUNC() \
100  PROFILE_BEGIN_AUTO_END(__ShinyFunction, __FUNCTION__, NULL, __FILE__, __LINE__)
101 
102  #define PROFILE_BEGIN_GROUP(name, group) \
103  PROFILE_BEGIN_AUTO_END(apn_##name, #name, group, __FILE__, __LINE__)
104 
105  #define PROFILE_FUNC_GROUP(group) \
106  PROFILE_BEGIN_AUTO_END(__ShinyFunction, __FUNCTION__, group, __FILE__, __LINE__)
107 
109  #define PROFILER_UPDATE \
110  Shiny::ProfileManager::instance.update
111 
113  #define PROFILER_OUTPUT \
114  Shiny::ProfileManager::instance.output
115 
116 #endif // UG_PROFILER_SHINY
117 
118 
119 #ifdef UG_PROFILER_SCALASCA
120  #include "epik_user.h"
121  #include <ostream>
122 
123  #define PROFILE_STRINGIFY(x) #x
124  #define PROFILE_TOSTRING(x) PROFILE_STRINGIFY(x)
125 
129  #define PROFILE_BEGIN(name) \
130  EPIK_USER_REG(__##name, PROFILE_TOSTRING(name)); \
131  EPIK_USER_START(__##name); \
132  AutoProfileNode apn_##name(__##name); \
133 
135  #define PROFILE_END() \
136  ProfileNodeManager::release_latest()
137 
139  #define PROFILE_FUNC() \
140  EPIK_TRACER(__FUNCTION__)
141 
142  #define PROFILE_BEGIN_GROUP(name, group) \
143  PROFILE_BEGIN(name)
144 
145  #define PROFILE_FUNC_GROUP(group) \
146  PROFILE_FUNC()
147 
148  namespace ProfilerDummy{
149  inline void Update(float a = 0.0f) {}
150  inline bool Output(const char *a = NULL) {return false;}
151  inline bool Output(std::ostream &a) {return false;}
152  }
153 
154  #define PROFILER_UPDATE ProfilerDummy::Update
155  #define PROFILER_OUTPUT ProfilerDummy::Output
156 
157 #endif // UG_PROFILER_SCALASCA
158 
159 #ifdef UG_PROFILER_VAMPIR
160  #include "vt_user.h"
161  #include <ostream>
162 
163  #define PROFILE_STRINGIFY(x) #x
164  #define PROFILE_TOSTRING(x) PROFILE_STRINGIFY(x)
165 
169  #define PROFILE_BEGIN(name) \
170  VT_USER_START(PROFILE_TOSTRING(name)); \
171  AutoProfileNode apn_##name(PROFILE_TOSTRING(name)); \
172 
174  #define PROFILE_END() \
175  ProfileNodeManager::release_latest()
176 
178  #define PROFILE_FUNC() \
179  VT_TRACER((char*)__FUNCTION__)
180 
181  #define PROFILE_BEGIN_GROUP(name, group) \
182  PROFILE_BEGIN(name)
183 
184  #define PROFILE_FUNC_GROUP(group) \
185  PROFILE_FUNC()
186 
187  namespace ProfilerDummy{
188  inline void Update(float a = 0.0f) {}
189  inline bool Output(const char *a = NULL) {return false;}
190  inline bool Output(std::ostream &a) {return false;}
191  }
192 
193  #define PROFILER_UPDATE ProfilerDummy::Update
194  #define PROFILER_OUTPUT ProfilerDummy::Output
195 
196 #endif // UG_PROFILER_VAMPIR
197 
198 #ifdef UG_PROFILER_SCOREP
199  #include <scorep/SCOREP_User.h>
200  #include <ostream>
201 
202  #define PROFILE_STRINGIFY(x) #x
203  #define PROFILE_TOSTRING(x) PROFILE_STRINGIFY(x)
204 
208  #define PROFILE_BEGIN(name) \
209  SCOREP_USER_REGION_DEFINE( __scorephandle__##name ) \
210  SCOREP_USER_REGION_BEGIN( __scorephandle__##name, PROFILE_TOSTRING(name), \
211  SCOREP_USER_REGION_TYPE_COMMON ) \
212  AutoProfileNode apn_##name(__scorephandle__##name);
213 
215  #define PROFILE_END() \
216  ProfileNodeManager::release_latest()
217 
219  #define PROFILE_FUNC() \
220  SCOREP_USER_REGION(__FUNCTION__, SCOREP_USER_REGION_TYPE_FUNCTION )
221 
222  #define PROFILE_BEGIN_GROUP(name, group) \
223  PROFILE_BEGIN(name)
224 
225  #define PROFILE_FUNC_GROUP(group) \
226  PROFILE_FUNC()
227 
228  namespace ProfilerDummy{
229  inline void Update(float a = 0.0f) {}
230  inline bool Output(const char *a = NULL) {return false;}
231  inline bool Output(std::ostream &a) {return false;}
232  }
233 
234  #define PROFILER_UPDATE ProfilerDummy::Update
235  #define PROFILER_OUTPUT ProfilerDummy::Output
236 
237 #endif // UG_PROFILER_SCOREP
238 
239 #define PROFILE_END_(name) \
240  assert(&(apn_##name) == ProfileNodeManager::inst().m_nodes.top()); \
241  struct apn_already_ended_##name { } ; \
242  PROFILE_END();
243 
244 #else
245  #include <ostream>
246 
247  namespace ProfilerDummy{
248  inline void Update(float a = 0.0f) {}
249  inline bool Output(const char *a = NULL) {return false;}
250  inline bool Output(std::ostream &a) {return false;}
251  }
252 
253 // Empty macros if UG_PROFILER == false
254  #define PROFILE_BEGIN(name) CPU_FREQ_BEGIN_AUTO_END(apn_##name, __FILE__, __LINE__);
255  #define PROFILE_BEGIN_GROUP(name, groups) PROFILE_BEGIN(name)
256  #define PROFILE_END() CPU_FREQ_END();
257  #define PROFILE_FUNC() CPU_FREQ_BEGIN_AUTO_END(apn##__FUNCTION__, __FILE__, __LINE__);
258  #define PROFILE_FUNC_GROUP(groups) PROFILE_FUNC()
259  #define PROFILER_UPDATE ProfilerDummy::Update
260  #define PROFILER_OUTPUT ProfilerDummy::Output
261 
262  #define PROFILE_END_(name)
263 
264 #endif // UG_PROFILER
265 
266 #endif // __H__UG__COMMON__PROFILER__
Definition: profiler.h:247
bool Output(const char *a=NULL)
Definition: profiler.h:249
void Update(float a=0.0f)
Definition: profiler.h:248