Skip to content

Commit

Permalink
Added tree map view highlights. Bug fixes. Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
milostosic committed Jul 26, 2023
1 parent 34fbb5b commit 3c0db68
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 25 deletions.
4 changes: 2 additions & 2 deletions install/UpdateBuildVersion.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off
copy "%~dp0..\src\buildversion.h" "%~dp0..\src\version.h"
"../../../../../Tools/Fart/fart.exe" "%~dp0..\src\version.h" ##BUILD_VERSION## 4.5.9
"../../../../../Tools/Fart/fart.exe" "%~dp0..\src\version.h" ##BUILD_VERSION## 4.6
copy MTunerPreVersion.swx MTuner.swx
"../../../../../Tools/Fart/fart.exe" MTuner.swx ##BUILD_VERSION## 4.5.9
"../../../../../Tools/Fart/fart.exe" MTuner.swx ##BUILD_VERSION## 4.6
"../../../../../Tools/Fart/fart.exe" MTuner.swx 1.0.0 1.0.0
2 changes: 2 additions & 0 deletions src/binloaderview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ BinLoaderView::BinLoaderView(QWidget* _parent, Qt::WindowFlags _flags) :
connect(m_operationList, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SIGNAL(setStackTrace(rtm::StackTrace**,int)));
connect(m_operationListInvalid, SIGNAL(setStackTrace(rtm::StackTrace**, int)), this, SIGNAL(setStackTrace(rtm::StackTrace**, int)));
connect(m_treeMap, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SIGNAL(setStackTrace(rtm::StackTrace**,int)));
connect(m_treeMap, SIGNAL(highlightTime(uint64_t)), this, SIGNAL(highlightTime(uint64_t)));
connect(m_treeMap, SIGNAL(highlightRange(uint64_t, uint64_t)), this, SIGNAL(highlightRange(uint64_t, uint64_t)));
connect(m_hotspots, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SIGNAL(setStackTrace(rtm::StackTrace**,int)));
connect(m_stackTree, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SIGNAL(setStackTrace(rtm::StackTrace**,int)));
connect(this, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SLOT(saveStackTrace(rtm::StackTrace**,int)));
Expand Down
28 changes: 20 additions & 8 deletions src/loader/capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,10 @@ void Capture::addModule(const char* _path, uint64_t inModBase, uint64_t inModSiz
rdebug::ModuleInfo& info = m_moduleInfos[i];
if (rtm::strCmp(rtm::pathGetFileName(info.m_modulePath), rtm::pathGetFileName(_path)) == 0)
{
if (inModBase == info.m_baseAddress)
return;
// update base address if new one encountered
info.m_baseAddress = inModBase;
info.m_size = inModSize;
return;
}
}

Expand Down Expand Up @@ -2114,7 +2116,7 @@ void Capture::addToMemoryGroups(MemoryGroupsHashType& _groups, MemoryOperation*
};
}

