From 97d009bd46007263537b92828c63eeb8c027c779 Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Tue, 9 Aug 2016 00:14:58 +0300 Subject: [PATCH] (ProfTreeWidget) Displays only relevant statistics; (profiler_gui) Comments in globals.h --- profiler_gui/blocks_tree_widget.cpp | 94 ++++++++++++++++++----------- profiler_gui/blocks_tree_widget.h | 3 +- profiler_gui/globals.cpp | 1 + profiler_gui/globals.h | 13 ++-- 4 files changed, 70 insertions(+), 41 deletions(-) diff --git a/profiler_gui/blocks_tree_widget.cpp b/profiler_gui/blocks_tree_widget.cpp index 1f0bf07..14b8988 100644 --- a/profiler_gui/blocks_tree_widget.cpp +++ b/profiler_gui/blocks_tree_widget.cpp @@ -63,16 +63,16 @@ enum ColumnsIndexes COL_AVERAGE_PER_FRAME, COL_NCALLS_PER_FRAME, - COL_MIN_PER_PARENT, - COL_MAX_PER_PARENT, - COL_AVERAGE_PER_PARENT, - COL_NCALLS_PER_PARENT, - COL_MIN_PER_THREAD, COL_MAX_PER_THREAD, COL_AVERAGE_PER_THREAD, COL_NCALLS_PER_THREAD, + COL_MIN_PER_PARENT, + COL_MAX_PER_PARENT, + COL_AVERAGE_PER_PARENT, + COL_NCALLS_PER_PARENT, + COL_COLUMNS_NUMBER }; @@ -149,7 +149,7 @@ const ::profiler::BlocksTree* ProfTreeWidgetItem::block() const return data(COL_SELF_DURATION, Qt::UserRole).toULongLong(); } -void ProfTreeWidgetItem::setTimeSmart(int _column, const ::profiler::timestamp_t& _time) +void ProfTreeWidgetItem::setTimeSmart(int _column, const ::profiler::timestamp_t& _time, const QString& _prefix) { const ::profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); @@ -159,19 +159,19 @@ void ProfTreeWidgetItem::setTimeSmart(int _column, const ::profiler::timestamp_t if (_time < 1e3) { - setText(_column, QString("%1 ns").arg(nanosecondsTime)); + setText(_column, QString("%1%2 ns").arg(_prefix).arg(nanosecondsTime)); } else if (_time < 1e6) { - setText(_column, QString("%1 us").arg(double(nanosecondsTime) * 1e-3, 0, 'f', 3)); + setText(_column, QString("%1%2 us").arg(_prefix).arg(double(nanosecondsTime) * 1e-3, 0, 'f', 3)); } else if (_time < 1e9) { - setText(_column, QString("%1 ms").arg(double(nanosecondsTime) * 1e-6, 0, 'f', 3)); + setText(_column, QString("%1%2 ms").arg(_prefix).arg(double(nanosecondsTime) * 1e-6, 0, 'f', 3)); } else { - setText(_column, QString("%1 s").arg(double(nanosecondsTime) * 1e-9, 0, 'f', 3)); + setText(_column, QString("%1%2 s").arg(_prefix).arg(double(nanosecondsTime) * 1e-9, 0, 'f', 3)); } } @@ -183,6 +183,14 @@ void ProfTreeWidgetItem::setTimeMs(int _column, const ::profiler::timestamp_t& _ setText(_column, QString::number(double(nanosecondsTime) * 1e-6, 'g', 9)); } +void ProfTreeWidgetItem::setTimeMs(int _column, const ::profiler::timestamp_t& _time, const QString& _prefix) +{ + const ::profiler::timestamp_t nanosecondsTime = PROF_NANOSECONDS(_time); + setData(_column, Qt::UserRole, (quint64)nanosecondsTime); + setToolTip(_column, QString("%1 ns").arg(nanosecondsTime)); + setText(_column, QString("%1%2").arg(_prefix).arg(double(nanosecondsTime) * 1e-6, 0, 'g', 9)); +} + void ProfTreeWidgetItem::setBackgroundColor(QRgb _color) { m_customBGColor = _color; @@ -531,10 +539,13 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks if (block.tree->per_thread_stats) { - item->setTimeSmart(COL_MIN_PER_THREAD, block.tree->per_thread_stats->min_duration); - item->setTimeSmart(COL_MAX_PER_THREAD, block.tree->per_thread_stats->max_duration); - item->setTimeSmart(COL_AVERAGE_PER_THREAD, block.tree->per_thread_stats->average_duration()); - item->setTimeSmart(COL_DURATION_SUM_PER_THREAD, block.tree->per_thread_stats->total_duration); + if (block.tree->per_thread_stats->calls_number > 1 || !::profiler_gui::EASY_GLOBALS.display_only_relevant_stats) + { + item->setTimeSmart(COL_MIN_PER_THREAD, block.tree->per_thread_stats->min_duration, "min "); + item->setTimeSmart(COL_MAX_PER_THREAD, block.tree->per_thread_stats->max_duration, "max "); + item->setTimeSmart(COL_AVERAGE_PER_THREAD, block.tree->per_thread_stats->average_duration()); + item->setTimeSmart(COL_DURATION_SUM_PER_THREAD, block.tree->per_thread_stats->total_duration); + } item->setData(COL_NCALLS_PER_THREAD, Qt::UserRole, block.tree->per_thread_stats->calls_number); item->setText(COL_NCALLS_PER_THREAD, QString::number(block.tree->per_thread_stats->calls_number)); @@ -551,10 +562,13 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks if (block.tree->per_parent_stats) { - item->setTimeSmart(COL_MIN_PER_PARENT, block.tree->per_parent_stats->min_duration); - item->setTimeSmart(COL_MAX_PER_PARENT, block.tree->per_parent_stats->max_duration); - item->setTimeSmart(COL_AVERAGE_PER_PARENT, block.tree->per_parent_stats->average_duration()); - item->setTimeSmart(COL_DURATION_SUM_PER_PARENT, block.tree->per_parent_stats->total_duration); + if (block.tree->per_parent_stats->calls_number > 1 || !::profiler_gui::EASY_GLOBALS.display_only_relevant_stats) + { + item->setTimeSmart(COL_MIN_PER_PARENT, block.tree->per_parent_stats->min_duration, "min "); + item->setTimeSmart(COL_MAX_PER_PARENT, block.tree->per_parent_stats->max_duration, "max "); + item->setTimeSmart(COL_AVERAGE_PER_PARENT, block.tree->per_parent_stats->average_duration()); + item->setTimeSmart(COL_DURATION_SUM_PER_PARENT, block.tree->per_parent_stats->total_duration); + } item->setData(COL_NCALLS_PER_PARENT, Qt::UserRole, block.tree->per_parent_stats->calls_number); item->setText(COL_NCALLS_PER_PARENT, QString::number(block.tree->per_parent_stats->calls_number)); @@ -562,10 +576,13 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler_gui::TreeBlocks& _blocks if (block.tree->per_frame_stats) { - item->setTimeSmart(COL_MIN_PER_FRAME, block.tree->per_frame_stats->min_duration); - item->setTimeSmart(COL_MAX_PER_FRAME, block.tree->per_frame_stats->max_duration); - item->setTimeSmart(COL_AVERAGE_PER_FRAME, block.tree->per_frame_stats->average_duration()); - item->setTimeSmart(COL_DURATION_SUM_PER_FRAME, block.tree->per_frame_stats->total_duration); + if (block.tree->per_frame_stats->calls_number > 1 || !::profiler_gui::EASY_GLOBALS.display_only_relevant_stats) + { + item->setTimeSmart(COL_MIN_PER_FRAME, block.tree->per_frame_stats->min_duration, "min "); + item->setTimeSmart(COL_MAX_PER_FRAME, block.tree->per_frame_stats->max_duration, "max "); + item->setTimeSmart(COL_AVERAGE_PER_FRAME, block.tree->per_frame_stats->average_duration()); + item->setTimeSmart(COL_DURATION_SUM_PER_FRAME, block.tree->per_frame_stats->total_duration); + } item->setData(COL_NCALLS_PER_FRAME, Qt::UserRole, block.tree->per_frame_stats->calls_number); item->setText(COL_NCALLS_PER_FRAME, QString::number(block.tree->per_frame_stats->calls_number)); @@ -696,10 +713,13 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler::BlocksTree::children_t& if (child.per_thread_stats) { - item->setTimeSmart(COL_MIN_PER_THREAD, child.per_thread_stats->min_duration); - item->setTimeSmart(COL_MAX_PER_THREAD, child.per_thread_stats->max_duration); - item->setTimeSmart(COL_AVERAGE_PER_THREAD, child.per_thread_stats->average_duration()); - item->setTimeSmart(COL_DURATION_SUM_PER_THREAD, child.per_thread_stats->total_duration); + if (child.per_thread_stats->calls_number > 1 || !::profiler_gui::EASY_GLOBALS.display_only_relevant_stats) + { + item->setTimeSmart(COL_MIN_PER_THREAD, child.per_thread_stats->min_duration, "min "); + item->setTimeSmart(COL_MAX_PER_THREAD, child.per_thread_stats->max_duration, "max "); + item->setTimeSmart(COL_AVERAGE_PER_THREAD, child.per_thread_stats->average_duration()); + item->setTimeSmart(COL_DURATION_SUM_PER_THREAD, child.per_thread_stats->total_duration); + } item->setData(COL_NCALLS_PER_THREAD, Qt::UserRole, child.per_thread_stats->calls_number); item->setText(COL_NCALLS_PER_THREAD, QString::number(child.per_thread_stats->calls_number)); @@ -714,10 +734,13 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler::BlocksTree::children_t& if (child.per_parent_stats) { - item->setTimeSmart(COL_MIN_PER_PARENT, child.per_parent_stats->min_duration); - item->setTimeSmart(COL_MAX_PER_PARENT, child.per_parent_stats->max_duration); - item->setTimeSmart(COL_AVERAGE_PER_PARENT, child.per_parent_stats->average_duration()); - item->setTimeSmart(COL_DURATION_SUM_PER_PARENT, child.per_parent_stats->total_duration); + if (child.per_parent_stats->calls_number > 1 || !::profiler_gui::EASY_GLOBALS.display_only_relevant_stats) + { + item->setTimeSmart(COL_MIN_PER_PARENT, child.per_parent_stats->min_duration, "min "); + item->setTimeSmart(COL_MAX_PER_PARENT, child.per_parent_stats->max_duration, "max "); + item->setTimeSmart(COL_AVERAGE_PER_PARENT, child.per_parent_stats->average_duration()); + item->setTimeSmart(COL_DURATION_SUM_PER_PARENT, child.per_parent_stats->total_duration); + } item->setData(COL_NCALLS_PER_PARENT, Qt::UserRole, child.per_parent_stats->calls_number); item->setText(COL_NCALLS_PER_PARENT, QString::number(child.per_parent_stats->calls_number)); @@ -725,10 +748,13 @@ size_t ProfTreeWidget::setTreeInternal(const ::profiler::BlocksTree::children_t& if (child.per_frame_stats) { - item->setTimeSmart(COL_MIN_PER_FRAME, child.per_frame_stats->min_duration); - item->setTimeSmart(COL_MAX_PER_FRAME, child.per_frame_stats->max_duration); - item->setTimeSmart(COL_AVERAGE_PER_FRAME, child.per_frame_stats->average_duration()); - item->setTimeSmart(COL_DURATION_SUM_PER_FRAME, child.per_frame_stats->total_duration); + if (child.per_frame_stats->calls_number > 1 || !::profiler_gui::EASY_GLOBALS.display_only_relevant_stats) + { + item->setTimeSmart(COL_MIN_PER_FRAME, child.per_frame_stats->min_duration, "min "); + item->setTimeSmart(COL_MAX_PER_FRAME, child.per_frame_stats->max_duration, "max "); + item->setTimeSmart(COL_AVERAGE_PER_FRAME, child.per_frame_stats->average_duration()); + item->setTimeSmart(COL_DURATION_SUM_PER_FRAME, child.per_frame_stats->total_duration); + } item->setData(COL_NCALLS_PER_FRAME, Qt::UserRole, child.per_frame_stats->calls_number); item->setText(COL_NCALLS_PER_FRAME, QString::number(child.per_frame_stats->calls_number)); diff --git a/profiler_gui/blocks_tree_widget.h b/profiler_gui/blocks_tree_widget.h index 03a39db..53cbd01 100644 --- a/profiler_gui/blocks_tree_widget.h +++ b/profiler_gui/blocks_tree_widget.h @@ -61,9 +61,10 @@ public: ::profiler::timestamp_t duration() const; ::profiler::timestamp_t selfDuration() const; - void setTimeSmart(int _column, const ::profiler::timestamp_t& _time); + void setTimeSmart(int _column, const ::profiler::timestamp_t& _time, const QString& _prefix = ""); void setTimeMs(int _column, const ::profiler::timestamp_t& _time); + void setTimeMs(int _column, const ::profiler::timestamp_t& _time, const QString& _prefix); void setBackgroundColor(QRgb _color); diff --git a/profiler_gui/globals.cpp b/profiler_gui/globals.cpp index 3edca32..8659e7b 100644 --- a/profiler_gui/globals.cpp +++ b/profiler_gui/globals.cpp @@ -34,6 +34,7 @@ namespace profiler_gui { : selected_thread(0) , selected_block(-1) , draw_graphics_items_borders(true) + , display_only_relevant_stats(true) { } diff --git a/profiler_gui/globals.h b/profiler_gui/globals.h index 8a65f49..ced0cd7 100644 --- a/profiler_gui/globals.h +++ b/profiler_gui/globals.h @@ -62,12 +62,13 @@ namespace profiler_gui { { static ProfGlobals& instance(); - ProfGlobalSignals events; - ::profiler::thread_blocks_tree_t profiler_blocks; - ProfBlocks gui_blocks; - ::profiler::thread_id_t selected_thread; - unsigned int selected_block; - bool draw_graphics_items_borders; + ProfGlobalSignals events; ///< Global signals + ::profiler::thread_blocks_tree_t profiler_blocks; ///< Profiler blocks tree loaded from file + ProfBlocks gui_blocks; ///< Profiler graphics blocks builded by GUI + ::profiler::thread_id_t selected_thread; ///< Current selected thread id + unsigned int selected_block; ///< Current selected profiler block index + bool draw_graphics_items_borders; ///< Draw borders for graphics blocks or not + bool display_only_relevant_stats; ///< Display only relevant information in ProfTreeWidget (excludes min, max, average times if there are only 1 calls number) private: