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

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

# Conflicts:
#	profiler_gui/main_window.cpp
#	src/reader.cpp
This commit is contained in:
Victor Zarubkin 2016-07-10 01:36:02 +03:00
commit 9a616fc693
7 changed files with 105 additions and 31 deletions

View File

@ -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;

View File

@ -14,6 +14,8 @@
* :
* : * 2016/06/29 Victor Zarubkin: Added menu with tests.
* :
* : * 2016/06/30 Sergey Yagovtsev: Open file by command line argument
* :
* : *
* ----------------- :
* license : TODO: add license text
@ -25,6 +27,7 @@
#include <QAction>
#include <QMenu>
#include <QMenuBar>
#include <QCoreApplication>
#include "main_window.h"
#include "blocks_tree_widget.h"
#include "blocks_graphics_view.h"
@ -85,7 +88,14 @@ ProfMainWindow::ProfMainWindow() : QMainWindow(), m_treeWidget(nullptr), m_graph
menu = new QMenu("Tests");
menu->addAction(actionTestView);
menuBar()->addMenu(menu);
}
if(QCoreApplication::arguments().size() > 1)
{
auto opened_filename = QCoreApplication::arguments().at(1).toStdString();
loadFile(opened_filename);
}
}
ProfMainWindow::~ProfMainWindow()
{
@ -96,14 +106,19 @@ ProfMainWindow::~ProfMainWindow()
void ProfMainWindow::onOpenFileClicked(bool)
{
auto filename = QFileDialog::getOpenFileName(this, "Open profiler log", m_lastFile.c_str(), "Profiler Log File (*.prof);;All Files (*.*)");
auto stdfilename = filename.toStdString();
loadFile(filename.toStdString());
}
//////////////////////////////////////////////////////////////////////////
void ProfMainWindow::loadFile(const std::string& stdfilename)
{
thread_blocks_tree_t prof_blocks;
auto nblocks = fillTreesFromFile(stdfilename.c_str(), prof_blocks, true);
if (nblocks != 0)
{
m_lastFile.swap(stdfilename);
m_lastFile = stdfilename;
m_currentProf.swap(prof_blocks);
static_cast<ProfTreeWidget*>(m_treeWidget->widget())->setTree(nblocks, m_currentProf);
static_cast<ProfGraphicsView*>(m_graphicsView->widget())->setTree(m_currentProf);

View File

@ -1,17 +1,17 @@
/************************************************************************
* file name : main_window.h
* ----------------- :
* creation time : 2016/06/26
* copyright : (c) 2016 Victor Zarubkin
* author : Victor Zarubkin
* email : v.s.zarubkin@gmail.com
* ----------------- :
* description : The file contains declaration of MainWindow for easy_profiler GUI.
* ----------------- :
* change log : * 2016/06/26 Victor Zarubkin: initial commit.
* : *
* ----------------- :
* license : TODO: add license text
/************************************************************************
* file name : main_window.h
* ----------------- :
* creation time : 2016/06/26
* copyright : (c) 2016 Victor Zarubkin
* author : Victor Zarubkin
* email : v.s.zarubkin@gmail.com
* ----------------- :
* description : The file contains declaration of MainWindow for easy_profiler GUI.
* ----------------- :
* change log : * 2016/06/26 Victor Zarubkin: initial commit.
* : *
* ----------------- :
* license : TODO: add license text
************************************************************************/
#ifndef EASY_PROFILER_GUI__MAIN_WINDOW__H
@ -52,6 +52,10 @@ protected slots:
void onExitClicked(bool);
void onTestViewportClicked(bool);
private:
void loadFile(const std::string& filename);
}; // END of class ProfMainWindow.
//////////////////////////////////////////////////////////////////////////

View File

@ -69,13 +69,30 @@ void printTree(TreePrinter& printer, const BlocksTree& tree, int level = 0, prof
}
}
int main()
int main(int argc, char* argv[])
{
thread_blocks_tree_t threaded_trees;
const char* filename = nullptr;
if(argc > 1 && argv[1]){
filename = argv[1];
}else{
std::cout << "Specify prof file!" << std::endl;
return 255;
}
const char* dump_filename = nullptr;
if(argc > 2 && argv[2]){
dump_filename = argv[2];
PROFILER_ENABLE
std::cout << "Will dump reader prof file to " << dump_filename << std::endl;
}
auto start = std::chrono::system_clock::now();
auto blocks_counter = fillTreesFromFile("test.prof", threaded_trees, true);
auto blocks_counter = fillTreesFromFile(filename, threaded_trees, true);
auto end = std::chrono::system_clock::now();
@ -86,5 +103,14 @@ int main()
std::cout << std::string(20, '=') << " thread "<< i.first << " "<< std::string(20, '=') << std::endl;
printTree(p, i.second,-1);
}
if(dump_filename!=nullptr)
{
auto bcount = profiler::dumpBlocksToFile(dump_filename);
std::cout << "Blocks count for reader: " << bcount << std::endl;
}
return 0;
}

View File

@ -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;
}

View File

@ -73,6 +73,7 @@ public:
void beginBlock(profiler::Block* _block);
void endBlock();
void setEnabled(bool isEnable);
unsigned int dumpBlocksToFile(const char* filename);
};
#endif

View File

@ -219,6 +219,7 @@ extern "C"{
unsigned int blocks_counter = 0;
while (!inFile.eof()){
PROFILER_BEGIN_BLOCK("Read block from file")
uint16_t sz = 0;
inFile.read((char*)&sz, sizeof(sz));
if (sz == 0)
@ -245,14 +246,24 @@ extern "C"{
auto mt0 = tree.node->block()->getBegin();
if (mt0 < t1)//parent - starts earlier than last ends
{
auto lower = std::lower_bound(root.children.begin(), root.children.end(), tree);
//auto lower = std::lower_bound(root.children.begin(), root.children.end(), tree);
/**/
PROFILER_BEGIN_BLOCK("Find children")
auto rlower1 = ++root.children.rbegin();
for(; rlower1 != root.children.rend(); ++rlower1){
if(mt0 > rlower1->node->block()->getBegin())
{
break;
}
}
auto lower = rlower1.base();
std::move(lower, root.children.end(), std::back_inserter(tree.children));
root.children.erase(lower, root.children.end());
if (gather_statistics)
{
PROFILER_BEGIN_BLOCK("Gather statistic for frame")
frame_statistics.clear();
//frame_statistics.reserve(tree.children.size()); // this gives slow-down on Windows
@ -282,12 +293,13 @@ extern "C"{
if (gather_statistics)
{
PROFILER_BEGIN_BLOCK("Gather statistic")
BlocksTree& current = root.children.back();
update_statistics(overall_statistics, current.node, current.total_statistics);
}
}
PROFILER_BEGIN_BLOCK("Gather statistic for roots")
if (gather_statistics)
{
for (auto& root_value : threaded_trees)
@ -321,7 +333,7 @@ extern "C"{
++root.sublevels;
}
}
PROFILER_END_BLOCK
// No need to delete BlockStatistics instances - they will be deleted inside BlocksTree destructors
return blocks_counter;