MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
mnetracer.h
Go to the documentation of this file.
1//=============================================================================================================
35#ifndef TRACER_H
36#define TRACER_H
37
38//=============================================================================================================
39// MACRO DEFINITIONS
40//=============================================================================================================
41
42#ifdef TRACE
43#define MNE_TRACE() UTILSLIB::MNETracer _mneTracer__LINE__(__FILE__,__func__,__LINE__);
44#define MNE_TRACER_ENABLE(FILENAME) UTILSLIB::MNETracer::enable(#FILENAME);
45#define MNE_TRACER_DISABLE UTILSLIB::MNETracer::disable();
46#define MNE_TRACE_VALUE(NAME, VALUE) UTILSLIB::MNETracer::traceQuantity(NAME, VALUE);
47#else
48#define MNE_TRACE()
49#define MNE_TRACER_ENABLE(FILENAME)
50#define MNE_TRACER_DISABLE
51#define MNE_TRACE_VALUE()
52#endif
53
54#ifdef MNE_TRACE_MEMORY
55#define MNE_TRACE_MEMORY_REPORT \
56std::cout << "Total Memory Allocated : " << 0.000001 * __totalMemAllocated << " MB\n";\
57std::cout << "Total Memory Deleted : " << 0.000001 * __totalMemDeleted << " MB\n";\
58std::cout << "Total Memory Diff : " << 0.000001 * (__totalMemAllocated - __totalMemDeleted) << " MB\n";\
59
60size_t __totalMemAllocated(0);
61size_t __totalMemDeleted(0);
62void *operator new(size_t size)
63{
64 // std::cout << "Allocating " << size << " Bytes.\n";
65 __totalMemAllocated += size;
66 return malloc(size);
67}
68
69void operator delete(void *memory, size_t size)
70{
71 // std::cout << "Deleting " << size << " Bytes.\n";
72 __totalMemDeleted += size;
73 free(memory);
74}
75#else
76#define MNE_TRACE_MEMORY_REPORT
77#endif
78
79//=============================================================================================================
80// INCLUDES
81//=============================================================================================================
82
83#include "utils_global.h"
84
85#include <iostream>
86#include <fstream>
87#include <string>
88#include <chrono>
89#include <thread>
90#include <mutex>
91
92//=============================================================================================================
93// DEFINE NAMESPACE MNESCAN
94//=============================================================================================================
95
96namespace UTILSLIB
97{
98
121{
122public:
131 MNETracer(const std::string& file, const std::string& function, int lineNumber);
132
138 ~MNETracer();
139
144 static void enable(const std::string& jsonFileName);
145
149 static void enable();
150
155 static void disable();
156
161 static void start(const std::string& jsonFileName);
162
166 static void start();
167
171 static void stop();
172
178 static void traceQuantity(const std::string& name, long val);
179
184 bool printToTerminalIsSet();
185
190 void setPrintToTerminal(bool s);
191
192private:
197 static void writeHeader();
198
203 static void writeFooter();
204
209 static void writeToFile(const std::string& str);
210
215 static void setZeroTime();
216
221 static long long getTimeNow();
222
227 void initialize();
228
232 void formatFileName();
233
237 void formatFunctionName();
238
242 void registerConstructionTime();
243
247 void registerFinalTime();
248
252 void registerThreadId();
253
257 void calculateDuration();
258
262 void printDurationMiliSec();
263
267 void writeBeginEvent();
268
272 void writeEndEvent();
273
274 static bool ms_bIsEnabled;
275 static std::ofstream ms_OutputFileStream;
276 static bool ms_bIsFirstEvent;
277 static std::mutex ms_outFileMutex;
278 static long long ms_iZeroTime;
280 bool m_bIsInitialized;
281 bool m_bPrintToTerminal;
282 std::string m_sFileName;
283 std::string m_sFunctionName;
284 int m_iLineNumber;
285 std::string m_iThreadId;
286 long long m_iBeginTime;
287 long long m_iEndTime;
288 double m_dDurationMilis;
289}; // MNETracer
290
291} // namespace UTILSLIB
292
293#endif //if TRACE defined
294
utils library export/import macros.
#define UTILSSHARED_EXPORT