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

(GUI) Fixed division by zero;

* (GUI) Displaying blocks number on hystogram for selected thread
This commit is contained in:
Victor Zarubkin 2016-12-12 22:28:54 +03:00
parent d88b747c33
commit b67e078e55
4 changed files with 20 additions and 8 deletions

View File

@ -426,7 +426,7 @@ template <class T> inline bool is_max(const T& _value) {
inline double percentReal(::profiler::timestamp_t _partial, ::profiler::timestamp_t _total) inline double percentReal(::profiler::timestamp_t _partial, ::profiler::timestamp_t _total)
{ {
return 100. * static_cast<double>(_partial) / static_cast<double>(_total); return _total ? 100. * static_cast<double>(_partial) / static_cast<double>(_total) : 0.;
} }
inline int percent(::profiler::timestamp_t _partial, ::profiler::timestamp_t _total) inline int percent(::profiler::timestamp_t _partial, ::profiler::timestamp_t _total)

View File

@ -234,6 +234,7 @@ EasyHystogramItem::EasyHystogramItem() : Parent(nullptr)
, m_maxDuration(0) , m_maxDuration(0)
, m_minDuration(0) , m_minDuration(0)
, m_timer(::std::bind(&This::onTimeout, this)) , m_timer(::std::bind(&This::onTimeout, this))
, m_pProfilerThread(nullptr)
, m_threadId(0) , m_threadId(0)
, m_blockId(::profiler_gui::numeric_max<decltype(m_blockId)>()) , m_blockId(::profiler_gui::numeric_max<decltype(m_blockId)>())
, m_timeouts(0) , m_timeouts(0)
@ -450,10 +451,12 @@ void EasyHystogramItem::paintByPtr(QPainter* _painter)
_painter->setPen(Qt::black); _painter->setPen(Qt::black);
rect.setRect(0, bottom + 2, width, widget->defaultFontHeight()); rect.setRect(0, bottom + 2, width, widget->defaultFontHeight());
_painter->drawText(rect, Qt::AlignHCenter | Qt::TextDontClip, QString("%1 | duration: %2 | active time: %3 (%4%)").arg(m_threadName) _painter->drawText(rect, Qt::AlignHCenter | Qt::TextDontClip, QString("%1 | duration: %2 | active time: %3 (%4%) | %5 blocks (%6 events)").arg(m_threadName)
.arg(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, m_threadDuration)) .arg(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, m_threadDuration))
.arg(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, m_threadActiveTime)) .arg(::profiler_gui::timeStringRealNs(EASY_GLOBALS.time_units, m_threadActiveTime))
.arg(QString::number(100. * (double)m_threadActiveTime / (double)m_threadDuration, 'f', 2))); .arg(m_threadDuration ? QString::number(100. * (double)m_threadActiveTime / (double)m_threadDuration, 'f', 2) : QString("0"))
.arg(m_pProfilerThread->blocks_number)
.arg(m_pProfilerThread->events.size()));
_painter->drawText(rect, Qt::AlignLeft, bindMode ? " MODE: zoom" : " MODE: overview"); _painter->drawText(rect, Qt::AlignLeft, bindMode ? " MODE: zoom" : " MODE: overview");
@ -669,7 +672,7 @@ void EasyHystogramItem::paintById(QPainter* _painter)
{ {
_painter->drawText(rect, Qt::AlignHCenter | Qt::TextDontClip, QString("%1 | %2 | %3 calls | %4% of thread active time").arg(m_threadName).arg(name) _painter->drawText(rect, Qt::AlignHCenter | Qt::TextDontClip, QString("%1 | %2 | %3 calls | %4% of thread active time").arg(m_threadName).arg(name)
.arg(item->tree.per_thread_stats->calls_number) .arg(item->tree.per_thread_stats->calls_number)
.arg(QString::number(100. * (double)item->tree.per_thread_stats->total_duration / (double)m_threadActiveTime, 'f', 2))); .arg(m_threadActiveTime ? QString::number(100. * (double)item->tree.per_thread_stats->total_duration / (double)m_threadActiveTime, 'f', 2) : QString("100")));
} }
else else
{ {
@ -750,6 +753,7 @@ void EasyHystogramItem::setSource(::profiler::thread_id_t _thread_id, const ::pr
if (m_pSource == nullptr) if (m_pSource == nullptr)
{ {
m_pProfilerThread = nullptr;
m_maxDurationStr.clear(); m_maxDurationStr.clear();
m_minDurationStr.clear(); m_minDurationStr.clear();
m_threadName.clear(); m_threadName.clear();
@ -769,6 +773,8 @@ void EasyHystogramItem::setSource(::profiler::thread_id_t _thread_id, const ::pr
m_threadDuration = easyBlock(root.children.back()).tree.node->end() - easyBlock(root.children.front()).tree.node->begin(); m_threadDuration = easyBlock(root.children.back()).tree.node->end() - easyBlock(root.children.front()).tree.node->begin();
m_threadActiveTime = root.active_time; m_threadActiveTime = root.active_time;
m_pProfilerThread = &root;
m_timeUnits = EASY_GLOBALS.time_units; m_timeUnits = EASY_GLOBALS.time_units;
m_maxDurationStr = ::profiler_gui::timeStringReal(m_timeUnits, m_maxDuration, 3); m_maxDurationStr = ::profiler_gui::timeStringReal(m_timeUnits, m_maxDuration, 3);
m_minDurationStr = ::profiler_gui::timeStringReal(m_timeUnits, m_minDuration, 3); m_minDurationStr = ::profiler_gui::timeStringReal(m_timeUnits, m_minDuration, 3);
@ -818,6 +824,8 @@ void EasyHystogramItem::setSource(::profiler::thread_id_t _thread_id, ::profiler
m_threadDuration = easyBlock(root.children.back()).tree.node->end() - easyBlock(root.children.front()).tree.node->begin(); m_threadDuration = easyBlock(root.children.back()).tree.node->end() - easyBlock(root.children.front()).tree.node->begin();
m_threadActiveTime = root.active_time; m_threadActiveTime = root.active_time;
m_pProfilerThread = &root;
show(); show();
m_timeUnits = EASY_GLOBALS.time_units; m_timeUnits = EASY_GLOBALS.time_units;
m_bReady.store(false, ::std::memory_order_release); m_bReady.store(false, ::std::memory_order_release);
@ -902,6 +910,7 @@ void EasyHystogramItem::setSource(::profiler::thread_id_t _thread_id, ::profiler
} }
else else
{ {
m_pProfilerThread = nullptr;
m_threadName.clear(); m_threadName.clear();
hide(); hide();
} }

View File

@ -147,6 +147,7 @@ class EasyHystogramItem : public QGraphicsItem
::profiler::timestamp_t m_threadActiveTime; ::profiler::timestamp_t m_threadActiveTime;
const ::profiler_gui::EasyItems* m_pSource; const ::profiler_gui::EasyItems* m_pSource;
QImage* m_temporaryImage; QImage* m_temporaryImage;
const ::profiler::BlocksTreeRoot* m_pProfilerThread;
::profiler::thread_id_t m_threadId; ::profiler::thread_id_t m_threadId;
::profiler::block_index_t m_blockId; ::profiler::block_index_t m_blockId;
int m_timeouts; int m_timeouts;

View File

@ -518,8 +518,9 @@ size_t FillTreeClass<T>::setTreeInternal(T& _safelocker, Items& _items, const ::
const auto& per_parent_stats = child.per_parent_stats; const auto& per_parent_stats = child.per_parent_stats;
const auto& per_frame_stats = child.per_frame_stats; const auto& per_frame_stats = child.per_frame_stats;
auto percentage = duration == 0 ? 0 : ::profiler_gui::percent(duration, _parent->duration()); auto parent_duration = _parent->duration();
auto percentage_sum = ::profiler_gui::percent(per_parent_stats->total_duration, _parent->duration()); auto percentage = duration == 0 ? 0 : ::profiler_gui::percent(duration, parent_duration);
auto percentage_sum = ::profiler_gui::percent(per_parent_stats->total_duration, parent_duration);
item->setData(COL_PERCENT_PER_PARENT, Qt::UserRole, percentage); item->setData(COL_PERCENT_PER_PARENT, Qt::UserRole, percentage);
item->setText(COL_PERCENT_PER_PARENT, QString::number(percentage)); item->setText(COL_PERCENT_PER_PARENT, QString::number(percentage));
item->setData(COL_PERCENT_SUM_PER_PARENT, Qt::UserRole, percentage_sum); item->setData(COL_PERCENT_SUM_PER_PARENT, Qt::UserRole, percentage_sum);
@ -529,8 +530,9 @@ size_t FillTreeClass<T>::setTreeInternal(T& _safelocker, Items& _items, const ::
{ {
if (_parent != _frame) if (_parent != _frame)
{ {
percentage = duration == 0 ? 0 : ::profiler_gui::percent(duration, _frame->duration()); parent_duration = _frame->duration();
percentage_sum = ::profiler_gui::percent(per_frame_stats->total_duration, _frame->duration()); percentage = duration == 0 ? 0 : ::profiler_gui::percent(duration, parent_duration);
percentage_sum = ::profiler_gui::percent(per_frame_stats->total_duration, parent_duration);
} }
item->setData(COL_PERCENT_PER_FRAME, Qt::UserRole, percentage); item->setData(COL_PERCENT_PER_FRAME, Qt::UserRole, percentage);