mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-26 08:01:51 +08:00
Move serialized block in header
This commit is contained in:
parent
c6c09dbe32
commit
0d986a6464
@ -29,3 +29,4 @@ endif(UNIX)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(sample)
|
||||
add_subdirectory(reader)
|
@ -102,6 +102,8 @@ namespace profiler
|
||||
thread_id_t thread_id;
|
||||
|
||||
BaseBlockData(color_t _color, block_type_t _type);
|
||||
|
||||
timestamp_t duration() const { return (end - begin); }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
@ -109,6 +111,7 @@ namespace profiler
|
||||
{
|
||||
const char *name;
|
||||
void tick(timestamp_t& stamp);
|
||||
|
||||
public:
|
||||
|
||||
Block(const char* _name, color_t _color = 0, block_type_t _type = BLOCK_TYPE_MARK);
|
||||
@ -125,8 +128,26 @@ namespace profiler
|
||||
inline void finish(){ tick(end); }
|
||||
|
||||
~Block();
|
||||
|
||||
};
|
||||
|
||||
class PROFILER_API SerilizedBlock
|
||||
{
|
||||
uint16_t m_size;
|
||||
char* m_data;
|
||||
public:
|
||||
SerilizedBlock(profiler::Block* block);
|
||||
SerilizedBlock(uint16_t _size, const char* _data);
|
||||
SerilizedBlock(SerilizedBlock&& that);
|
||||
~SerilizedBlock();
|
||||
|
||||
const char* const data() const { return m_data; }
|
||||
uint16_t size() const { return m_size; }
|
||||
|
||||
const BaseBlockData * block();
|
||||
const char* getBlockName();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -42,5 +42,8 @@ Block::~Block()
|
||||
|
||||
endBlock();
|
||||
}
|
||||
else{//for mark end equal begin
|
||||
end = begin;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,14 @@ SerilizedBlock::SerilizedBlock(Block* block):
|
||||
m_data = new char[m_size];
|
||||
memcpy(&m_data[0], block, sizeof(BaseBlockData));
|
||||
strncpy(&m_data[sizeof(BaseBlockData)], block->getName(), name_len);
|
||||
}
|
||||
|
||||
SerilizedBlock::SerilizedBlock(uint16_t _size, const char* _data) :
|
||||
m_size(_size),
|
||||
m_data(nullptr)
|
||||
{
|
||||
m_data = new char[m_size];
|
||||
memcpy(&m_data[0], _data, m_size);
|
||||
}
|
||||
|
||||
SerilizedBlock::~SerilizedBlock()
|
||||
@ -45,6 +52,23 @@ SerilizedBlock::~SerilizedBlock()
|
||||
}
|
||||
}
|
||||
|
||||
SerilizedBlock::SerilizedBlock(SerilizedBlock&& that)
|
||||
{
|
||||
m_size = that.m_size;
|
||||
m_data = that.m_data;
|
||||
that.m_size = 0;
|
||||
that.m_data = nullptr;
|
||||
}
|
||||
|
||||
const BaseBlockData * SerilizedBlock::block()
|
||||
{
|
||||
return (BaseBlockData*)m_data;
|
||||
}
|
||||
|
||||
const char* SerilizedBlock::getBlockName()
|
||||
{
|
||||
return (const char*)&m_data[sizeof(profiler::BaseBlockData)];
|
||||
}
|
||||
|
||||
ProfileManager::ProfileManager()
|
||||
{
|
||||
|
@ -27,19 +27,6 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
||||
class SerilizedBlock
|
||||
{
|
||||
uint16_t m_size;
|
||||
char* m_data;
|
||||
public:
|
||||
|
||||
SerilizedBlock(profiler::Block* block);
|
||||
~SerilizedBlock();
|
||||
|
||||
const char* const data() { return m_data; }
|
||||
uint16_t size() const { return m_size; }
|
||||
};
|
||||
|
||||
class ProfileManager
|
||||
{
|
||||
ProfileManager();
|
||||
@ -60,7 +47,7 @@ class ProfileManager
|
||||
|
||||
void _internalInsertBlock(profiler::Block* _block);
|
||||
|
||||
typedef std::list<SerilizedBlock*> serialized_list_t;
|
||||
typedef std::list<profiler::SerilizedBlock*> serialized_list_t;
|
||||
serialized_list_t m_blocks;
|
||||
public:
|
||||
static ProfileManager& instance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user