QmlProfiler: display binding loops

Change-Id: Ib553f67b25e614bd210959ce82bc970daa228fdb
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
Christiaan Janssen
2012-02-06 16:08:56 +01:00
parent 1d1d2f0b74
commit bd438d1c5c
8 changed files with 192 additions and 9 deletions

View File

@@ -269,6 +269,7 @@ Rectangle {
rangeDetails.file = "";
rangeDetails.line = -1;
rangeDetails.column = 0;
rangeDetails.isBindingLoop = false;
}
function selectNextWithId( eventId )
@@ -424,6 +425,7 @@ Rectangle {
rangeDetails.line = qmlEventList.getLine(selectedItem);
rangeDetails.column = qmlEventList.getColumn(selectedItem);
rangeDetails.type = root.names[qmlEventList.getType(selectedItem)];
rangeDetails.isBindingLoop = qmlEventList.getBindingLoopDest(selectedItem)!==-1;
rangeDetails.visible = true;

View File

@@ -95,6 +95,21 @@ function drawData(canvas, ctxt, region)
highest[ty] = xx+eventWidth;
}
}
// binding loops
ctxt.strokeStyle = "orange";
ctxt.lineWidth = 2;
var radius = 1;
for (var ii = 0; ii < qmlEventList.count(); ++ii) {
if (qmlEventList.getBindingLoopDest(ii) >= 0) {
var xcenter = Math.round(qmlEventList.getStartTime(ii) +
qmlEventList.getDuration(ii) -
qmlEventList.traceStartTime()) * spacing;
var ycenter = Math.round(bump + qmlEventList.getType(ii) * blockHeight + blockHeight/2);
ctxt.arc(xcenter, ycenter, radius, 0, 2*Math.PI, true);
ctxt.stroke();
}
}
}
function drawTimeBar(canvas, ctxt, region)

View File

@@ -42,6 +42,7 @@ Item {
property string file
property int line
property int column
property bool isBindingLoop
property bool locked: view.selectionLocked
@@ -153,6 +154,11 @@ Item {
return (file.length !== 0) ? (file + ":" + rangeDetails.line) : "";
}
}
Detail {
visible: isBindingLoop
opacity: content.length != 0 ? 1 : 0
label: qsTr("Binding loop detected")
}
}
}

View File

