From 82e9920e159928ec3ff488068afb4d0902e2a85f Mon Sep 17 00:00:00 2001 From: Sergey Yagovtsev Date: Mon, 4 Jul 2016 22:53:02 +0300 Subject: [PATCH] Add dumpBLocksToFile function --- include/profiler/profiler.h | 1 + src/profile_manager.cpp | 31 +++++++++++++++++++++++-------- src/profile_manager.h | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/include/profiler/profiler.h b/include/profiler/profiler.h index 5839700..2358799 100644 --- a/include/profiler/profiler.h +++ b/include/profiler/profiler.h @@ -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; diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index a5b4b58..ff78cd3 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -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; +} diff --git a/src/profile_manager.h b/src/profile_manager.h index b433aa7..6819e10 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -73,6 +73,7 @@ public: void beginBlock(profiler::Block* _block); void endBlock(); void setEnabled(bool isEnable); + unsigned int dumpBlocksToFile(const char* filename); }; #endif