static void addToTree(StackTraceTree* _root, StackTrace* _trace, int64_t _size, int32_t _overhead, StackTrace::Scope _offset, StackTraceTree::Enum _opType)
static void addToTree(StackTraceTree* _root, StackTrace* _trace, int64_t _size, int32_t _overhead, StackTrace::Scope _offset, StackTraceTree::Enum _opType, uint64_t _operationTime)
{
const int32_t numFrames = (int32_t)_trace->m_numFrames;
int32_t currFrame = numFrames;
Expand All @@ -2129,6 +2131,11 @@ static void addToTree(StackTraceTree* _root, StackTrace* _trace, int64_t _size,
if (_opType != StackTraceTree::Count)
++currNode->m_opCount[_opType];

if (currNode->m_minTime == 0)
currNode->m_minTime = _operationTime;

currNode->m_maxTime = _operationTime;

// add stack trace to root node
StackTrace::getNextArray(_trace);
StackTrace** ar = StackTrace::getNextArray(_trace);
Expand Down Expand Up @@ -2193,6 +2200,11 @@ static void addToTree(StackTraceTree* _root, StackTrace* _trace, int64_t _size,

if (_opType != StackTraceTree::Count)
++currNode->m_opCount[_opType];

if (currNode->m_minTime == 0)
currNode->m_minTime = _operationTime;

currNode->m_maxTime = _operationTime;
}
}

Expand All @@ -2204,7 +2216,7 @@ void Capture::addToStackTraceTree(StackTraceTree& _tree, MemoryOperation* _op, S
case rmem::LogMarkers::OpCalloc:
case rmem::LogMarkers::OpAllocAligned:
{
addToTree(&_tree, _op->m_stackTrace, _op->m_allocSize, _op->m_overhead, _offset, StackTraceTree::Alloc);
addToTree(&_tree, _op->m_stackTrace, _op->m_allocSize, _op->m_overhead, _offset, StackTraceTree::Alloc, _op->m_operationTime);
}
break;

Expand All @@ -2214,10 +2226,10 @@ void Capture::addToStackTraceTree(StackTraceTree& _tree, MemoryOperation* _op, S
RTM_ASSERT(prevOp != NULL, "");

if (isInFilter(prevOp))
addToTree(&_tree, prevOp->m_stackTrace, -(int64_t)prevOp->m_allocSize, -(int32_t)prevOp->m_overhead, _offset, StackTraceTree::Free);
addToTree(&_tree, prevOp->m_stackTrace, -(int64_t)prevOp->m_allocSize, -(int32_t)prevOp->m_overhead, _offset, StackTraceTree::Free, _op->m_operationTime);
else
// prev op not in filter, do not reduce used memory to avoid going (possibly) negative
addToTree(&_tree, prevOp->m_stackTrace, 0, 0, _offset, StackTraceTree::Free);
addToTree(&_tree, prevOp->m_stackTrace, 0, 0, _offset, StackTraceTree::Free, _op->m_operationTime);
}
break;

Expand All @@ -2228,9 +2240,9 @@ void Capture::addToStackTraceTree(StackTraceTree& _tree, MemoryOperation* _op, S
if (prevOp)
{
if (isInFilter(prevOp))
addToTree(&_tree, prevOp->m_stackTrace, -(int64_t)prevOp->m_allocSize, -(int32_t)prevOp->m_overhead, _offset, StackTraceTree::Count);
addToTree(&_tree, prevOp->m_stackTrace, -(int64_t)prevOp->m_allocSize, -(int32_t)prevOp->m_overhead, _offset, StackTraceTree::Count, _op->m_operationTime);
}
addToTree(&_tree, _op->m_stackTrace, _op->m_allocSize, _op->m_overhead, _offset, StackTraceTree::Realloc);
addToTree(&_tree, _op->m_stackTrace, _op->m_allocSize, _op->m_overhead, _offset, StackTraceTree::Realloc, _op->m_operationTime);
}
break;
};
Expand Down
4 changes: 4 additions & 0 deletions src/loader/mtunerlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ struct StackTraceTree
uint64_t m_addressID;
int64_t m_memUsage;
int64_t m_memUsagePeak;
uint64_t m_minTime;
uint64_t m_maxTime;
int32_t m_overhead;
int32_t m_overheadPeak;
int32_t m_depth;
Expand All @@ -237,6 +239,8 @@ struct StackTraceTree
m_addressID(0),
m_memUsage(0),
m_memUsagePeak(0),
m_minTime(0),
m_maxTime(0),
m_overhead(0),
m_overheadPeak(0),
m_depth(0),
Expand Down
5 changes: 4 additions & 1 deletion src/treemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ TreeMapWidget::TreeMapWidget(QWidget* _parent, Qt::WindowFlags _flags) :

m_graphicsView->setScene(m_scene);
m_graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
connect(m_graphicsView, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SIGNAL(setStackTrace(rtm::StackTrace**,int)));
connect(m_graphicsView, SIGNAL(setStackTrace(rtm::StackTrace**,int)), this, SIGNAL(setStackTrace(rtm::StackTrace**,int))) ;

connect(m_graphicsView, SIGNAL(highlightTime(uint64_t)), this, SIGNAL(highlightTime(uint64_t)));
connect(m_graphicsView, SIGNAL(highlightRange(uint64_t, uint64_t)), this, SIGNAL(highlightRange(uint64_t, uint64_t)));
}

void TreeMapWidget::changeEvent(QEvent* _event)
Expand Down
2 changes: 2 additions & 0 deletions src/treemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public Q_SLOTS:

Q_SIGNALS:
void setStackTrace(rtm::StackTrace**, int);
void highlightTime(uint64_t);
void highlightRange(uint64_t, uint64_t);

private:
Ui::TreeMap ui;
Expand Down
38 changes: 31 additions & 7 deletions src/treemapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ TreeMapView::TreeMapView(QWidget* _parent) :
{
m_context = NULL;
m_highlightNode = NULL;
m_clickedNode = NULL;
m_mapType = 0;
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Expand Down Expand Up @@ -214,10 +215,10 @@ void TreeMapView::updateHighlight(const QPoint& _pos)
QLocale locale;
QString str = "<pre>" +
QStringColor(tr("Total size"), "ff42a6ba") + QStringColor(locale.toString(qulonglong(m_highlightNode->m_size)), "ffffff33", false) + "<br>" +
QStringColor(tr("Operations"), "ff83cf67") + locale.toString(qulonglong(m_highlightNode->m_allocs + m_highlightNode->m_reallocs + m_highlightNode->m_frees)) + "<br><br>" +
QStringColor(tr(" Allocs"), "ffffffff") + locale.toString(qulonglong(m_highlightNode->m_allocs)) + "<br>" +
QStringColor(tr("Reallocs"), "ffffffff") + locale.toString(qulonglong(m_highlightNode->m_reallocs)) + "<br>" +
QStringColor(tr(" Frees"), "ffffffff") + locale.toString(qulonglong(m_highlightNode->m_frees)) + "</pre>";
QStringColor(tr("Operations"), "ff83cf67") + locale.toString(qulonglong(m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Alloc] + m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Realloc] + m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Free])) + "<br><br>" +
QStringColor(tr(" Allocs"), "ffffffff") + locale.toString(qulonglong(m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Alloc])) + "<br>" +
QStringColor(tr("Reallocs"), "ffffffff") + locale.toString(qulonglong(m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Realloc])) + "<br>" +
QStringColor(tr(" Frees"), "ffffffff") + locale.toString(qulonglong(m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Free])) + "</pre>";
m_toolTipLabel->setText(str);
m_item->redraw();
invalidateScene();
Expand All @@ -233,9 +234,6 @@ void TreeMapView::buildTreeRecurse(rtm::StackTraceTree* _tree)

