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

(Core) Fixed serious error caused by invoking endBlock() while dumping blocks to stream/file

This commit is contained in:
Victor Zarubkin 2017-04-06 23:10:14 +03:00
parent 654bfdf9da
commit a9d13deb18
3 changed files with 21 additions and 3 deletions

View File

@ -62,6 +62,14 @@ BaseBlockData::BaseBlockData(timestamp_t _begin_time, block_id_t _descriptor_id)
}
BaseBlockData::BaseBlockData(timestamp_t _begin_time, timestamp_t _end_time, block_id_t _descriptor_id)
: m_begin(_begin_time)
, m_end(_end_time)
, m_id(_descriptor_id)
{
}
Block::Block(Block&& that)
: BaseBlockData(that.m_begin, that.m_id)
, m_name(that.m_name)
@ -78,6 +86,14 @@ Block::Block(timestamp_t _begin_time, block_id_t _descriptor_id, const char* _ru
}
Block::Block(timestamp_t _begin_time, timestamp_t _end_time, block_id_t _descriptor_id, const char* _runtimeName)
: BaseBlockData(_begin_time, _end_time, _descriptor_id)
, m_name(_runtimeName)
, m_status(::profiler::ON)
{
}
Block::Block(const BaseBlockDescriptor* _descriptor, const char* _runtimeName)
: BaseBlockData(1ULL, _descriptor->id())
, m_name(_runtimeName)

View File

@ -468,6 +468,7 @@ namespace profiler {
BaseBlockData(const BaseBlockData&) = default;
BaseBlockData(timestamp_t _begin_time, block_id_t _id);
BaseBlockData(timestamp_t _begin_time, timestamp_t _end_time, block_id_t _id);
inline timestamp_t begin() const { return m_begin; }
inline timestamp_t end() const { return m_end; }
@ -508,6 +509,7 @@ namespace profiler {
Block(Block&& that);
Block(const BaseBlockDescriptor* _desc, const char* _runtimeName);
Block(timestamp_t _begin_time, block_id_t _id, const char* _runtimeName);
Block(timestamp_t _begin_time, timestamp_t _end_time, block_id_t _id, const char* _runtimeName);
~Block();
inline const char* name() const { return m_name; }

View File

@ -938,7 +938,7 @@ void ProfileManager::beginContextSwitch(profiler::thread_id_t _thread_id, profil
if (ts != nullptr)
// Dirty hack: _target_thread_id will be written to the field "block_id_t m_id"
// and will be available calling method id().
ts->sync.openedList.emplace(_time, _target_thread_id, _target_process);
ts->sync.openedList.emplace(_time, _time, _target_thread_id, _target_process);
}
//////////////////////////////////////////////////////////////////////////
@ -1006,7 +1006,7 @@ void ProfileManager::endContextSwitch(profiler::thread_id_t _thread_id, processi
return;
Block& lastBlock = ts->sync.openedList.top();
lastBlock.finish(_endtime);
lastBlock.m_end = _endtime;
ts->storeCSwitch(lastBlock);
ts->sync.openedList.pop();
@ -1395,7 +1395,7 @@ uint32_t ProfileManager::dumpBlocksToStream(profiler::OStream& _outputStream, bo
t.blocks.closedList.serialize(_outputStream);
t.clearClosed();
t.blocks.openedList.clear();
//t.blocks.openedList.clear();
t.sync.openedList.clear();
if (t.expired.load(std::memory_order_acquire) != 0)