GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmRunProgressStats.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_RUN_PROGRESS_STATS_H_
25#define _GEMA_RUN_PROGRESS_STATS_H_
26
27#include "gmResultsData.h"
28#include "gmThreadManager.h"
29
30#include <unit.h>
31#include <qtPtrList.h>
32
33class GmResultsData;
34class Unit;
37
42{
43 Q_OBJECT
44
45public:
46
47 enum Level {
53 //-------------------------------
54 // Don't insert items below this line
55 GM_RUNPROG_NUM_LEVELS
56 };
57
59 GM_RUNPROG_TRACK_TIME = 0x0001,
60 GM_RUNPROG_TRACK_MEM = 0x0002,
61 GM_RUNPROG_TRACK_REPORT_AT_END = 0x0004,
62 GM_RUNPROG_TRACK_REPORT_STATS = 0x0008,
63 GM_RUNPROG_TRACK_STATS_MIN = 0x0010,
64 GM_RUNPROG_TRACK_STATS_MAX = 0x0020,
65 GM_RUNPROG_TRACK_STATS_AVG = 0x0040,
66 GM_RUNPROG_TRACK_STATS_TOTAL = 0x0080,
67 GM_RUNPROG_TRACK_STATS_ALL = 0x00F0,
68 GM_RUNPROG_TRACK_ATTR_DEFAULT = 0x0100,
69 GM_RUNPROG_TRACK_DEFAULT = GM_RUNPROG_TRACK_TIME | GM_RUNPROG_TRACK_REPORT_STATS |
70 GM_RUNPROG_TRACK_STATS_ALL,
71 };
72
74
76
82 static void setLevelConfiguration(QString item, Level level)
83 {
84 if(item == ":default")
85 _defLevel = level;
86 else
87 _levelMap[item] = level;
88 }
89
91 static Level defLevel() { return _defLevel; }
92
94 static Level configuredLevel(QString item) { return _levelMap.value(item, _defLevel); }
95
96 static int itemOptionsFromLevel(QString item, bool mem = false, bool* detailedStats = NULL);
97
98 int registerItem(const QObject* owner, int fatherItemId, QString name, int options = GM_RUNPROG_TRACK_DEFAULT, QString autoId = "");
99 QString itemName (int itemId) const;
100 int findItem (int fatherItemId, QString name) const;
101 bool renameItem (int itemId, QString autoId);
102
104 bool validItemId(int itemId) const { return itemId >= 0 && itemId < _items.listSize() && _items[itemId]; }
105
106 const QObject* itemOwner(int itemId) const;
107
108 void setItemData(int itemId, void* data);
109
110 void registerNestedItem(int trackingItemId, int trackedItemId);
111
120 int registerAttribute(int itemId, QString name, QString description, Unit unit, int nlin, int ncol,
121 QString format, int statOptions = GM_RUNPROG_TRACK_ATTR_DEFAULT)
122 {
123 assert(validItemId(itemId));
124 return registerAttribute(_items[itemId], name, description, unit, nlin, ncol, format, statOptions);
125 }
126
128 int registerScalarAttribute(int itemId, QString name, QString description, Unit unit, QString format,
129 int statOptions = GM_RUNPROG_TRACK_ATTR_DEFAULT)
130 {
131 return registerAttribute(itemId, name, description, unit, 1, 1, format, statOptions);
132 }
133
135 int registerCounterAttribute(int itemId, QString name, QString description, int statOptions = GM_RUNPROG_TRACK_ATTR_DEFAULT)
136 {
137 return registerAttribute(itemId, name, description, Unit(), 1, 1, ".0f", statOptions);
138 }
139
141 int registerStringAttribute(int itemId, QString name, QString description, int statOptions = GM_RUNPROG_TRACK_ATTR_DEFAULT)
142 {
143 return registerAttribute(itemId, name, description, Unit(), 0, 0, "", statOptions);
144 }
145
146 inline int attr(int itemId, int attrId) const; // Can not be defined in the .h due to undefined Item type -- including the header would create a cycle :(
147
149 GmAttributeResultsManager* attrManager() const { return _attrm; }
150
151 int findAttribute(int itemId, QString name) const;
152 int findAttribute(int itemId, int nestedId, QString name) const;
153
154 int autoTimeItemAttribute(int itemId) const;
155 int autoMemItemAttribute (int itemId) const;
156
157 GmRunProgressReport* addNewReport(QString title, QString fileName, bool itemColumn = false);
158 void addReportToItem(GmRunProgressReport* report, int itemId, QString itemReportDescription);
159 GmRunProgressReport* report(QString fileName) const;
160
161 void itemStart(int itemId);
162 void itemEnd (int itemId);
163
165 QString strAttributeValue(int itemId, int attrId) const { return _attrm->resultAttributeString(attr(itemId, attrId)); }
166
168 const double* numericAttributeValue(int itemId, int attrId) const { return _attrm->resultAttributeBuffer(attr(itemId, attrId)); }
169
170
172 void setAttributeValue(int itemId, int attrId, double val) { _attrm->setResultAttributeValue(attr(itemId, attrId), val); }
173
175 void setAttributeValue(int itemId, int attrId, double val1, double val2) { _attrm->setResultAttributeValue(attr(itemId, attrId), val1, val2); }
176
178 void setAttributeValue(int itemId, int attrId, double val1, double val2, double val3) { _attrm->setResultAttributeValue(attr(itemId, attrId), val1, val2, val3); }
179
183 void setAttributeValue(int itemId, int attrId, const double* val) { _attrm->setResultAttributeValue(attr(itemId, attrId), val); }
184
188 void setAttributeValue(int itemId, int attrId, const GmVector& val) { _attrm->setResultAttributeValue(attr(itemId, attrId), val); }
189
193 void setAttributeValue(int itemId, int attrId, const GmMatrix& val) { _attrm->setResultAttributeValue(attr(itemId, attrId), val); }
194
196 void setAttributeValue(int itemId, int attrId, int val) { _attrm->setResultAttributeValue(attr(itemId, attrId), (double)val); }
197
199 void setAttributeValue(int itemId, int attrId, unsigned val) { _attrm->setResultAttributeValue(attr(itemId, attrId), (double)val); }
200
202 void setAttributeValue(int itemId, int attrId, QString val) { _attrm->setResultAttributeValue(attr(itemId, attrId), val); }
203
205 void setAttributeValue(int itemId, int attrId, const char* val) { _attrm->setResultAttributeValue(attr(itemId, attrId), QString(val)); }
206
208 void incAttributeValue(int itemId, int attrId)
209 {
210 const double* v = _attrm->resultAttributeBuffer(attr(itemId, attrId));
211 _attrm->setResultAttributeValue(attr(itemId, attrId), *v + 1);
212 }
213
215 void decAttributeValue(int itemId, int attrId)
216 {
217 const double* v = _attrm->resultAttributeBuffer(attr(itemId, attrId));
218 _attrm->setResultAttributeValue(attr(itemId, attrId), *v - 1);
219 }
220
221 void reportStats(QString finalStatusStr, qint64 runTime);
222 void csvStats (QString csvFile, bool add, bool totalOnly, const QStringList& filters, QString simName, qint64 runTime);
223
224
225 void removeRegisteredItem(int itemId);
226
227public slots:
228 void removeRegisteredItems(QObject* owner);
229
230private:
232
233 inline int attr(const GmRunProgressStatsItem* item, int attrId) const;
234
235 QString parseItemName(int fatherId, QString name, QString autoId) const;
236
237 int registerAttribute(GmRunProgressStatsItem* item, QString name, QString description,
238 Unit unit,int nlin, int ncol, QString format, int statOptions);
239
240 void csvStatsFillReportData (bool totalOnly, const QStringList& filters, qint64 runTime,
241 QStringList& attrList, QStringList& unitList, QStringList& dataList) const;
242 bool csvStatsParseReportData(QString fileName, QString attrHeader, QString unitHeader, int numDataCols, QString dataHeader,
243 QStringList& attrList, QStringList& unitList, QStringList& dataList, QStringList& nameList) const;
244
245 QString itemStr (const GmRunProgressStatsItem* item, int attrId) const;
246 QString itemStatStr(const GmRunProgressStatsItem* item, int attrId) const;
247
248 void addReportTraillers() const;
249
253
254 QtPtrList<GmRunProgressStatsItem> _items;
259};
260
268{
269public:
270 GmRunProgress(GmRunProgressStats* ps, int itemId) : _ps(itemId >= 0 ? ps : NULL), _itemId(itemId)
271 {
272 if(_ps)
273 _ps->itemStart(itemId);
274 }
275
277
278 QString strAttributeValue (int attrId) const { return _ps ? _ps->strAttributeValue (_itemId, attrId) : ""; }
279 const double* numericAttributeValue(int attrId) const { return _ps ? _ps->numericAttributeValue(_itemId, attrId) : NULL; }
280
281 void setAttributeValue(int attrId, double val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
282 void setAttributeValue(int attrId, double val1, double val2) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val1, val2); }
283 void setAttributeValue(int attrId, double val1, double val2, double val3) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val1, val2, val3); }
284 void setAttributeValue(int attrId, const double* val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
285 void setAttributeValue(int attrId, const GmVector& val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
286 void setAttributeValue(int attrId, const GmMatrix& val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
287 void setAttributeValue(int attrId, int val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
288 void setAttributeValue(int attrId, unsigned val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
289 void setAttributeValue(int attrId, QString val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
290 void setAttributeValue(int attrId, const char* val) { if(_ps) _ps->setAttributeValue(_itemId, attrId, val); }
291 void incAttributeValue(int attrId) { if(_ps) _ps->incAttributeValue(_itemId, attrId); }
292 void decAttributeValue(int attrId) { if(_ps) _ps->decAttributeValue(_itemId, attrId); }
293
294protected:
297};
298
301{
302public:
304};
305
306#endif
307
A class used to host the metadata and the values for all attributes added to the results data....
Definition gmAttributeResultsManager.h:60
Class representing a category with multiple logging levels.
Definition gmLog.h:58
Auxiliar class used to store the complete set of results data for a simulation.
Definition gmResultsData.h:58
A RAII class used to simplify tracking an item with a progressStats object. When the object is create...
Definition gmRunProgressStats.h:268
int _itemId
The item id. -1 if tracking is not necessary.
Definition gmRunProgressStats.h:296
GmRunProgressStats * _ps
The progress stats object. NULL if tracking is not necessary.
Definition gmRunProgressStats.h:295
An alternative implementation of GmRunProgress that when called from a worker thread does nothing.
Definition gmRunProgressStats.h:301
A class used to create formatted reports based on ProgressStats item attribute values.
Definition gmRunProgressReport.h:40
A class used to store time, memory and additional values statistics related to the simulation loading...
Definition gmRunProgressStats.h:42
GmAttributeResultsManager * attrManager() const
Returns the global attribute manager.
Definition gmRunProgressStats.h:149
static Level _defLevel
The default level for entries that are not present on _levelMap.
Definition gmRunProgressStats.h:257
static void setLevelConfiguration(QString item, Level level)
Sets the level configuration for an item. Should be called before item creation. Intended usage is to...
Definition gmRunProgressStats.h:82
void setAttributeValue(int itemId, int attrId, double val1, double val2, double val3)
Sets the value for a vector[3] result attribute identified by its id (returned by registerAttribute()...
Definition gmRunProgressStats.h:178
void setAttributeValue(int itemId, int attrId, double val1, double val2)
Sets the value for a vector[2] result attribute identified by its id (returned by registerAttribute()...
Definition gmRunProgressStats.h:175
GmResultsData * _resultsData
The results data object storing item attributes.
Definition gmRunProgressStats.h:250
QString strAttributeValue(int itemId, int attrId) const
Returns the current value for a string attribute.
Definition gmRunProgressStats.h:165
void setAttributeValue(int itemId, int attrId, const char *val)
Sets the value for a string attribute identified by its id (returned by registerStringAttribute())
Definition gmRunProgressStats.h:205
int registerCounterAttribute(int itemId, QString name, QString description, int statOptions=GM_RUNPROG_TRACK_ATTR_DEFAULT)
Registers a counter attribute, always printed as an integer value.
Definition gmRunProgressStats.h:135
int registerAttribute(int itemId, QString name, QString description, Unit unit, int nlin, int ncol, QString format, int statOptions=GM_RUNPROG_TRACK_ATTR_DEFAULT)
Registers a new value attribute for the given item.
Definition gmRunProgressStats.h:120
bool validItemId(int itemId) const
Returns true if the given id is a valid item id.
Definition gmRunProgressStats.h:104
TrackOptions
Definition gmRunProgressStats.h:58
void setAttributeValue(int itemId, int attrId, const GmMatrix &val)
Sets the value for a matrix valued attribute identified by its id (returned by registerAttribute())....
Definition gmRunProgressStats.h:193
GmAttributeResultsManager * _attrm
The attribute manager (from _resultsData)
Definition gmRunProgressStats.h:251
void setAttributeValue(int itemId, int attrId, int val)
Sets the value for a counter attribute identified by its id (returned by registerCounterAttribute())
Definition gmRunProgressStats.h:196
void setAttributeValue(int itemId, int attrId, double val)
Sets the value for a scalar result attribute identified by its id (returned by registerAttribute())
Definition gmRunProgressStats.h:172
static Level configuredLevel(QString item)
The configured level for the given item. Can be used to choose the appropriate track options dependin...
Definition gmRunProgressStats.h:94
QMap< QString, int > _itemsMap
Maps item names to their position on _items.
Definition gmRunProgressStats.h:255
static Level defLevel()
Returns the default level.
Definition gmRunProgressStats.h:91
int registerStringAttribute(int itemId, QString name, QString description, int statOptions=GM_RUNPROG_TRACK_ATTR_DEFAULT)
Registers a string attribute.
Definition gmRunProgressStats.h:141
int registerScalarAttribute(int itemId, QString name, QString description, Unit unit, QString format, int statOptions=GM_RUNPROG_TRACK_ATTR_DEFAULT)
Registers a scalar attribute.
Definition gmRunProgressStats.h:128
QVector< GmRunProgressReport * > _reports
The set of added reports, owned by the progress object.
Definition gmRunProgressStats.h:258
void setAttributeValue(int itemId, int attrId, QString val)
Sets the value for a string attribute identified by its id (returned by registerStringAttribute())
Definition gmRunProgressStats.h:202
const double * numericAttributeValue(int itemId, int attrId) const
Returns the current value for a numeric attribute.
Definition gmRunProgressStats.h:168
void setAttributeValue(int itemId, int attrId, unsigned val)
Sets the value for a counter attribute identified by its id (returned by registerCounterAttribute())
Definition gmRunProgressStats.h:199
void itemEnd(int itemId)
Notifies the progress object that the operation tied to the given item has just finished.
Definition gmRunProgressStats.cpp:614
QtPtrList< GmRunProgressStatsItem > _items
The set of registered items. Might include NULL entries!
Definition gmRunProgressStats.h:254
Level
Definition gmRunProgressStats.h:47
@ GM_RUNPROG_DISABLED
No statistics at all.
Definition gmRunProgressStats.h:48
@ GM_RUNPROG_DS_DP
Detailed statistics, Detailed printing.
Definition gmRunProgressStats.h:52
@ GM_RUNPROG_NS_SP
Normal statistics, Summary printing. The default if not changed by a call to setLevelConfiguration()
Definition gmRunProgressStats.h:49
@ GM_RUNPROG_DS_SP
Detailed statistics, Summary printing.
Definition gmRunProgressStats.h:51
@ GM_RUNPROG_NS_DP
Normal statistics, Detailed printing.
Definition gmRunProgressStats.h:50
void incAttributeValue(int itemId, int attrId)
Increments the current value of a "counter" attribute, doing the equivalent of attr = attr + 1.
Definition gmRunProgressStats.h:208
GmLogCategory _logger
The logger object used to emit messages when logging to the standard log file.
Definition gmRunProgressStats.h:252
void itemStart(int itemId)
Notifies the progress object that the operation tied to the given item is about to start.
Definition gmRunProgressStats.cpp:580
void setAttributeValue(int itemId, int attrId, const GmVector &val)
Sets the value for a vector valued attribute identified by its id (returned by registerAttribute())....
Definition gmRunProgressStats.h:188
void setAttributeValue(int itemId, int attrId, const double *val)
Sets the value for a multi valued attribute identified by its id (returned by registerAttribute())....
Definition gmRunProgressStats.h:183
static QMap< QString, Level > _levelMap
The map with item level configuration. Filled BEFORE item creation and used to init item levels.
Definition gmRunProgressStats.h:256
void decAttributeValue(int itemId, int attrId)
Decrements the current value of a "counter" attribute, doing the equivalent of attr = attr - 1.
Definition gmRunProgressStats.h:215
An item used to store time, memory and additional values statistics related to the simulation loading...
Definition gmRunProgressStatsItem.h:39
static bool inMainThread()
Is the current thread the main thread? Equivalent to comparing the currentId() with 0.
Definition gmThreadManager.h:174
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35
arma::mat GmMatrix
The basic type for a GeMA matrix object. Currently based on an Armadillo matrix.
Definition gmMatrix.h:38
Declaration of the GmResultsData class.
Declaration of the GmThreadManager class.
arma::vec GmVector
The basic type for a GeMA vector object. Currently based on an Armadillo vector.
Definition gmVector.h:34
Q_DISABLE_COPY(Class)