node.m_tree = _tree;
node.m_size = getNodeValueByType( node, m_mapType );
node.m_allocs = node.m_tree->m_opCount[rtm::StackTraceTree::Alloc];
node.m_reallocs = node.m_tree->m_opCount[rtm::StackTraceTree::Realloc];
node.m_frees = node.m_tree->m_opCount[rtm::StackTraceTree::Free];

m_tree.push_back(node);
m_treeLines.append(QLineF());
Expand Down Expand Up @@ -311,9 +309,26 @@ void TreeMapView::mouseReleaseEvent(QMouseEvent* _event)
{
rtm::StackTrace** trace = &m_highlightNode->m_tree->m_stackTraceList;
emit setStackTrace(trace, 1);

if (m_clickedNode != m_highlightNode)
{
m_clickedNode = m_highlightNode;
repaint();
}

const uint32_t numOps = m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Alloc] +
m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Free] +
m_highlightNode->m_tree->m_opCount[rtm::StackTraceTree::Realloc];
if (numOps == 1)
emit highlightTime(m_highlightNode->m_tree->m_minTime);
else
emit highlightRange(m_highlightNode->m_tree->m_minTime, m_highlightNode->m_tree->m_maxTime);
}
else
{
emit setStackTrace(NULL, 0);
m_clickedNode = NULL;
}
}

QGraphicsView::mouseReleaseEvent(_event);
Expand Down Expand Up @@ -386,15 +401,24 @@ void TreeMapGraphicsItem::paint(QPainter* _painter, const QStyleOptionGraphicsIt
}

TreeMapNode* highlight = m_treeView->getHighlightNode();
TreeMapNode* clicked = m_treeView->getClickedNode();

_painter->setPen(QPen(Qt::black, 1.0, Qt::SolidLine));

QColor c1(33, 80, 70, 255);
QColor c2(33, 80, 90, 255);
QColor c3(33, 70, 80, 255);

_painter->setBrush(c2);
_painter->drawLines(lines.data(), lines.size());

if (clicked && (clicked != highlight))
{
QRectF highlightRect = clicked->m_rect;
_painter->setBrush(c3);
_painter->drawRect(highlightRect);
}

if (highlight)
{
QRectF highlightRect = highlight->m_rect;
Expand Down
10 changes: 4 additions & 6 deletions src/treemapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ struct TreeMapNode
{
rtm::StackTraceTree* m_tree; ///< Pointer to the actual stact trace tree node, used to resolve symbols
uint64_t m_size; ///< Size of the node, based on the view type (usage, peak, etc.)
uint32_t m_allocs; ///< Number of allocations
uint32_t m_reallocs; ///< Number of reallocations
uint32_t m_frees; ///< Number of frees
QRectF m_rect;

TreeMapNode()
: m_size(0)
, m_allocs(0)
, m_reallocs(0)
, m_frees(0)
{}
};

Expand All @@ -36,6 +30,7 @@ class TreeMapView : public QGraphicsView
rtm_vector<TreeMapNode> m_tree;
QList<QLineF> m_treeLines;
TreeMapNode* m_highlightNode;
TreeMapNode* m_clickedNode;
uint32_t m_mapType;
TreeMapGraphicsItem* m_item;
QLabel* m_toolTipLabel;
Expand All @@ -49,6 +44,7 @@ class TreeMapView : public QGraphicsView
uint32_t getMapType() const { return m_mapType; }
void updateHighlight(const QPoint& _pos);
inline TreeMapNode* getHighlightNode() { return m_highlightNode; }
inline TreeMapNode* getClickedNode() { return m_clickedNode; }
rtm_vector<TreeMapNode>& getTree() { return m_tree; }
QVector<QLineF>& getTreeLines() { return m_treeLines; }
/// QWidget
Expand All @@ -61,6 +57,8 @@ class TreeMapView : public QGraphicsView

Q_SIGNALS:
void setStackTrace(rtm::StackTrace**, int);
void highlightTime(uint64_t);
void highlightRange(uint64_t, uint64_t);

private:
void buildTreeRecurse(rtm::StackTraceTree* _tree);
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#ifndef RTM_MTUNER_VERSION_H
#define RTM_MTUNER_VERSION_H

static const char* MTunerVersion = "4.5.9";
static const char* MTunerVersion = "4.6";

#endif // RTM_MTUNER_VERSION_H

0 comments on commit 3c0db68

Please sign in to comment.