From 43b6d1312be1166201bdb6878de48d6340b2befb Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Wed, 7 Jun 2017 02:08:53 +0300 Subject: [PATCH] (GUI) Added possibility to display only frames (top-level blocks) on histogram to be able to find unexpected blocks on top level. Use [Settings] -> [Only frames on histogram] --- profiler_gui/easy_graphics_scrollbar.cpp | 33 ++++++++++++++++++++++-- profiler_gui/easy_graphics_scrollbar.h | 6 +++++ profiler_gui/globals.cpp | 3 +++ profiler_gui/globals.h | 1 + profiler_gui/globals_qobjects.h | 1 + profiler_gui/main_window.cpp | 18 +++++++++++++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/profiler_gui/easy_graphics_scrollbar.cpp b/profiler_gui/easy_graphics_scrollbar.cpp index faf18df..a8de2e0 100644 --- a/profiler_gui/easy_graphics_scrollbar.cpp +++ b/profiler_gui/easy_graphics_scrollbar.cpp @@ -781,6 +781,26 @@ void EasyHistogramItem::setBoundingRect(qreal x, qreal y, qreal w, qreal h) m_boundingRect.setRect(x, y, w, h); } +void EasyHistogramItem::rebuildSource(HistRegime _regime) +{ + if (m_regime == _regime) + rebuildSource(); +} + +void EasyHistogramItem::rebuildSource() +{ + if (m_regime == Hist_Id) + { + m_regime = Hist_Pointer; + setSource(m_threadId, m_blockId); + } + else + { + m_regime = Hist_Id; + setSource(m_threadId, m_pSource); + } +} + void EasyHistogramItem::setSource(::profiler::thread_id_t _thread_id, const ::profiler_gui::EasyItems* _items) { if (m_regime == Hist_Pointer && m_threadId == _thread_id && m_pSource == _items) @@ -965,7 +985,7 @@ void EasyHistogramItem::setSource(::profiler::thread_id_t _thread_id, ::profiler m_threadWaitTime = root.wait_time; m_bReady.store(false, ::std::memory_order_release); - m_workerThread = ::std::thread([this](decltype(root) profiler_thread, ::profiler::block_index_t selected_block) + m_workerThread = ::std::thread([this](decltype(root) profiler_thread, ::profiler::block_index_t selected_block, bool _showOnlyTopLevelBlocks) { typedef ::std::vector<::std::pair<::profiler::block_index_t, ::profiler::block_index_t> > Stack; @@ -994,6 +1014,9 @@ void EasyHistogramItem::setSource(::profiler::thread_id_t _thread_id, ::profiler m_blockTotalDuraion += w; } + if (_showOnlyTopLevelBlocks) + continue; + stack.push_back(::std::make_pair(frame, 0U)); while (!stack.empty()) { @@ -1080,7 +1103,7 @@ void EasyHistogramItem::setSource(::profiler::thread_id_t _thread_id, ::profiler m_bReady.store(true, ::std::memory_order_release); - }, std::ref(root), EASY_GLOBALS.selected_block); + }, std::ref(root), EASY_GLOBALS.selected_block, EASY_GLOBALS.display_only_frames_on_histogram); m_timeouts = 3; m_timer.start(WORKER_THREAD_CHECK_INTERVAL); @@ -1737,6 +1760,12 @@ EasyGraphicsScrollbar::EasyGraphicsScrollbar(QWidget* _parent) m_histogramItem->onModeChanged(); }); + connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::displayOnlyFramesOnHistogramChanged, [this]() + { + if (m_histogramItem->isVisible()) + m_histogramItem->rebuildSource(EasyHistogramItem::Hist_Id); + }); + connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::threadNameDecorationChanged, this, &This::onThreadViewChanged); connect(&EASY_GLOBALS.events, &::profiler_gui::EasyGlobalSignals::hexThreadIdChanged, this, &This::onThreadViewChanged); diff --git a/profiler_gui/easy_graphics_scrollbar.h b/profiler_gui/easy_graphics_scrollbar.h index 3adf61f..06a8ec7 100644 --- a/profiler_gui/easy_graphics_scrollbar.h +++ b/profiler_gui/easy_graphics_scrollbar.h @@ -141,8 +141,12 @@ class EasyHistogramItem : public QGraphicsItem typedef QGraphicsItem Parent; typedef EasyHistogramItem This; +public: + enum HistRegime : uint8_t { Hist_Pointer, Hist_Id }; +private: + QRectF m_boundingRect; qreal m_topDuration; qreal m_bottomDuration; @@ -203,6 +207,8 @@ public: void setSource(::profiler::thread_id_t _thread_id, const ::profiler_gui::EasyItems* _items); void setSource(::profiler::thread_id_t _thread_id, ::profiler::block_id_t _block_id); + void rebuildSource(HistRegime _regime); + void rebuildSource(); void validateName(); void updateImage(); void cancelImageUpdate(); diff --git a/profiler_gui/globals.cpp b/profiler_gui/globals.cpp index 70dcffb..4aa6499 100644 --- a/profiler_gui/globals.cpp +++ b/profiler_gui/globals.cpp @@ -63,6 +63,8 @@ namespace profiler_gui { EasyGlobals& EasyGlobals::instance() { + // It's okay even without C++11 "magic statics" feature because first call happens + // on application initialization - there is only one thread and no data races occur. static EasyGlobals globals; return globals; } @@ -100,6 +102,7 @@ namespace profiler_gui { , highlight_blocks_with_same_id(true) , selecting_block_changes_thread(true) , auto_adjust_histogram_height(true) + , display_only_frames_on_histogram(false) , bind_scene_and_tree_expand_status(true) { diff --git a/profiler_gui/globals.h b/profiler_gui/globals.h index be7ad45..7489f62 100644 --- a/profiler_gui/globals.h +++ b/profiler_gui/globals.h @@ -199,6 +199,7 @@ namespace profiler_gui { bool highlight_blocks_with_same_id; ///< Highlight all blocks with same id on diagram bool selecting_block_changes_thread; ///< If true then current selected thread will change every time you select block bool auto_adjust_histogram_height; ///< Automatically adjust histogram height to the visible region + bool display_only_frames_on_histogram; ///< Display only top-level blocks on histogram when drawing histogram by block id bool bind_scene_and_tree_expand_status; /** \brief If true then items on graphics scene and in the tree (blocks hierarchy) are binded on each other so expanding/collapsing items on scene also expands/collapse items in the tree. */ diff --git a/profiler_gui/globals_qobjects.h b/profiler_gui/globals_qobjects.h index 664c7cc..b34d924 100644 --- a/profiler_gui/globals_qobjects.h +++ b/profiler_gui/globals_qobjects.h @@ -80,6 +80,7 @@ namespace profiler_gui { void blocksRefreshRequired(bool); void expectedFrameTimeChanged(); void autoAdjustHistogramChanged(); + void displayOnlyFramesOnHistogramChanged(); void hierarchyFlagChanged(bool); void threadNameDecorationChanged(); void hexThreadIdChanged(); diff --git a/profiler_gui/main_window.cpp b/profiler_gui/main_window.cpp index 0a2403d..07d0a75 100644 --- a/profiler_gui/main_window.cpp +++ b/profiler_gui/main_window.cpp @@ -258,6 +258,8 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_lastAddress("localhost"), m_lastP toolbar->addSeparator(); auto menu = new QMenu("Settings", this); + menu->setToolTipsVisible(true); + QToolButton* toolButton = new QToolButton(toolbar); toolButton->setIcon(QIcon(":/Settings")); toolButton->setMenu(menu); @@ -282,6 +284,17 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_lastAddress("localhost"), m_lastP } + action = menu->addAction("Only frames on histogram"); + action->setToolTip("Display only top-level blocks on histogram."); + action->setCheckable(true); + action->setChecked(EASY_GLOBALS.display_only_frames_on_histogram); + connect(action, &QAction::triggered, [this](bool _checked) + { + EASY_GLOBALS.display_only_frames_on_histogram = _checked; + emit EASY_GLOBALS.events.displayOnlyFramesOnHistogramChanged(); + }); + + menu->addSeparator(); auto submenu = menu->addMenu("View"); submenu->setToolTipsVisible(true); @@ -1270,6 +1283,10 @@ void EasyMainWindow::loadSettings() if (!flag.isNull()) EASY_GLOBALS.auto_adjust_histogram_height = flag.toBool(); + flag = settings.value("display_only_frames_on_histogram"); + if (!flag.isNull()) + EASY_GLOBALS.display_only_frames_on_histogram = flag.toBool(); + flag = settings.value("use_decorated_thread_name"); if (!flag.isNull()) EASY_GLOBALS.use_decorated_thread_name = flag.toBool(); @@ -1347,6 +1364,7 @@ void EasyMainWindow::saveSettingsAndGeometry() settings.setValue("selecting_block_changes_thread", EASY_GLOBALS.selecting_block_changes_thread); settings.setValue("enable_event_indicators", EASY_GLOBALS.enable_event_markers); settings.setValue("auto_adjust_histogram_height", EASY_GLOBALS.auto_adjust_histogram_height); + settings.setValue("display_only_frames_on_histogram", EASY_GLOBALS.display_only_frames_on_histogram); settings.setValue("use_decorated_thread_name", EASY_GLOBALS.use_decorated_thread_name); settings.setValue("hex_thread_id", EASY_GLOBALS.hex_thread_id); settings.setValue("enable_statistics", EASY_GLOBALS.enable_statistics);