0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 16:11:02 +08:00

Added reader example

This commit is contained in:
Sergey Yagovtsev 2016-02-24 06:30:13 +03:00
parent 5dfb456176
commit c6c09dbe32
2 changed files with 63 additions and 0 deletions

20
reader/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
project(profiler_reader)
set(CPP_FILES
main.cpp
)
set(SOURCES
${CPP_FILES}
)
add_definitions(
#-DFULL_DISABLE_PROFILER
)
add_executable(${PROJECT_NAME} ${SOURCES})
if(UNIX)
set(SPEC_LIB pthread)
endif(UNIX)
target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB})

43
reader/main.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "profiler/profiler.h"
#include <fstream>
#include <list>
#include <iostream>
template<class T>
struct tree
{
typedef tree<T> tree_t;
tree_t* parent;
};
int main()
{
std::ifstream inFile("test.prof", std::fstream::binary);
if (!inFile.is_open()){
return -1;
}
std::list<profiler::SerilizedBlock> blocksList;
while (!inFile.eof()){
uint16_t sz = 0;
inFile.read((char*)&sz, sizeof(sz));
if (sz == 0)
{
inFile.read((char*)&sz, sizeof(sz));
continue;
}
char* data = new char[sz];
inFile.read((char*)&data[0], sz);
blocksList.emplace_back(sz, data);
}
for (auto& i : blocksList){
static auto thread_id = i.block()->thread_id;
//if (i.block()->thread_id == thread_id)
std::cout << i.block()->duration() << "\n";
//std::cout << i.getBlockName() << ":" << (i.block()->end - i.block()->begin)/1000 << " usec." << std::endl;
}
return 0;
}