File indexing completed on 2024-04-28 16:30:34
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 #ifndef SKGTRACES_H 0007 #define SKGTRACES_H 0008 /** @file 0009 * This file defines classes SKGTraces an macros. 0010 * 0011 * @author Stephane MANKOWSKI / Guillaume DE BURE 0012 */ 0013 #include <qmap.h> 0014 #include <qstack.h> 0015 #include <qstringlist.h> 0016 #include <qtextstream.h> 0017 0018 #include "skgdefine.h" 0019 0020 /** 0021 * Macro for traces 0022 */ 0023 #define SKGTRACE SKGTRACESUITE << SKGTraces::SKGIndentTrace 0024 /** 0025 * Macro for traces 0026 */ 0027 #define SKGTRACESUITE SKGTraces::SKGCout 0028 /** 0029 * Macro for traces 0030 */ 0031 #define SKGTRACESEPARATOR SKGTRACE << "##############################################\n" << SKGFLUSH; 0032 0033 #ifdef SKGNOTRACES 0034 /** 0035 * Macro for traces 0036 */ 0037 #define IFSKGTRACEL(Level) if (false) 0038 #else 0039 /** 0040 * Macro for traces 0041 */ 0042 #define IFSKGTRACEL(Level) if ((Level) <= SKGTraces::SKGLevelTrace) 0043 #endif 0044 0045 /** 0046 * Macro for traces 0047 */ 0048 #define SKGTRACEL(Level) SKGTRACESUITEL(Level) << SKGTraces::SKGIndentTrace 0049 /** 0050 * Macro for traces 0051 */ 0052 #define SKGTRACESUITEL(Level) IFSKGTRACEL(Level) SKGTRACESUITE 0053 0054 /** 0055 * This structure represents one performance measure 0056 */ 0057 struct SKGPerfoInfo { 0058 /** The number of call for the method */ 0059 int NbCall; 0060 /** The global time passed in the method */ 0061 double Time; 0062 /** The time consumed by the method */ 0063 double TimePropre; 0064 /** The minimum time passed in the method */ 0065 double TimeMin; 0066 /** The maximum time passed in the method */ 0067 double TimeMax; 0068 }; 0069 0070 /** 0071 * A map of strings ==> SKGPerfoInfo 0072 * @see SKGPerfoMapIterator 0073 */ 0074 using SKGPerfoMap = QMap<QString, SKGPerfoInfo>; 0075 0076 /** 0077 * A iterator for SKGPerfoMap ==> SKGPerfoInfo 0078 * @see SKGPerfoMap 0079 */ 0080 using SKGPerfoMapIterator = QMap<QString, SKGPerfoInfo>::Iterator; 0081 0082 /** 0083 * A stack of strings 0084 */ 0085 using SKGQStringStack = QStack<QString>; 0086 0087 class SKGError; 0088 0089 /** 0090 * This class manages traces 0091 */ 0092 class SKGBASEMODELER_EXPORT SKGTraces final 0093 { 0094 public: 0095 /** 0096 * Constructor 0097 * @param iName The message to display 0098 * @param iLevel The level to display this error. 0099 * The error will be display if the level of traces asked is greater or equal than 0100 * the level of this trace (iLevel) 0101 * @param iRC A pointer of the error object of the calling method 0102 * The SKGError 0103 */ 0104 explicit SKGTraces(int iLevel, const char* iName, SKGError* iRC); 0105 0106 /** 0107 * Constructor 0108 * @param iName The message to display 0109 * @param iLevel The level to display this error. 0110 * The error will be display if the level of traces asked is greater or equal than 0111 * the level of this trace (iLevel) 0112 * @param iRC A pointer of the error object of the calling method 0113 * The SKGError 0114 */ 0115 SKGTraces(int iLevel, const QString& iName, SKGError* iRC); 0116 0117 /** 0118 * Destructor 0119 */ 0120 ~SKGTraces(); 0121 0122 /** 0123 * Clean profiling statistics 0124 */ 0125 static void cleanProfilingStatistics(); 0126 0127 /** 0128 * Get profiling statistics 0129 */ 0130 static QStringList getProfilingStatistics(); 0131 0132 /** 0133 * Dump profiling statistics 0134 */ 0135 static void dumpProfilingStatistics(); 0136 0137 /** 0138 * Standard output stream for traces 0139 */ 0140 static QTextStream SKGCout; 0141 0142 /** 0143 * The current level of indentation 0144 */ 0145 static QString SKGIndentTrace; 0146 0147 /** 0148 * The current level of taces 0149 */ 0150 static int SKGLevelTrace; 0151 0152 /** 0153 * To enable, disable profiling 0154 */ 0155 static bool SKGPerfo; 0156 0157 private: 0158 Q_DISABLE_COPY(SKGTraces) 0159 void init(int iLevel, const QString& iName, SKGError* iRC); 0160 0161 QString m_mame; 0162 bool m_output = false; 0163 bool m_profiling = false; 0164 SKGError* m_rc = nullptr; 0165 double m_elapse = 0.0; 0166 SKGPerfoMapIterator m_it; 0167 0168 static SKGPerfoMap m_SKGPerfoMethode; 0169 static SKGQStringStack m_SKGPerfoPathMethode; 0170 }; 0171 0172 /** 0173 * Macro for traces 0174 */ 0175 #define TOKENPASTE(x, y) x ## y 0176 0177 /** 0178 * Macro for traces 0179 */ 0180 #define TOKENPASTE2(x, y) TOKENPASTE(x, y) 0181 0182 #ifdef SKGNOTRACES 0183 /** 0184 * Macro for traces 0185 */ 0186 #define SKGTRACEINRC(Level, Name, RC) 0187 0188 /** 0189 * Macro for traces 0190 */ 0191 #define SKGTRACEIN(Level, Name) 0192 #else 0193 /** 0194 * Macro for traces 0195 */ 0196 #define SKGTRACEINRC(Level, Name, RC) \ 0197 SKGTraces TOKENPASTE2(trace1_, __LINE__)(Level, Name, &(RC)); 0198 0199 /** 0200 * Macro for traces 0201 */ 0202 #define SKGTRACEIN(Level, Name) \ 0203 SKGTraces TOKENPASTE2(trace2_, __LINE__)(Level, Name, nullptr); 0204 #endif 0205 0206 #ifdef SKGFULLTRACES 0207 /** 0208 * Macro for traces 0209 */ 0210 #define _SKGTRACEINRC(Level, Name, RC) SKGTRACEINRC(Level, Name, RC) 0211 /** 0212 * Macro for traces 0213 */ 0214 #define _SKGTRACEIN(Level, Name) SKGTRACEIN(Level, Name) 0215 #else 0216 /** 0217 * Macro for traces 0218 */ 0219 #define _SKGTRACEINRC(Level, Name, RC) 0220 /** 0221 * Macro for traces 0222 */ 0223 #define _SKGTRACEIN(Level, Name) 0224 #endif 0225 0226 /** 0227 * Macro for traces 0228 */ 0229 #define SKGTRACEINFUNCRC(Level, RC) \ 0230 SKGTRACEINRC(Level, Q_FUNC_INFO, RC) 0231 0232 /** 0233 * Macro for traces 0234 */ 0235 #define SKGTRACEINFUNC(Level) \ 0236 SKGTRACEIN(Level, Q_FUNC_INFO) 0237 0238 /** 0239 * Macro for traces 0240 */ 0241 #define _SKGTRACEINFUNCRC(Level, RC) \ 0242 _SKGTRACEINRC(Level, Q_FUNC_INFO, RC) 0243 0244 /** 0245 * Macro for traces 0246 */ 0247 #define _SKGTRACEINFUNC(Level) \ 0248 _SKGTRACEIN(Level, Q_FUNC_INFO) 0249 0250 #endif 0251