0
0
mirror of https://github.com/yse/easy_profiler.git synced 2025-01-14 00:27:55 +08:00

Add dumpBLocksToFile function

This commit is contained in:
Sergey Yagovtsev 2016-07-04 22:53:02 +03:00
parent 980edd631a
commit 82e9920e15
3 changed files with 25 additions and 8 deletions

View File

@ -226,6 +226,7 @@ namespace profiler
void PROFILER_API beginBlock(Block* _block);
void PROFILER_API endBlock();
void PROFILER_API setEnabled(bool isEnable);
unsigned int PROFILER_API dumpBlocksToFile(const char* filename);
}
typedef uint8_t block_type_t;

View File

@ -22,6 +22,11 @@ extern "C"{
{
ProfileManager::instance().beginBlock(_block);
}
unsigned int PROFILER_API dumpBlocksToFile(const char* filename)
{
return ProfileManager::instance().dumpBlocksToFile(filename);
}
}
SerilizedBlock::SerilizedBlock(Block* block):
@ -85,14 +90,7 @@ ProfileManager::ProfileManager()
ProfileManager::~ProfileManager()
{
std::ofstream of("test.prof",std::fstream::binary);
for (auto* b : m_blocks){
uint16_t sz = b->size();
of.write((const char*)&sz, sizeof(uint16_t));
of.write(b->data(), b->size());
delete b;
}
//dumpBlocksToFile("test.prof");
}
ProfileManager& ProfileManager::instance()
@ -149,3 +147,20 @@ void ProfileManager::_internalInsertBlock(profiler::Block* _block)
guard_lock_t lock(m_storedSpin);
m_blocks.emplace_back(new SerilizedBlock(_block));
}
unsigned int ProfileManager::dumpBlocksToFile(const char* filename)
{
std::ofstream of(filename, std::fstream::binary);
for (auto* b : m_blocks){
uint16_t sz = b->size();
of.write((const char*)&sz, sizeof(uint16_t));
of.write(b->data(), b->size());
delete b;
}
unsigned int size = (unsigned int)m_blocks.size();
m_blocks.clear();
return size;
}

View File

@ -73,6 +73,7 @@ public:
void beginBlock(profiler::Block* _block);
void endBlock();
void setEnabled(bool isEnable);
unsigned int dumpBlocksToFile(const char* filename);
};
#endif