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

#31 [Gui] Arbitrary values viewer bug fixes

This commit is contained in:
Victor Zarubkin 2018-01-28 02:01:49 +03:00
parent 230f7d1463
commit 1f6d3c2a7d
8 changed files with 156 additions and 74 deletions

View File

@ -64,6 +64,7 @@
#include <QToolBar>
#include <QAction>
#include <list>
#include <cmath>
#include "arbitrary_value_inspector.h"
#include "treeview_first_column_delegate.h"
#include "globals.h"
@ -150,7 +151,7 @@ ArbitraryValuesCollection::ArbitraryValuesCollection()
ArbitraryValuesCollection::~ArbitraryValuesCollection()
{
interrupt();
join();
}
const ArbitraryValuesMap& ArbitraryValuesCollection::valuesMap() const
@ -243,16 +244,26 @@ bool ArbitraryValuesCollection::calculatePoints(profiler::timestamp_t _beginTime
void ArbitraryValuesCollection::interrupt()
{
if (!m_collectorThread.joinable())
return;
if (m_collectorThread.joinable())
{
m_bInterrupt.store(true, std::memory_order_release);
m_collectorThread.join();
m_bInterrupt.store(false, std::memory_order_release);
m_bInterrupt.store(true, std::memory_order_release);
m_collectorThread.join();
m_bInterrupt.store(false, std::memory_order_release);
setStatus(Idle);
m_jobType = None;
m_values.clear();
}
}
setStatus(Idle);
m_jobType = None;
m_values.clear();
void ArbitraryValuesCollection::join()
{
if (m_collectorThread.joinable())
{
m_bInterrupt.store(true, std::memory_order_release);
m_collectorThread.join();
m_bInterrupt.store(false, std::memory_order_release);
}
}
void ArbitraryValuesCollection::setStatus(JobStatus _status)
@ -733,6 +744,7 @@ void ArbitraryValuesChartItem::updateImageAsync(QRectF _boundingRect, qreal _cur
if (c.chartType == ChartType::Points)
{
qreal prevX = 1e300, prevY = 1e300;
for (auto it = first; it != points.end() && it->x() < _maximum; ++it)
{
if (it->x() < _minimum)
@ -743,7 +755,14 @@ void ArbitraryValuesChartItem::updateImageAsync(QRectF _boundingRect, qreal _cur
const qreal x = it->x() * realScale - offset;
const qreal y = gety(it->y());
p.drawPoint(QPointF {x, y});
const auto dx = fabs(x - prevX), dy = fabs(y - prevY);
if (dx > 1 || dy > 1)
{
p.drawPoint(QPointF{x, y});
prevX = x;
prevY = y;
}
}
}
else if (first != points.end() && first->x() < _maximum)
@ -767,7 +786,13 @@ void ArbitraryValuesChartItem::updateImageAsync(QRectF _boundingRect, qreal _cur
p2.setY(y);
if (it->x() >= _minimum)
p.drawLine(p1, p2);
{
const auto dx = fabs(x - p1.x()), dy = fabs(y - p1.y());
if (dx > 1 || dy > 1)
p.drawLine(p1, p2);
else
continue;
}
if (it->x() >= _maximum)
break;
@ -783,7 +808,7 @@ void ArbitraryValuesChartItem::updateImageAsync(QRectF _boundingRect, qreal _cur
p.setPen(QColor::fromRgba(profiler::colors::modify_alpha32(0xc0000000, color)));
else
p.setPen(QColor::fromRgba(color));
p.setBrush(QColor::fromRgba(0xc0ffffff));
p.setBrush(QColor::fromRgba(0xc8ffffff));
qreal prevX = -offset * 2, prevY = -500;
for (auto it = first; it != points.end() && it->x() < _maximum; ++it)
@ -853,20 +878,7 @@ GraphicsChart::GraphicsChart(QWidget* _parent)
m_chartItem->setPos(0, 0);
m_chartItem->setBoundingRect(0, rect.top() + margin(), scene()->width(), rect.height() - margins() - 1);
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::autoAdjustChartChanged, [this]
{
if (m_chartItem->isVisible())
m_chartItem->onModeChanged();
});
if (!EASY_GLOBALS.scene.empty)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setRange(EASY_GLOBALS.scene.left, EASY_GLOBALS.scene.right);
setSliderWidth(EASY_GLOBALS.scene.window);
setValue(EASY_GLOBALS.scene.offset);
m_slider->show();
}
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::autoAdjustChartChanged, this, &This::onAutoAdjustChartChanged);
m_chartItem->updateImage();
}
@ -876,12 +888,23 @@ GraphicsChart::~GraphicsChart()
}
void GraphicsChart::onAutoAdjustChartChanged()
{
if (m_chartItem->isVisible())
m_chartItem->onModeChanged();
}
void GraphicsChart::clear()
{
m_chartItem->clear();
cancelImageUpdate();
Parent::clear();
}
void GraphicsChart::cancelImageUpdate()
{
m_chartItem->clear();
}
void GraphicsChart::update(Collections _collections)
{
m_chartItem->update(std::move(_collections));
@ -927,7 +950,7 @@ ArbitraryTreeWidgetItem::ArbitraryTreeWidgetItem(QTreeWidgetItem* _parent, profi
ArbitraryTreeWidgetItem::~ArbitraryTreeWidgetItem()
{
interrupt();
}
QVariant ArbitraryTreeWidgetItem::data(int _column, int _role) const
@ -954,6 +977,11 @@ const ArbitraryValuesCollection* ArbitraryTreeWidgetItem::collection() const
return m_collection.get();
}
ArbitraryValuesCollection* ArbitraryTreeWidgetItem::collection()
{
return m_collection.get();
}
void ArbitraryTreeWidgetItem::collectValues(profiler::thread_id_t _threadId)
{
if (!m_collection)
@ -1046,6 +1074,7 @@ void ArbitraryValuesWidget::clear()
{
if (m_collectionsTimer.isActive())
m_collectionsTimer.stop();
m_chart->cancelImageUpdate();
m_checkedItems.clear();
m_treeWidget->clear();
m_boldItem = nullptr;
@ -1153,6 +1182,7 @@ void ArbitraryValuesWidget::onCollectionsTimeout()
{
if (item->collection()->status() != ArbitraryValuesCollection::InProgress)
{
item->collection()->join();
collections.push_back(CollectionPaintData {item->collection(), item->color(),
ChartType::Line, item == m_treeWidget->currentItem()});
}

View File

@ -116,6 +116,7 @@ public:
void collectValues(profiler::thread_id_t _threadId, profiler::vin_t _valueId, const char* _valueName, profiler::timestamp_t _beginTime);
bool calculatePoints(profiler::timestamp_t _beginTime);
void interrupt();
void join();
private:
@ -211,9 +212,14 @@ public:
public:
void cancelImageUpdate();
void update(Collections _collections);
void update(const ArbitraryValuesCollection* _selected);
private slots:
void onAutoAdjustChartChanged();
}; // end of class GraphicsChart.
//////////////////////////////////////////////////////////////////////////
@ -241,6 +247,7 @@ public:
void setBold(bool _isBold);
const ArbitraryValuesCollection* collection() const;
ArbitraryValuesCollection* collection();
void collectValues(profiler::thread_id_t _threadId);
void interrupt();

View File

@ -1134,38 +1134,17 @@ EasyGraphicsScrollbar::EasyGraphicsScrollbar(int _initialHeight, QWidget* _paren
m_histogramItem->setBoundingRect(0, scene()->sceneRect().top() + margin(), scene()->width(), sceneHeight - margins() - 1);
m_histogramItem->hide();
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged, [this]()
{
if (m_histogramItem->isVisible())
{
m_histogramItem->updateImage();
scene()->update();
}
});
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::expectedFrameTimeChanged,
this, &This::onExpectedFrameTimeChanged);
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::autoAdjustHistogramChanged, [this]()
{
if (m_histogramItem->isVisible())
m_histogramItem->onModeChanged();
});
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::autoAdjustHistogramChanged,
this, &This::onAutoAdjustHistogramChanged);
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::displayOnlyFramesOnHistogramChanged, [this]()
{
if (m_histogramItem->isVisible())
m_histogramItem->rebuildSource(GraphicsHistogramItem::Hist_Id);
});
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::displayOnlyFramesOnHistogramChanged,
this, &This::onDisplayOnlyFramesOnHistogramChanged);
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::threadNameDecorationChanged, this, &This::onThreadViewChanged);
connect(&EASY_GLOBALS.events, &profiler_gui::EasyGlobalSignals::hexThreadIdChanged, this, &This::onThreadViewChanged);
if (!EASY_GLOBALS.scene.empty)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setRange(EASY_GLOBALS.scene.left, EASY_GLOBALS.scene.right);
setSliderWidth(EASY_GLOBALS.scene.window);
setValue(EASY_GLOBALS.scene.offset);
m_slider->show();
}
}
EasyGraphicsScrollbar::~EasyGraphicsScrollbar()
@ -1184,6 +1163,27 @@ void EasyGraphicsScrollbar::onThreadViewChanged()
}
}
void EasyGraphicsScrollbar::onExpectedFrameTimeChanged()
{
if (m_histogramItem->isVisible())
{
m_histogramItem->updateImage();
scene()->update();
}
}
void EasyGraphicsScrollbar::onAutoAdjustHistogramChanged()
{
if (m_histogramItem->isVisible())
m_histogramItem->onModeChanged();
}
void EasyGraphicsScrollbar::onDisplayOnlyFramesOnHistogramChanged()
{
if (m_histogramItem->isVisible())
m_histogramItem->rebuildSource(GraphicsHistogramItem::Hist_Id);
}
//////////////////////////////////////////////////////////////////////////
void EasyGraphicsScrollbar::clear()

