0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 16:51:22 +08:00

Merge branch 'develop' of https://github.com/yse/easy_profiler into develop

This commit is contained in:
Victor Zarubkin 2016-08-01 22:22:23 +03:00
commit bc44bec36d
6 changed files with 35 additions and 2 deletions

View File

@ -146,6 +146,10 @@ void foo()
*/
#define PROFILER_DISABLE profiler::setEnabled(false);
#define PROFILER_SET_THREAD_NAME(name) profiler::setThreadName(name);
#define PROFILER_SET_MAIN_THREAD PROFILER_SET_THREAD_NAME("Main")
#else
#define PROFILER_ADD_MARK(name)
#define PROFILER_ADD_MARK_GROUPED(name,block_group)
@ -158,6 +162,8 @@ void foo()
#define PROFILER_DISABLE profiler::setEnabled(false);
#define PROFILER_ADD_EVENT(name)
#define PROFILER_ADD_EVENT_GROUPED(name,block_group)
#define PROFILER_SET_THREAD_NAME(name)
#define PROFILER_SET_MAIN_THREAD
#endif
#include <stdint.h>
@ -227,6 +233,7 @@ namespace profiler
void PROFILER_API endBlock();
void PROFILER_API setEnabled(bool isEnable);
unsigned int PROFILER_API dumpBlocksToFile(const char* filename);
void PROFILER_API setThreadName(const char* name);
}
typedef uint8_t block_type_t;
@ -235,6 +242,7 @@ namespace profiler
const block_type_t BLOCK_TYPE_EVENT = 1;
const block_type_t BLOCK_TYPE_BLOCK = 2;
const block_type_t BLOCK_TYPE_THREAD_SIGN = 3;
#pragma pack(push,1)
class PROFILER_API BaseBlockData

View File

@ -99,6 +99,7 @@ struct BlocksTree
::profiler::SerilizedBlock* node;
::profiler::BlockStatistics* frame_statistics; ///< Pointer to statistics for this block within the parent (may be nullptr for top-level blocks)
::profiler::BlockStatistics* total_statistics; ///< Pointer to statistics for this block within the bounds of all frames per current thread
const char* thread_name;
#ifdef PROFILER_COUNT_TOTAL_CHILDREN_NUMBER
unsigned int total_children_number; ///< Number of all children including number of grandchildren (and so on)
@ -118,6 +119,7 @@ struct BlocksTree
#ifdef PROFILER_COUNT_DEPTH
, depth(0)
#endif
, thread_name("")
{
}

View File

@ -21,7 +21,7 @@ Block::Block(const char* _name, color_t _color, block_type_t _type) :
name(_name)
{
tick(begin);
if (this->type == BLOCK_TYPE_EVENT)
if (BLOCK_TYPE_BLOCK != this->type)
{
end = begin;
}

View File

@ -27,6 +27,11 @@ extern "C"{
{
return ProfileManager::instance().dumpBlocksToFile(filename);
}
void PROFILER_API setThreadName(const char* name)
{
return ProfileManager::instance().setThreadName(name);
}
}
SerilizedBlock::SerilizedBlock(Block* block):
@ -164,3 +169,14 @@ unsigned int ProfileManager::dumpBlocksToFile(const char* filename)
return size;
}
void ProfileManager::setThreadName(const char* name)
{
profiler::Block block(name, 0, profiler::BLOCK_TYPE_THREAD_SIGN);
auto find_it = m_namedThreades.find(block.getThreadId());
if (find_it != m_namedThreades.end())
return;
_internalInsertBlock(&block);
m_namedThreades.insert(block.getThreadId());
}

View File

@ -26,6 +26,7 @@ along with this program.If not, see <http://www.gnu.org/licenses/>.
#include <stack>
#include <map>
#include <list>
#include <set>
#ifdef WIN32
#include <Windows.h>
@ -54,6 +55,7 @@ class ProfileManager
typedef std::stack<profiler::Block*> stack_of_blocks_t;
typedef std::map<size_t, stack_of_blocks_t> map_of_threads_stacks;
typedef std::set<size_t> set_of_thread_id;
map_of_threads_stacks m_openedBracketsMap;
@ -66,7 +68,7 @@ class ProfileManager
typedef std::list<profiler::SerilizedBlock*> serialized_list_t;
serialized_list_t m_blocks;
set_of_thread_id m_namedThreades;
public:
static ProfileManager& instance();
~ProfileManager();
@ -74,6 +76,7 @@ public:
void endBlock();
void setEnabled(bool isEnable);
unsigned int dumpBlocksToFile(const char* filename);
void setThreadName(const char* name);
};
#endif

View File

@ -239,6 +239,10 @@ extern "C"{
tree.node = new profiler::SerilizedBlock(sz, data);
++blocks_counter;
if (::profiler::BLOCK_TYPE_THREAD_SIGN == baseData->getType()){
root.thread_name = tree.node->getBlockName();
}
if (!root.children.empty())
{
BlocksTree& back = root.children.back();