Commit 7b79dc33 authored by Mike McQuaid's avatar Mike McQuaid Committed by hjk
Browse files

Add callgrind plugin.



Merge-request: 284
Reviewed-by: default avatarhjk <qtc-committer@nokia.com>
parent e16f83a8
<plugin name=\"Callgrind\" version=\"$$QTCREATOR_VERSION\" compatVersion=\"$$QTCREATOR_VERSION\">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2011 Nokia Corporation</copyright>
<license>
Commercial Usage
Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
GNU Lesser General Public License Usage
Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. Please review the following information to ensure the GNU Lesser General Public License version 2.1 requirements will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
</license>
<category>Code Analyzer</category>
<description>Valgrind Callgrind Tool Plugin</description>
<url>http://qt.nokia.com</url>
<dependencyList>
<dependency name=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"TextEditor\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"AnalyzerBase\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"ValgrindToolBase\" version=\"$$QTCREATOR_VERSION\"/>
</dependencyList>
</plugin>
include(callgrind_dependencies.pri)
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
LIBS *= -l$$qtLibraryName(Callgrind)
TEMPLATE = lib
TARGET = Callgrind
DEFINES += CALLGRIND_LIBRARY
include(../../qtcreatorplugin.pri)
include(callgrind_dependencies.pri)
# Callgrind files
HEADERS += \
callgrindplugin.h \
callgrind_global.h \
callgrindconfigwidget.h \
callgrindcostdelegate.h \
callgrindcostview.h \
callgrindhelper.h \
callgrindnamedelegate.h \
callgrindsettings.h \
callgrindtool.h \
callgrindvisualisation.h \
callgrindwidgethandler.h \
callgrindengine.h \
workarounds.h \
callgrindtextmark.h
SOURCES += \
callgrindplugin.cpp \
callgrindconfigwidget.cpp \
callgrindcostdelegate.cpp \
callgrindcostview.cpp \
callgrindhelper.cpp \
callgrindnamedelegate.cpp \
callgrindsettings.cpp \
callgrindtool.cpp \
callgrindvisualisation.cpp \
callgrindwidgethandler.cpp \
callgrindengine.cpp \
workarounds.cpp \
callgrindtextmark.cpp
FORMS += \
callgrindconfigwidget.ui
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/analyzerbase/analyzerbase.pri)
include(../../plugins/valgrindtoolbase/valgrindtoolbase.pri)
include(../../libs/cplusplus/cplusplus.pri)
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef CALLGRIND_GLOBAL_H
#define CALLGRIND_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(CALLGRIND_LIBRARY)
# define CALLGRINDSHARED_EXPORT Q_DECL_EXPORT
#else
# define CALLGRINDSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // CALLGRIND_GLOBAL_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "callgrindconfigwidget.h"
#include "ui_callgrindconfigwidget.h"
#include "callgrindsettings.h"
using namespace Callgrind::Internal;
CallgrindConfigWidget::CallgrindConfigWidget(AbstractCallgrindSettings *settings, QWidget *parent)
: QWidget(parent)
, m_ui(new Ui::CallgrindConfigWidget)
, m_settings(settings)
{
m_ui->setupUi(this);
m_ui->enableCacheSim->setChecked(m_settings->enableCacheSim());
connect(m_ui->enableCacheSim, SIGNAL(toggled(bool)),
m_settings, SLOT(setEnableCacheSim(bool)));
connect(m_settings, SIGNAL(enableCacheSimChanged(bool)),
m_ui->enableCacheSim, SLOT(setChecked(bool)));
m_ui->enableBranchSim->setChecked(m_settings->enableBranchSim());
connect(m_ui->enableBranchSim, SIGNAL(toggled(bool)),
m_settings, SLOT(setEnableBranchSim(bool)));
connect(m_settings, SIGNAL(enableBranchSimChanged(bool)),
m_ui->enableBranchSim, SLOT(setChecked(bool)));
m_ui->collectSystime->setChecked(m_settings->collectSystime());
connect(m_ui->collectSystime, SIGNAL(toggled(bool)),
m_settings, SLOT(setCollectSystime(bool)));
connect(m_settings, SIGNAL(collectSystimeChanged(bool)),
m_ui->collectSystime, SLOT(setChecked(bool)));
m_ui->collectBusEvents->setChecked(m_settings->collectBusEvents());
connect(m_ui->collectBusEvents, SIGNAL(toggled(bool)),
m_settings, SLOT(setCollectBusEvents(bool)));
connect(m_settings, SIGNAL(collectBusEventsChanged(bool)),
m_ui->collectBusEvents, SLOT(setChecked(bool)));
}
CallgrindConfigWidget::~CallgrindConfigWidget()
{
delete m_ui;
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef ANALYZER_INTERNAL_CALLGRINDCONFIGWIDGET_H
#define ANALYZER_INTERNAL_CALLGRINDCONFIGWIDGET_H
#include <QtGui/QWidget>
namespace Callgrind {
namespace Internal {
namespace Ui {
class CallgrindConfigWidget;
}
class AbstractCallgrindSettings;
class CallgrindConfigWidget : public QWidget
{
Q_OBJECT
public:
CallgrindConfigWidget(AbstractCallgrindSettings *settings, QWidget *parent);
virtual ~CallgrindConfigWidget();
private:
Ui::CallgrindConfigWidget *m_ui;
AbstractCallgrindSettings *m_settings;
};
}
}
#endif // ANALYZER_INTERNAL_CALLGRINDCONFIGWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Callgrind::Internal::CallgrindConfigWidget</class>
<widget class="QWidget" name="Callgrind::Internal::CallgrindConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<height>565</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="memcheckOptions">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Profiling Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="enableCacheSim">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;
&lt;p&gt;Specify if you want to do full cache simulation.&lt;/p&gt;
&lt;p&gt;By default, only instruction read accesses will be counted (&quot;Ir&quot;).&lt;/p&gt;
&lt;p&gt;
With cache simulation, further event counters are enabled:
&lt;ul&gt;&lt;li&gt;Cache misses on instruction reads (&quot;I1mr&quot;/&quot;I2mr&quot;)&lt;/li&gt;
&lt;li&gt;Data read accesses (&quot;Dr&quot;) and related cache misses (&quot;D1mr&quot;/&quot;D2mr&quot;)&lt;/li&gt;
&lt;li&gt;Data write accesses (&quot;Dw&quot;) and related cache misses (&quot;D1mw&quot;/&quot;D2mw&quot;)&lt;/li&gt;&lt;/ul&gt;
&lt;/p&gt;
For more information, see ???.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Enable cache simulation</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="enableBranchSim">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p&gt;Specify if you want to do branch prediction simulation.&lt;/p&gt;
&lt;p&gt;Further event counters are enabled: &lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Number of executed conditional branches and related predictor misses (
&quot;Bc&quot;/&quot;Bcm&quot;)&lt;/li&gt;
&lt;li&gt;Executed indirect jumps and related misses of the jump address predictor (
&quot;Bi&quot;/&quot;Bim&quot;)&lt;/li&gt;&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Enable branch prediction simulation</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="collectSystime">
<property name="toolTip">
<string>This specifies whether information for system call times should be collected.</string>
</property>
<property name="text">
<string>Collect system call time</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="collectBusEvents">
<property name="toolTip">
<string>This specifies whether the number of global bus events executed should be collected. The event type &quot;Ge&quot; is used for these events.</string>
</property>
<property name="text">
<string>Collect global bus events</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/**************************************************************************
**
** This file is part of Qt Creator Analyzer Tools
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef CALLGRINDCONSTANTS_H
#define CALLGRINDCONSTANTS_H
namespace Callgrind {
namespace Constants {
const char * const A_SHOWCOSTSOFFUNCTION = "Analyzer.Callgrind.ShowCostsOfFunction";
}
}
#endif // CALLGRINDCONSTANTS_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "callgrindcostdelegate.h"
#include "callgrindcostview.h"
#include "callgrindhelper.h"
#include <valgrind/callgrind/callgrindabstractmodel.h>
#include <valgrind/callgrind/callgrindparsedata.h>
#include <utils/qtcassert.h>
#include <QPainter>
#include <QDebug>
#include <QApplication>
using namespace Valgrind::Callgrind;
namespace Callgrind {
namespace Internal {
//BEGIN CostDelegate::Private
class CostDelegate::Private {
public:
Private();
~Private();
Valgrind::Callgrind::AbstractModel *m_model;
CostDelegate::CostFormat m_format;
static int toNativeRole(CostFormat format);
float relativeCost(const QModelIndex &index) const;
QString displayText(const QModelIndex &index, const QLocale &locale) const;
};
CostDelegate::Private::Private()
: m_model(0)
, m_format(CostDelegate::FormatAbsolute)
{
}
CostDelegate::Private::~Private()
{
}
int CostDelegate::Private::toNativeRole(CostDelegate::CostFormat format)
{
switch(format)
{
case FormatAbsolute:
case FormatRelative:
return Valgrind::Callgrind::AbstractModel::RelativeTotalCostRole;
case FormatRelativeToParent:
return Valgrind::Callgrind::AbstractModel::RelativeParentCostRole;
default:
return -1;
}
}
float CostDelegate::Private::relativeCost(const QModelIndex &index) const
{
bool ok = false;
float cost = index.data(toNativeRole(m_format)).toFloat(&ok);
QTC_ASSERT(ok, return 0);
return cost;
}
QString CostDelegate::Private::displayText(const QModelIndex &index, const QLocale &locale) const
{
switch (m_format) {
case FormatAbsolute:
return locale.toString(index.data().toULongLong());
case FormatRelative:
case FormatRelativeToParent:
if (!m_model)
break;
float cost = relativeCost(index) * 100.0f;
return CallgrindHelper::toPercent(cost, locale);
}
return QString();
}
//END CostDelegate::Private
//BEGIN CostDelegate
CostDelegate::CostDelegate(QObject *parent)
: QStyledItemDelegate(parent)
, d(new Private)
{
}
CostDelegate::~CostDelegate()
{
delete d;
}
void CostDelegate::setModel(Valgrind::Callgrind::AbstractModel *model)
{
d->m_model = model;
}
void CostDelegate::setFormat(CostFormat format)
{
d->m_format = format;
}
CostDelegate::CostFormat CostDelegate::format() const
{
return d->m_format;
}
void CostDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
// init
QStyleOptionViewItemV4 opt(option);
initStyleOption(&opt, index);
QStyle *style = opt.widget ? opt.widget->style() : QApplication::style();
// draw controls, but no text
opt.text.clear();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
painter->save();
// draw bar
float ratio = qBound(0.0f, d->relativeCost(index), 1.0f);
QRect barRect = opt.rect;
barRect.setWidth(opt.rect.width() * ratio);
painter->setPen(Qt::NoPen);
painter->setBrush(CallgrindHelper::colorForCostRatio(ratio));
painter->drawRect(barRect);
// draw text
const QString text = d->displayText(index, opt.locale);
const QBrush &textBrush = (option.state & QStyle::State_Selected ? opt.palette.highlightedText() : opt.palette.text());
painter->setBrush(Qt::NoBrush);
painter->setPen(textBrush.color());
painter->drawText(opt.rect, Qt::AlignRight, text);
painter->restore();
}
QSize CostDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{