View File

@ -176,6 +176,9 @@ public:
private slots:
void onThreadViewChanged();
void onExpectedFrameTimeChanged();
void onAutoAdjustHistogramChanged();
void onDisplayOnlyFramesOnHistogramChanged();
}; // END of class EasyGraphicsScrollbar.

View File

@ -60,7 +60,7 @@
EasyQTimer::EasyQTimer()
: QObject()
{
connect(&m_timer, &QTimer::timeout, [this] { m_handler(); });
connect(&m_timer, &QTimer::timeout, this, &EasyQTimer::onTimeout);
}
EasyQTimer::EasyQTimer(::std::function<void()>&& handler, bool signleShot)
@ -68,7 +68,7 @@ EasyQTimer::EasyQTimer(::std::function<void()>&& handler, bool signleShot)
, m_handler(::std::forward<::std::function<void()>&&>(handler))
{
m_timer.setSingleShot(signleShot);
connect(&m_timer, &QTimer::timeout, [this] { m_handler(); });
connect(&m_timer, &QTimer::timeout, this, &EasyQTimer::onTimeout);
}
EasyQTimer::~EasyQTimer()
@ -76,6 +76,11 @@ EasyQTimer::~EasyQTimer()
}
void EasyQTimer::onTimeout()
{
m_handler();
}
void EasyQTimer::setHandler(::std::function<void()>&& handler)
{
m_handler = handler;

View File

@ -87,6 +87,10 @@ public:
void stop();
bool isActive() const;
private slots:
void onTimeout();
}; // END of class EasyQTimer.
//////////////////////////////////////////////////////////////////////////