@@ -54,6 +54,16 @@ using namespace QmlJsDebugClient;
namespace QmlProfiler {
namespace Internal {
struct Colors {
Colors () {
this->bindingLoopBackground = QColor("orange").lighter();
}
QColor bindingLoopBackground;
};
Q_GLOBAL_STATIC(Colors, colors)
////////////////////////////////////////////////////////////////////////////////////
class EventsViewItem : public QStandardItem
@@ -531,6 +541,11 @@ void QmlProfilerEventsMainView::QmlProfilerEventsMainViewPrivate::buildModelFrom
newRow.at(0)->setData(QVariant(binding->location.line),LineRole);
newRow.at(0)->setData(QVariant(binding->location.column),ColumnRole);
newRow.at(0)->setData(QVariant(binding->eventId),EventIdRole);
if (binding->isBindingLoop)
foreach (QStandardItem *item, newRow) {
item->setBackground(colors()->bindingLoopBackground);
item->setToolTip(tr("Binding loop detected"));
}
// append
parentItem->appendRow(newRow);
@@ -877,6 +892,11 @@ void QmlProfilerEventsParentsAndChildrenView::rebuildTree(void *eventList)
newRow.at(0)->setData(QVariant(event->reference->eventId), EventIdRole);
newRow.at(2)->setData(QVariant(event->duration));
newRow.at(3)->setData(QVariant(event->calls));
if (event->inLoopPath)
foreach (QStandardItem *item, newRow) {
item->setBackground(colors()->bindingLoopBackground);
item->setToolTip(tr("Part of binding loop"));
}
} else {
QV8EventSub *event = v8List->at(index);
newRow << new EventsViewItem(event->reference->displayName);

View File

@@ -107,9 +107,10 @@ void TimelineView::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget
int firstIndex = m_eventList->findFirstIndex(m_startTime);
int lastIndex = m_eventList->findLastIndex(m_endTime);
drawItemsToPainter(p, firstIndex, lastIndex);
drawSelectionBoxes(p);
drawItemsToPainter(p, firstIndex, lastIndex);
drawSelectionBoxes(p, firstIndex, lastIndex);
drawBindingLoopMarkers(p, firstIndex, lastIndex);
m_lastStartTime = m_startTime;
m_lastEndTime = m_endTime;
@@ -166,13 +167,11 @@ void TimelineView::drawItemsToPainter(QPainter *p, int fromIndex, int toIndex)
}
}
void TimelineView::drawSelectionBoxes(QPainter *p)
void TimelineView::drawSelectionBoxes(QPainter *p, int fromIndex, int toIndex)
{
if (m_selectedItem == -1)
return;
int fromIndex = m_eventList->findFirstIndex(m_startTime);
int toIndex = m_eventList->findLastIndex(m_endTime);
int id = m_eventList->getEventId(m_selectedItem);
p->setBrush(Qt::transparent);
@@ -216,6 +215,74 @@ void TimelineView::drawSelectionBoxes(QPainter *p)
}
}
void TimelineView::drawBindingLoopMarkers(QPainter *p, int fromIndex, int toIndex)
{
int destindex;
int xfrom, xto, eventType;
int yfrom, yto;
int radius = DefaultRowHeight / 3;
QPen shadowPen = QPen(QColor("grey"),2);
QPen markerPen = QPen(QColor("orange"),2);
QBrush shadowBrush = QBrush(QColor("grey"));
QBrush markerBrush = QBrush(QColor("orange"));
p->save();
for (int i = fromIndex; i <= toIndex; i++) {
destindex = m_eventList->getBindingLoopDest(i);
if (destindex >= 0) {
// from
xfrom = (m_eventList->getStartTime(i) + m_eventList->getDuration(i)/2 -
m_startTime) * m_spacing;
eventType = m_eventList->getType(i);
if (m_rowsExpanded[eventType])
yfrom = m_rowStarts[eventType] + DefaultRowHeight*
(m_eventList->eventPosInType(i) + 1);
else
yfrom = m_rowStarts[eventType] + DefaultRowHeight*m_eventList->getNestingLevel(i);
yfrom += DefaultRowHeight / 2;
// to
xto = (m_eventList->getStartTime(destindex) + m_eventList->getDuration(destindex)/2 -
m_startTime) * m_spacing;
eventType = m_eventList->getType(destindex);
if (m_rowsExpanded[eventType])
yto = m_rowStarts[eventType] + DefaultRowHeight*
(m_eventList->eventPosInType(destindex) + 1);
else
yto = m_rowStarts[eventType] + DefaultRowHeight *
m_eventList->getNestingLevel(destindex);
yto += DefaultRowHeight / 2;
// radius
int eventWidth = m_eventList->getDuration(i) * m_spacing;
radius = 5;
if (radius * 2 > eventWidth)
radius = eventWidth / 2;
if (radius < 2)
radius = 2;
// shadow
int shadowoffset = 2;
p->setPen(shadowPen);
p->setBrush(shadowBrush);
p->drawEllipse(QPoint(xfrom, yfrom + shadowoffset), radius, radius);
p->drawEllipse(QPoint(xto, yto + shadowoffset), radius, radius);
p->drawLine(QPoint(xfrom, yfrom + shadowoffset), QPoint(xto, yto + shadowoffset));
// marker
p->setPen(markerPen);
p->setBrush(markerBrush);
p->drawEllipse(QPoint(xfrom, yfrom), radius, radius);
p->drawEllipse(QPoint(xto, yto), radius, radius);
p->drawLine(QPoint(xfrom, yfrom), QPoint(xto, yto));
}
}
p->restore();
}
void TimelineView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// special case: if there is a drag area below me, don't accept the

View File

@@ -182,7 +182,8 @@ protected:
private:
QColor colorForItem(int itemIndex);
void drawItemsToPainter(QPainter *p, int fromIndex, int toIndex);
void drawSelectionBoxes(QPainter *p);
void drawSelectionBoxes(QPainter *p, int fromIndex, int toIndex);
void drawBindingLoopMarkers(QPainter *p, int fromIndex, int toIndex);
void manageClicked();
void manageHovered(int x, int y);