24 #ifndef _GEMA_MEMORY_DUMP_H_ 25 #define _GEMA_MEMORY_DUMP_H_ 46 #define GM_MEMORY_DUMP_ITEM_NAME_SIZE 80 49 #define GM_MEMORY_DUMP_ITEM_DATA_SIZE 16 52 #define GM_MEMORY_DUMP_MIN_COMPRESSION (4 * 1024) 63 void addBuffer(
char* buffer, qint64 size);
66 qint64
size()
const {
return _totalSize; }
74 bool isDone()
const {
return _bufIndex == _bufferList.size() && _bufOffset == 0; }
76 bool writeDataToFile (
QFile* file, qint64 size);
77 bool readDataFromFile(
QFile* file, qint64 size);
78 void writeDataToMem (
char* ptr, qint64 size);
79 void readDataFromMem (
char* ptr, qint64 size);
108 virtual QString itemName()
const = 0;
111 virtual int itemType()
const = 0;
114 virtual bool canCompress()
const = 0;
117 virtual bool partialOp()
const = 0;
123 virtual bool fixedSize()
const = 0;
132 virtual bool opStart(
int op) { Q_UNUSED(op);
return true; }
141 virtual bool opEnd(
int op) { Q_UNUSED(op);
return true; }
144 virtual qint64 size()
const = 0;
158 virtual bool fillDataHeader(
char* header) = 0;
178 virtual void getDataBuffer(
GmMemoryBufferList& bufferList, qint64 size = 0, qint64 offset = 0) = 0;
202 virtual bool setDataBuffer(
GmMemoryBufferList& bufferList,
const char* header, qint64 size, qint64 offset = 0) = 0;
226 double dumpSizeA = 1.0,
unsigned dumpSizeB = 0);
240 assert(itemId >= 0 && itemId < _dumpItems.size());
241 return _dumpItems[itemId]->_item;
244 int findItem(
QString name,
int typeMask = 0,
int typeValue = 0,
int groupId = -1,
int start = 0);
249 assert(itemId >= 0 && itemId < _dumpItems.size());
250 assert(_dumpItems[itemId]->_data);
251 return _dumpItems[itemId]->_data->_groupId;
257 void setItemActive (
int itemId,
bool active);
258 void setGroupActive(
int groupId,
bool active);
263 assert(itemId >= 0 && itemId < _dumpItems.size());
264 return _dumpItems[itemId]->_active;
267 bool init(
QString dumpFile,
bool overwrite,
bool keep);
273 bool saveItem(
int itemId, qint64 size = 0, qint64 offset = 0);
274 bool loadItem(
int itemId, qint64 size = 0, qint64 offset = 0);
276 bool saveActiveItems();
277 bool loadActiveItems();
283 int adjustGroupId(
int id)
const { assert(
id >= -2);
return id == -1 ? _nextGroupId : (
id == -2 ? _currentGroupId : id); }
286 static int strToMode(
const QString& str);
338 static_assert(
sizeof(
FileItemHeader) % 16 == 0,
"Unexpected structure size");
381 bool fileInit(
QString dumpFile,
bool overwrite,
bool keep);
383 bool fileInitExisting();
388 bool fileSaveItem (
DumpItem* item,
bool update, qint64 size = 0, qint64 offset = 0);
389 bool memorySaveItem(
DumpItem* item, qint64 size = 0, qint64 offset = 0);
391 bool fileLoadItem (
DumpItem* item, qint64 size = 0, qint64 offset = 0);
392 bool memoryLoadItem(
DumpItem* item, qint64 size = 0, qint64 offset = 0);
394 bool writeOrCheckControlHeader(
bool write, qint64* infoBlockPos);
395 bool saveDataBlock (qint32 blockId, qint64 blockSize,
const char* buffer, qint64 size);
402 bool loadChunkData (
char* buffer, qint64 offset, qint64 size);
404 bool updateFileInfoHeader();
407 bool readData (
char* buffer, qint64 size);
409 bool writeData(
const char* buffer, qint64 size);
412 qint64 blockSize(qint64 dataSize,
bool grow);
414 #if defined ENABLE_TESTS 416 friend Q_DECL_EXPORT
void TEST_GmMemoryDumpCheck(
GmMemoryDump*,
bool);
417 void checkAndPrintFileStructure(
bool print,
bool saved);
int _currentGroupId
The id of the last added group id.
Definition: gmMemoryDump.h:435
bool isDone() const
Check that all data data on the buffer has been traversed by read or write functions.
Definition: gmMemoryDump.h:74
unsigned _dumpSizeB
Offset for extra grow size added to a data item size.
Definition: gmMemoryDump.h:424
#define GM_MEMORY_DUMP_ITEM_NAME_SIZE
The maximum size for a dump item name.
Definition: gmMemoryDump.h:46
virtual bool opEnd(int op)
Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryD...
Definition: gmMemoryDump.h:141
QVarLengthArray< QPair< char *, qint64 >, 5 > _bufferList
A list with buffers and their sizes.
Definition: gmMemoryDump.h:81
Dumped memory is saved to a file.
Definition: gmMemoryDump.h:41
bool _keepFile
Should we keep dump files after the object is destroyed?
Definition: gmMemoryDump.h:426
int adjustGroupId(int id) const
Returns the adjusted group id, translating the -1 (next group) or -2 (current group) options for addD...
Definition: gmMemoryDump.h:283
void setPrintStructure(bool mode)
Enables or disables printing the dump item structure, both when addDumpItem() is called and when a fi...
Definition: gmMemoryDump.h:233
double _dumpSizeA
Multiplier for extra grow size added to a data item size.
Definition: gmMemoryDump.h:423
Declaration of usefull configuration definitions for the Core library.
GmMemoryDumpMode _mode
Dump mode.
Definition: gmMemoryDump.h:420
A helper class that can store a list of buffers and their sizes, allowing for GmMemoryDumpItem instan...
Definition: gmMemoryDump.h:58
#define GM_MEMORY_DUMP_ITEM_DATA_SIZE
The size of the per item fixed item data buffer.
Definition: gmMemoryDump.h:49
ItemHeader * _data
The item control header.
Definition: gmMemoryDump.h:377
QFile * _file
The dump file (if the current mode so requires)
Definition: gmMemoryDump.h:429
virtual void bufferReleased(int op, bool ok)
Function called once after a call to getDataBuffer() / setDataBuffer() to inform the item data that t...
Definition: gmMemoryDump.h:217
qint32 _lastChunkBlockId
The block Id for the last chunk stored in the file.
Definition: gmMemoryDump.h:433
DumpItem(GmMemoryDumpItem *item, qint32 id, qint16 groupId)
Dump item constructor.
Definition: gmMemoryDump.h:371
GmMemoryDumpItem * item(int itemId) const
Returns the dump item, given the id returned by addDumpItem()
Definition: gmMemoryDump.h:238
#define GM_MEMORY_DUMP_MIN_COMPRESSION
The default minimum buffer size in bytes for compression to be worthy (must be > 0)
Definition: gmMemoryDump.h:52
int itemGroup(int itemId) const
Returns the group id of the given item.
Definition: gmMemoryDump.h:247
GmMemoryDumpMode
Supported memory dump modes.
Definition: gmMemoryDump.h:37
Dumped file is opend for restore only. No save operations are allowed.
Definition: gmMemoryDump.h:42
Dumped memory is saved on memory.
Definition: gmMemoryDump.h:40
int _nextGroupId
The id of the next item group id (can be different from _currentGroupId+1 if the user explicitly gave...
Definition: gmMemoryDump.h:436
virtual bool opStart(int op)
Function called by GmMemoryDump::load(), GmMemoryDump::save(), GmMemoryDump::loadItem() and GmMemoryD...
Definition: gmMemoryDump.h:132
int numItems() const
Returns the number of added dump items.
Definition: gmMemoryDump.h:255
bool _init
Check if init was called successfully.
Definition: gmMemoryDump.h:430
qint64 size() const
Returns the sum of the sizes of the stored buffers.
Definition: gmMemoryDump.h:66
void print(const GmMatrix &m, const GmLogCategory &logger, GmLogLevel level, int fieldWidth, char format, int precision)
Prints the matrix using the specified logger, level and precision fields.
Definition: gmMatrixUtils.cpp:34
const GmLogCategory & _logger
Basic logger object for dump messages.
Definition: gmMemoryDump.h:438
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
bool _active
Is this item active or not? Used by saveActiveItems() / loadActiveItems()
Definition: gmMemoryDump.h:378
int _bufIndex
The current buffer for the next operation.
Definition: gmMemoryDump.h:83
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
Auto mode. Dumped memory is saved either on file or on memory depending on memory usage.
Definition: gmMemoryDump.h:39
The structure adding controll information to a GmMemoryDumpItem.
Definition: gmMemoryDump.h:368
bool _printStructure
Should we print the configured item structure?
Definition: gmMemoryDump.h:427
QString _fileName
Dump file name.
Definition: gmMemoryDump.h:425
qint64 _totalSize
The sum of the buffers sizes on _bufferList.
Definition: gmMemoryDump.h:82
qint64 _bufOffset
The current buffer offset for the next operation.
Definition: gmMemoryDump.h:84
int _compression
Compression level for dumped data. From -1 to 9. 0 = no, 9 = max, -1 = zlib default.
Definition: gmMemoryDump.h:421
GmMemoryDumpItem * _item
The dump item.
Definition: gmMemoryDump.h:376
~DumpItem()
Dump item destructor. Deletes the stored item data object along with other control data.
Definition: gmMemoryDump.h:374
QVector< DumpItem * > _dumpItems
A list with the set of dump items + their controll info.
Definition: gmMemoryDump.h:434
int _minCompressionSize
The minumum size a buffer must have to be compressed.
Definition: gmMemoryDump.h:422
bool isItemActive(int itemId)
Returns true if the given item is active.
Definition: gmMemoryDump.h:261
qint64 _fileInfoPos
The position on the file for the Info block header.
Definition: gmMemoryDump.h:431
virtual ~GmMemoryDumpItem()
Virtual destructor.
Definition: gmMemoryDump.h:103
Interface for an object that can be dumped and undumped to either file or memory by GmMemoryDump.
Definition: gmMemoryDump.h:99
qint64 _firstChunkPos
The position in the dump file for the first dump item chunk.
Definition: gmMemoryDump.h:432
Class storing a memory dump containing several dump items.
Definition: gmMemoryDump.h:221
Declaration of support functions and macros for information logging.