View File

@ -179,6 +179,7 @@ GraphicsSliderArea::GraphicsSliderArea(QWidget* _parent)
, m_bLocked(false)
, m_bUpdatingPos(false)
, m_bEmitChange(true)
, m_bValidated(false)
{
setCacheMode(QGraphicsView::CacheNone);
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
@ -220,23 +221,8 @@ GraphicsSliderArea::GraphicsSliderArea(QWidget* _parent)
connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneCleared, this, &This::clear);
connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneVisibleRegionSizeChanged, this, &This::setSliderWidth);
connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneVisibleRegionPosChanged, this, &This::setValue);
connect(globalEvents, &profiler_gui::EasyGlobalSignals::chartSliderChanged, [this] (qreal pos)
{
if (!m_bUpdatingPos)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setValue(pos);
}
});
connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneSizeChanged, [this] (qreal left, qreal right)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setRange(left, right);
m_slider->show();
});
connect(globalEvents, &profiler_gui::EasyGlobalSignals::chartSliderChanged, this, &This::onExternalChartSliderChanged);
connect(globalEvents, &profiler_gui::EasyGlobalSignals::sceneSizeChanged, this, &This::onSceneSizeChanged);
connect(globalEvents, &profiler_gui::EasyGlobalSignals::lockCharts, this, &This::lock);
connect(globalEvents, &profiler_gui::EasyGlobalSignals::unlockCharts, this, &This::unlock);
}
@ -246,6 +232,45 @@ GraphicsSliderArea::~GraphicsSliderArea()
}
void GraphicsSliderArea::showEvent(QShowEvent* _event)
{
Parent::showEvent(_event);
if (!m_bValidated)
{
m_bValidated = true;
validateScene();
}
}
void GraphicsSliderArea::validateScene()
{
if (!EASY_GLOBALS.scene.empty)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setRange(EASY_GLOBALS.scene.left, EASY_GLOBALS.scene.right);
setSliderWidth(EASY_GLOBALS.scene.window);
setValue(EASY_GLOBALS.scene.offset);
m_slider->show();
scene()->update();
}
}
void GraphicsSliderArea::onExternalChartSliderChanged(qreal _pos)
{
if (!m_bUpdatingPos)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setValue(_pos);
}
}
void GraphicsSliderArea::onSceneSizeChanged(qreal _left, qreal _right)
{
const profiler_gui::BoolFlagGuard guard(m_bEmitChange, false);
setRange(_left, _right);
m_slider->show();
}
//////////////////////////////////////////////////////////////////////////
void GraphicsSliderArea::clear()

View File

@ -108,6 +108,7 @@ protected:
bool m_bLocked;
bool m_bUpdatingPos;
bool m_bEmitChange;
bool m_bValidated;
public:
@ -116,6 +117,7 @@ public:
// Public virtual methods
void showEvent(QShowEvent* _event) override;
void mousePressEvent(QMouseEvent* _event) override;
void mouseReleaseEvent(QMouseEvent* _event) override;
void mouseMoveEvent(QMouseEvent* _event) override;
@ -150,6 +152,10 @@ public:
void showSelectionIndicator();
void hideSelectionIndicator();
protected:
void validateScene();
public slots:
void lock() { m_bLocked = true; }
@ -157,6 +163,8 @@ public slots:
protected slots:
void onExternalChartSliderChanged(qreal _pos);
void onSceneSizeChanged(qreal _left, qreal _right);
void onWindowWidthChange(qreal _width);
}; // END of class GraphicsSliderArea.