2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-05-23 13:50:28 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
#include "callgrindtool.h"
|
|
|
|
|
|
|
|
|
|
#include "callgrindcostdelegate.h"
|
|
|
|
|
#include "callgrindcostview.h"
|
|
|
|
|
#include "callgrindengine.h"
|
|
|
|
|
#include "callgrindtextmark.h"
|
|
|
|
|
#include "callgrindvisualisation.h"
|
|
|
|
|
|
|
|
|
|
#include <valgrind/callgrind/callgrindcallmodel.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrindcostitem.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrinddatamodel.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrindfunction.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrindfunctioncall.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrindparsedata.h>
|
2013-09-09 14:34:19 +02:00
|
|
|
#include <valgrind/callgrind/callgrindparser.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
#include <valgrind/callgrind/callgrindproxymodel.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrindstackbrowser.h>
|
2011-07-04 10:50:44 +02:00
|
|
|
#include <valgrind/valgrindplugin.h>
|
2011-07-12 16:47:32 +02:00
|
|
|
#include <valgrind/valgrindsettings.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
#include <analyzerbase/analyzermanager.h>
|
|
|
|
|
#include <analyzerbase/analyzerutils.h>
|
|
|
|
|
#include <analyzerbase/analyzerconstants.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
#include <cplusplus/LookupContext.h>
|
|
|
|
|
#include <cplusplus/Overview.h>
|
2015-02-18 12:25:39 +01:00
|
|
|
#include <cplusplus/Symbols.h>
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
#include <extensionsystem/iplugin.h>
|
2015-02-18 12:25:39 +01:00
|
|
|
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <texteditor/textdocument.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/fancymainwindow.h>
|
|
|
|
|
#include <utils/styledbar.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/project.h>
|
2015-02-18 12:25:39 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2014-11-19 17:58:33 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2015-02-18 12:25:39 +01:00
|
|
|
#include <projectexplorer/session.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QActionGroup>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDockWidget>
|
2013-09-09 14:34:19 +02:00
|
|
|
#include <QFileDialog>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QVBoxLayout>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
using namespace Analyzer;
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Valgrind::Callgrind;
|
2014-09-30 16:54:26 +02:00
|
|
|
using namespace TextEditor;
|
2013-07-30 11:55:28 +02:00
|
|
|
using namespace ProjectExplorer;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class CallgrindToolPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
friend class CallgrindTool;
|
|
|
|
|
|
|
|
|
|
explicit CallgrindToolPrivate(CallgrindTool *parent);
|
|
|
|
|
virtual ~CallgrindToolPrivate();
|
|
|
|
|
|
|
|
|
|
void setParseData(ParseData *data);
|
|
|
|
|
|
|
|
|
|
CostDelegate::CostFormat costFormat() const;
|
2011-07-06 16:52:14 +02:00
|
|
|
QWidget *createWidgets();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
void doClear(bool clearParseData);
|
|
|
|
|
void updateEventCombo();
|
|
|
|
|
|
2015-06-19 08:34:46 +02:00
|
|
|
ValgrindRunControl *createRunControl(const AnalyzerStartParameters &sp,
|
2015-02-03 23:56:02 +02:00
|
|
|
RunConfiguration *runConfiguration = 0);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void cycleDetectionEnabled(bool enabled);
|
|
|
|
|
void dumpRequested();
|
|
|
|
|
void resetRequested();
|
|
|
|
|
void pauseToggled(bool checked);
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void slotClear();
|
|
|
|
|
void slotRequestDump();
|
2014-11-04 11:45:13 +02:00
|
|
|
void loadExternalLogFile();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
void selectFunction(const Function *);
|
|
|
|
|
void setCostFormat(CostDelegate::CostFormat format);
|
2011-05-23 13:50:28 +02:00
|
|
|
void enableCycleDetection(bool enabled);
|
2012-08-22 23:35:02 +02:00
|
|
|
void shortenTemplates(bool enabled);
|
2011-05-23 13:50:28 +02:00
|
|
|
void setCostEvent(int index);
|
|
|
|
|
|
|
|
|
|
/// This function will add custom text marks to the editor
|
|
|
|
|
/// \note Call this after the data model has been populated
|
|
|
|
|
void createTextMarks();
|
|
|
|
|
|
|
|
|
|
/// This function will clear all text marks from the editor
|
|
|
|
|
void clearTextMarks();
|
|
|
|
|
|
|
|
|
|
void updateFilterString();
|
|
|
|
|
void updateCostFormat();
|
|
|
|
|
|
|
|
|
|
void handleFilterProjectCosts();
|
|
|
|
|
void handleShowCostsOfFunction();
|
|
|
|
|
|
|
|
|
|
void slotGoToOverview();
|
|
|
|
|
void stackBrowserChanged();
|
|
|
|
|
|
|
|
|
|
/// If \param busy is true, all widgets get a busy cursor when hovered
|
2011-12-13 14:01:52 +01:00
|
|
|
void setBusyCursor(bool busy);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
void dataFunctionSelected(const QModelIndex &index);
|
|
|
|
|
void calleeFunctionSelected(const QModelIndex &index);
|
|
|
|
|
void callerFunctionSelected(const QModelIndex &index);
|
2015-02-03 23:56:02 +02:00
|
|
|
void visualisationFunctionSelected(const Function *function);
|
|
|
|
|
void showParserResults(const ParseData *data);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2015-02-04 00:18:51 +02:00
|
|
|
void takeParserDataFromRunControl(CallgrindRunControl *rc);
|
2013-09-09 14:34:19 +02:00
|
|
|
void takeParserData(ParseData *data);
|
2015-02-03 23:56:02 +02:00
|
|
|
void engineStarting(const AnalyzerRunControl *);
|
2011-05-23 13:50:28 +02:00
|
|
|
void engineFinished();
|
|
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
void editorOpened(IEditor *);
|
2014-09-30 16:54:26 +02:00
|
|
|
void requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CallgrindTool *q;
|
|
|
|
|
|
|
|
|
|
DataModel *m_dataModel;
|
|
|
|
|
DataProxyModel *m_proxyModel;
|
|
|
|
|
StackBrowser *m_stackBrowser;
|
|
|
|
|
|
|
|
|
|
CallModel *m_callersModel;
|
|
|
|
|
CallModel *m_calleesModel;
|
|
|
|
|
|
|
|
|
|
// callgrind widgets
|
|
|
|
|
CostView *m_flatView;
|
|
|
|
|
CostView *m_callersView;
|
|
|
|
|
CostView *m_calleesView;
|
|
|
|
|
Visualisation *m_visualisation;
|
|
|
|
|
|
|
|
|
|
// navigation
|
|
|
|
|
QAction *m_goBack;
|
2011-06-20 17:30:38 +02:00
|
|
|
QAction *m_goNext;
|
2011-05-23 13:50:28 +02:00
|
|
|
QLineEdit *m_searchFilter;
|
|
|
|
|
|
|
|
|
|
// cost formatting
|
|
|
|
|
QAction *m_filterProjectCosts;
|
|
|
|
|
QAction *m_costAbsolute;
|
|
|
|
|
QAction *m_costRelative;
|
|
|
|
|
QAction *m_costRelativeToParent;
|
|
|
|
|
QAction *m_cycleDetection;
|
2012-08-22 23:35:02 +02:00
|
|
|
QAction *m_shortenTemplates;
|
2011-05-23 13:50:28 +02:00
|
|
|
QComboBox *m_eventCombo;
|
|
|
|
|
|
|
|
|
|
QTimer *m_updateTimer;
|
|
|
|
|
|
|
|
|
|
QVector<CallgrindTextMark *> m_textMarks;
|
|
|
|
|
|
2013-09-09 14:34:19 +02:00
|
|
|
QAction *m_loadExternalLogFile;
|
2011-05-23 13:50:28 +02:00
|
|
|
QAction *m_dumpAction;
|
|
|
|
|
QAction *m_resetAction;
|
|
|
|
|
QAction *m_pauseAction;
|
|
|
|
|
|
|
|
|
|
QString m_toggleCollectFunction;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CallgrindToolPrivate::CallgrindToolPrivate(CallgrindTool *parent)
|
|
|
|
|
: q(parent)
|
|
|
|
|
, m_dataModel(new DataModel(this))
|
|
|
|
|
, m_proxyModel(new DataProxyModel(this))
|
|
|
|
|
, m_stackBrowser(new StackBrowser(this))
|
|
|
|
|
, m_callersModel(new CallModel(this))
|
|
|
|
|
, m_calleesModel(new CallModel(this))
|
|
|
|
|
, m_flatView(0)
|
|
|
|
|
, m_callersView(0)
|
|
|
|
|
, m_calleesView(0)
|
|
|
|
|
, m_visualisation(0)
|
|
|
|
|
, m_goBack(0)
|
2011-06-20 17:30:38 +02:00
|
|
|
, m_goNext(0)
|
2011-05-23 13:50:28 +02:00
|
|
|
, m_searchFilter(0)
|
|
|
|
|
, m_filterProjectCosts(0)
|
|
|
|
|
, m_costAbsolute(0)
|
|
|
|
|
, m_costRelative(0)
|
|
|
|
|
, m_costRelativeToParent(0)
|
|
|
|
|
, m_eventCombo(0)
|
|
|
|
|
, m_updateTimer(new QTimer(this))
|
|
|
|
|
, m_dumpAction(0)
|
|
|
|
|
, m_resetAction(0)
|
|
|
|
|
, m_pauseAction(0)
|
|
|
|
|
{
|
|
|
|
|
m_updateTimer->setInterval(200);
|
|
|
|
|
m_updateTimer->setSingleShot(true);
|
|
|
|
|
|
|
|
|
|
m_proxyModel->setSourceModel(m_dataModel);
|
|
|
|
|
m_proxyModel->setDynamicSortFilter(true);
|
|
|
|
|
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
|
m_proxyModel->setFilterKeyColumn(DataModel::NameColumn);
|
|
|
|
|
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
|
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_stackBrowser, &StackBrowser::currentChanged,
|
|
|
|
|
this, &CallgrindToolPrivate::stackBrowserChanged);
|
|
|
|
|
connect(m_updateTimer, &QTimer::timeout,
|
|
|
|
|
this, &CallgrindToolPrivate::updateFilterString);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallgrindToolPrivate::~CallgrindToolPrivate()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_textMarks);
|
|
|
|
|
doClear(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::slotGoToOverview()
|
|
|
|
|
{
|
|
|
|
|
selectFunction(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::slotClear()
|
|
|
|
|
{
|
|
|
|
|
doClear(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::doClear(bool clearParseData)
|
|
|
|
|
{
|
|
|
|
|
if (clearParseData) // Crashed when done from destructor.
|
|
|
|
|
setParseData(0);
|
|
|
|
|
|
|
|
|
|
// clear filters
|
|
|
|
|
if (m_filterProjectCosts)
|
|
|
|
|
m_filterProjectCosts->setChecked(false);
|
|
|
|
|
m_proxyModel->setFilterBaseDir(QString());
|
|
|
|
|
if (m_searchFilter)
|
2014-07-23 09:53:06 +02:00
|
|
|
m_searchFilter->clear();
|
2011-05-23 13:50:28 +02:00
|
|
|
m_proxyModel->setFilterFixedString(QString());
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-13 14:01:52 +01:00
|
|
|
void CallgrindToolPrivate::setBusyCursor(bool busy)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
QCursor cursor(busy ? Qt::BusyCursor : Qt::ArrowCursor);
|
|
|
|
|
m_flatView->setCursor(cursor);
|
|
|
|
|
m_calleesView->setCursor(cursor);
|
|
|
|
|
m_callersView->setCursor(cursor);
|
|
|
|
|
m_visualisation->setCursor(cursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::selectFunction(const Function *func)
|
|
|
|
|
{
|
|
|
|
|
if (!func) {
|
|
|
|
|
m_flatView->clearSelection();
|
|
|
|
|
m_visualisation->setFunction(0);
|
|
|
|
|
m_callersModel->clear();
|
|
|
|
|
m_calleesModel->clear();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QModelIndex index = m_dataModel->indexForObject(func);
|
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
|
|
|
|
|
m_flatView->selectionModel()->clearSelection();
|
|
|
|
|
m_flatView->selectionModel()->setCurrentIndex(proxyIndex,
|
|
|
|
|
QItemSelectionModel::ClearAndSelect |
|
|
|
|
|
QItemSelectionModel::Rows);
|
|
|
|
|
m_flatView->scrollTo(proxyIndex);
|
|
|
|
|
|
|
|
|
|
m_callersModel->setCalls(func->incomingCalls(), func);
|
|
|
|
|
m_calleesModel->setCalls(func->outgoingCalls(), func);
|
|
|
|
|
m_visualisation->setFunction(func);
|
|
|
|
|
|
|
|
|
|
const Function *item = m_stackBrowser->current();
|
|
|
|
|
if (!item || item != func)
|
|
|
|
|
m_stackBrowser->select(func);
|
|
|
|
|
|
|
|
|
|
if (QFile::exists(func->file())) {
|
|
|
|
|
///TODO: custom position support?
|
|
|
|
|
int line = func->lineNumber();
|
2013-08-29 17:17:24 +02:00
|
|
|
EditorManager::openEditorAt(func->file(), qMax(line, 0));
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::stackBrowserChanged()
|
|
|
|
|
{
|
2011-06-20 17:30:38 +02:00
|
|
|
m_goBack->setEnabled(m_stackBrowser->hasPrevious());
|
|
|
|
|
m_goNext->setEnabled(m_stackBrowser->hasNext());
|
2011-05-23 13:50:28 +02:00
|
|
|
const Function *item = m_stackBrowser->current();
|
|
|
|
|
selectFunction(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::updateFilterString()
|
|
|
|
|
{
|
|
|
|
|
m_proxyModel->setFilterFixedString(m_searchFilter->text());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::setCostFormat(CostDelegate::CostFormat format)
|
|
|
|
|
{
|
|
|
|
|
switch (format) {
|
|
|
|
|
case CostDelegate::FormatAbsolute:
|
|
|
|
|
m_costAbsolute->setChecked(true);
|
|
|
|
|
break;
|
|
|
|
|
case CostDelegate::FormatRelative:
|
|
|
|
|
m_costRelative->setChecked(true);
|
|
|
|
|
break;
|
|
|
|
|
case CostDelegate::FormatRelativeToParent:
|
|
|
|
|
m_costRelativeToParent->setChecked(true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::setCostEvent(int index)
|
|
|
|
|
{
|
|
|
|
|
// prevent assert in model, don't try to set event to -1
|
|
|
|
|
// happens when we clear the eventcombo
|
|
|
|
|
if (index == -1)
|
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
|
|
m_dataModel->setCostEvent(index);
|
|
|
|
|
m_calleesModel->setCostEvent(index);
|
|
|
|
|
m_callersModel->setCostEvent(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::enableCycleDetection(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_cycleDetection->setChecked(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 23:35:02 +02:00
|
|
|
void CallgrindToolPrivate::shortenTemplates(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
m_shortenTemplates->setChecked(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
// Following functions can be called with actions=0 or widgets=0
|
|
|
|
|
// depending on initialization sequence (whether callgrind was current).
|
|
|
|
|
CostDelegate::CostFormat CallgrindToolPrivate::costFormat() const
|
|
|
|
|
{
|
|
|
|
|
if (m_costRelativeToParent && m_costRelativeToParent->isChecked())
|
|
|
|
|
return CostDelegate::FormatRelativeToParent;
|
|
|
|
|
if (m_costRelative && m_costRelative->isChecked())
|
|
|
|
|
return CostDelegate::FormatRelative;
|
|
|
|
|
return CostDelegate::FormatAbsolute;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::updateCostFormat()
|
|
|
|
|
{
|
|
|
|
|
const CostDelegate::CostFormat format = costFormat();
|
|
|
|
|
if (m_flatView)
|
|
|
|
|
m_flatView->setCostFormat(format);
|
|
|
|
|
if (m_calleesView) {
|
|
|
|
|
m_calleesView->setCostFormat(format);
|
|
|
|
|
m_callersView->setCostFormat(format);
|
|
|
|
|
}
|
2013-08-08 17:37:37 +02:00
|
|
|
if (ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings())
|
2013-08-05 18:00:36 +02:00
|
|
|
settings->setCostFormat(format);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::handleFilterProjectCosts()
|
|
|
|
|
{
|
2015-02-03 23:56:02 +02:00
|
|
|
Project *pro = ProjectTree::currentProject();
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(pro, return);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
if (m_filterProjectCosts->isChecked()) {
|
2014-05-02 12:53:36 +02:00
|
|
|
const QString projectDir = pro->projectDirectory().toString();
|
2011-05-23 13:50:28 +02:00
|
|
|
m_proxyModel->setFilterBaseDir(projectDir);
|
2013-07-17 00:01:45 +03:00
|
|
|
} else {
|
2011-05-23 13:50:28 +02:00
|
|
|
m_proxyModel->setFilterBaseDir(QString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::dataFunctionSelected(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
const Function *func = index.data(DataModel::FunctionRole).value<const Function *>();
|
|
|
|
|
QTC_ASSERT(func, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(func);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::calleeFunctionSelected(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
const FunctionCall *call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
|
|
|
|
|
QTC_ASSERT(call, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(call->callee());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::callerFunctionSelected(const QModelIndex &index)
|
|
|
|
|
{
|
|
|
|
|
const FunctionCall *call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
|
|
|
|
|
QTC_ASSERT(call, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(call->caller());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::visualisationFunctionSelected(const Function *function)
|
|
|
|
|
{
|
|
|
|
|
if (function && function == m_visualisation->function())
|
|
|
|
|
// up-navigation when the initial function was activated
|
|
|
|
|
m_stackBrowser->goBack();
|
|
|
|
|
else
|
|
|
|
|
selectFunction(function);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::setParseData(ParseData *data)
|
|
|
|
|
{
|
|
|
|
|
// we have new parse data, invalidate filters in the proxy model
|
|
|
|
|
m_visualisation->setFunction(0);
|
|
|
|
|
|
|
|
|
|
// invalidate parse data in the data model
|
|
|
|
|
delete m_dataModel->parseData();
|
|
|
|
|
|
|
|
|
|
if (data && data->events().isEmpty()) {
|
|
|
|
|
// might happen if the user cancelled the profile run
|
|
|
|
|
// callgrind then sometimes produces empty callgrind.out.PID files
|
|
|
|
|
delete data;
|
|
|
|
|
data = 0;
|
|
|
|
|
}
|
|
|
|
|
m_dataModel->setParseData(data);
|
|
|
|
|
m_calleesModel->setParseData(data);
|
|
|
|
|
m_callersModel->setParseData(data);
|
|
|
|
|
|
|
|
|
|
updateEventCombo();
|
|
|
|
|
|
|
|
|
|
// clear history for new data
|
|
|
|
|
m_stackBrowser->clear();
|
|
|
|
|
|
|
|
|
|
// unset busy state
|
2011-12-13 14:01:52 +01:00
|
|
|
//setBusy(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::updateEventCombo()
|
|
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(m_eventCombo, return);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
m_eventCombo->clear();
|
|
|
|
|
|
|
|
|
|
const ParseData *data = m_dataModel->parseData();
|
|
|
|
|
if (!data || data->events().isEmpty()) {
|
|
|
|
|
m_eventCombo->hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_eventCombo->show();
|
|
|
|
|
foreach (const QString &event, data->events())
|
|
|
|
|
m_eventCombo->addItem(ParseData::prettyStringForEvent(event));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QToolButton *createToolButton(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
QToolButton *button = new QToolButton;
|
|
|
|
|
button->setDefaultAction(action);
|
2011-06-20 17:30:38 +02:00
|
|
|
//button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
2011-05-23 13:50:28 +02:00
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-30 18:55:48 +02:00
|
|
|
CallgrindTool::CallgrindTool(QObject *parent)
|
2015-02-18 14:35:20 +01:00
|
|
|
: QObject(parent)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
d = new CallgrindToolPrivate(this);
|
2011-07-01 14:19:12 +02:00
|
|
|
setObjectName(QLatin1String("CallgrindTool"));
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
|
|
|
|
d, &CallgrindToolPrivate::editorOpened);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallgrindTool::~CallgrindTool()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-19 08:34:46 +02:00
|
|
|
ValgrindRunControl *CallgrindTool::createRunControl(const AnalyzerStartParameters &sp,
|
2013-07-30 11:55:28 +02:00
|
|
|
RunConfiguration *runConfiguration)
|
2011-07-06 16:52:14 +02:00
|
|
|
{
|
2013-07-30 14:08:01 +02:00
|
|
|
return d->createRunControl(sp, runConfiguration);
|
2011-07-06 16:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-19 08:34:46 +02:00
|
|
|
ValgrindRunControl *CallgrindToolPrivate::createRunControl(const AnalyzerStartParameters &sp,
|
2013-07-30 11:55:28 +02:00
|
|
|
RunConfiguration *runConfiguration)
|
2011-07-06 16:52:14 +02:00
|
|
|
{
|
2013-07-30 14:08:01 +02:00
|
|
|
CallgrindRunControl *rc = new CallgrindRunControl(sp, runConfiguration);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(rc, &CallgrindRunControl::parserDataReady,
|
|
|
|
|
this, &CallgrindToolPrivate::takeParserDataFromRunControl);
|
|
|
|
|
connect(rc, &AnalyzerRunControl::starting,
|
|
|
|
|
this, &CallgrindToolPrivate::engineStarting);
|
|
|
|
|
connect(rc, &RunControl::finished,
|
|
|
|
|
this, &CallgrindToolPrivate::engineFinished);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(this, &CallgrindToolPrivate::dumpRequested, rc, &CallgrindRunControl::dump);
|
|
|
|
|
connect(this, &CallgrindToolPrivate::resetRequested, rc, &CallgrindRunControl::reset);
|
|
|
|
|
connect(this, &CallgrindToolPrivate::pauseToggled, rc, &CallgrindRunControl::setPaused);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
// initialize run control
|
|
|
|
|
rc->setPaused(m_pauseAction->isChecked());
|
2011-07-06 16:52:14 +02:00
|
|
|
|
|
|
|
|
// we may want to toggle collect for one function only in this run
|
2013-07-30 14:08:01 +02:00
|
|
|
rc->setToggleCollectFunction(m_toggleCollectFunction);
|
2011-07-06 16:52:14 +02:00
|
|
|
m_toggleCollectFunction.clear();
|
|
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
QTC_ASSERT(m_visualisation, return rc);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2011-07-18 16:10:25 +02:00
|
|
|
// apply project settings
|
|
|
|
|
if (runConfiguration) {
|
2013-08-12 17:04:10 +02:00
|
|
|
if (IRunConfigurationAspect *analyzerAspect = runConfiguration->extraAspect(ANALYZER_VALGRIND_SETTINGS)) {
|
2013-08-12 15:07:23 +02:00
|
|
|
if (const ValgrindBaseSettings *settings = qobject_cast<ValgrindBaseSettings *>(analyzerAspect->currentSettings())) {
|
2011-07-18 16:10:25 +02:00
|
|
|
m_visualisation->setMinimumInclusiveCostRatio(settings->visualisationMinimumInclusiveCostRatio() / 100.0);
|
|
|
|
|
m_proxyModel->setMinimumInclusiveCostRatio(settings->minimumInclusiveCostRatio() / 100.0);
|
|
|
|
|
m_dataModel->setVerboseToolTipsEnabled(settings->enableEventToolTips());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-30 14:08:01 +02:00
|
|
|
return rc;
|
2011-07-06 16:52:14 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 11:55:54 +02:00
|
|
|
void CallgrindTool::handleShowCostsOfFunction()
|
|
|
|
|
{
|
|
|
|
|
d->handleShowCostsOfFunction();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-06 16:52:14 +02:00
|
|
|
QWidget *CallgrindTool::createWidgets()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2011-07-06 16:52:14 +02:00
|
|
|
return d->createWidgets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *CallgrindToolPrivate::createWidgets()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_visualisation, return 0);
|
|
|
|
|
|
2014-07-16 16:32:11 +02:00
|
|
|
QSettings *coreSettings = ICore::settings();
|
|
|
|
|
|
2011-07-06 16:52:14 +02:00
|
|
|
//
|
|
|
|
|
// DockWidgets
|
|
|
|
|
//
|
2011-06-30 13:44:22 +02:00
|
|
|
Utils::FancyMainWindow *mw = AnalyzerManager::mainWindow();
|
2011-05-23 13:50:28 +02:00
|
|
|
m_visualisation = new Visualisation(mw);
|
|
|
|
|
m_visualisation->setFrameStyle(QFrame::NoFrame);
|
2012-11-26 15:02:17 +02:00
|
|
|
m_visualisation->setObjectName(QLatin1String("Valgrind.CallgrindTool.Visualisation"));
|
2014-07-23 16:07:39 +02:00
|
|
|
m_visualisation->setWindowTitle(tr("Visualization"));
|
2011-05-23 13:50:28 +02:00
|
|
|
m_visualisation->setModel(m_dataModel);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_visualisation, &Visualisation::functionActivated,
|
|
|
|
|
this, &CallgrindToolPrivate::visualisationFunctionSelected);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
m_callersView = new CostView(mw);
|
2012-11-26 15:02:17 +02:00
|
|
|
m_callersView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CallersView"));
|
2014-07-23 16:07:39 +02:00
|
|
|
m_callersView->setWindowTitle(tr("Callers"));
|
2014-07-16 16:32:11 +02:00
|
|
|
m_callersView->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView");
|
2011-05-23 13:50:28 +02:00
|
|
|
m_callersView->sortByColumn(CallModel::CostColumn);
|
|
|
|
|
m_callersView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
// enable sorting
|
|
|
|
|
QSortFilterProxyModel *callerProxy = new QSortFilterProxyModel(m_callersModel);
|
|
|
|
|
callerProxy->setSourceModel(m_callersModel);
|
|
|
|
|
m_callersView->setModel(callerProxy);
|
|
|
|
|
m_callersView->hideColumn(CallModel::CalleeColumn);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_callersView, &QAbstractItemView::activated,
|
|
|
|
|
this, &CallgrindToolPrivate::callerFunctionSelected);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
m_calleesView = new CostView(mw);
|
2012-11-26 15:02:17 +02:00
|
|
|
m_calleesView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CalleesView"));
|
2014-07-23 16:07:39 +02:00
|
|
|
m_calleesView->setWindowTitle(tr("Callees"));
|
2014-07-16 16:32:11 +02:00
|
|
|
m_calleesView->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView");
|
2011-05-23 13:50:28 +02:00
|
|
|
m_calleesView->sortByColumn(CallModel::CostColumn);
|
|
|
|
|
m_calleesView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
// enable sorting
|
|
|
|
|
QSortFilterProxyModel *calleeProxy = new QSortFilterProxyModel(m_calleesModel);
|
|
|
|
|
calleeProxy->setSourceModel(m_calleesModel);
|
|
|
|
|
m_calleesView->setModel(calleeProxy);
|
|
|
|
|
m_calleesView->hideColumn(CallModel::CallerColumn);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_calleesView, &QAbstractItemView::activated,
|
|
|
|
|
this, &CallgrindToolPrivate::calleeFunctionSelected);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
m_flatView = new CostView(mw);
|
2012-11-26 15:02:17 +02:00
|
|
|
m_flatView->setObjectName(QLatin1String("Valgrind.CallgrindTool.FlatView"));
|
2014-07-23 16:07:39 +02:00
|
|
|
m_flatView->setWindowTitle(tr("Functions"));
|
2014-07-16 16:32:11 +02:00
|
|
|
m_flatView->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView");
|
2011-05-23 13:50:28 +02:00
|
|
|
m_flatView->sortByColumn(DataModel::SelfCostColumn);
|
|
|
|
|
m_flatView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
m_flatView->setModel(m_proxyModel);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_flatView, &QAbstractItemView::activated,
|
|
|
|
|
this, &CallgrindToolPrivate::dataFunctionSelected);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
updateCostFormat();
|
|
|
|
|
|
2015-02-18 14:35:20 +01:00
|
|
|
QDockWidget *callersDock = AnalyzerManager::createDockWidget(CallgrindToolId, m_callersView);
|
|
|
|
|
QDockWidget *flatDock = AnalyzerManager::createDockWidget(CallgrindToolId, m_flatView);
|
|
|
|
|
QDockWidget *calleesDock = AnalyzerManager::createDockWidget(CallgrindToolId, m_calleesView);
|
2011-06-30 13:44:22 +02:00
|
|
|
QDockWidget *visualizationDock = AnalyzerManager::createDockWidget
|
2015-02-18 14:35:20 +01:00
|
|
|
(CallgrindToolId, m_visualisation, Qt::RightDockWidgetArea);
|
2011-07-05 15:36:49 +02:00
|
|
|
|
|
|
|
|
callersDock->show();
|
|
|
|
|
calleesDock->show();
|
|
|
|
|
flatDock->show();
|
2011-05-23 13:50:28 +02:00
|
|
|
visualizationDock->hide();
|
|
|
|
|
|
|
|
|
|
mw->splitDockWidget(mw->toolBarDockWidget(), flatDock, Qt::Vertical);
|
2011-07-05 15:36:49 +02:00
|
|
|
mw->splitDockWidget(mw->toolBarDockWidget(), calleesDock, Qt::Vertical);
|
|
|
|
|
mw->splitDockWidget(calleesDock, callersDock, Qt::Horizontal);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2011-07-06 16:52:14 +02:00
|
|
|
//
|
|
|
|
|
// Control Widget
|
|
|
|
|
//
|
2011-05-23 13:50:28 +02:00
|
|
|
QAction *action = 0;
|
|
|
|
|
QWidget *widget = new QWidget;
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout;
|
|
|
|
|
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
2014-11-04 11:45:13 +02:00
|
|
|
// load external log file
|
2013-09-09 14:34:19 +02:00
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_OPENFILE)));
|
2014-11-04 11:45:13 +02:00
|
|
|
action->setToolTip(tr("Load External Log File"));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::triggered, this, &CallgrindToolPrivate::loadExternalLogFile);
|
2013-09-09 14:34:19 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_loadExternalLogFile = action;
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
// dump action
|
|
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
|
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_REDO)));
|
2011-06-20 17:30:38 +02:00
|
|
|
//action->setText(tr("Dump"));
|
2014-03-06 14:57:35 +01:00
|
|
|
action->setToolTip(tr("Request the dumping of profile information. This will update the Callgrind visualization."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::triggered, this, &CallgrindToolPrivate::slotRequestDump);
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_dumpAction = action;
|
|
|
|
|
|
|
|
|
|
// reset action
|
|
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
|
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR)));
|
2011-06-20 17:30:38 +02:00
|
|
|
//action->setText(tr("Reset"));
|
|
|
|
|
action->setToolTip(tr("Reset all event counters."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::triggered, this, &CallgrindToolPrivate::resetRequested);
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_resetAction = action;
|
|
|
|
|
|
|
|
|
|
// pause action
|
|
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setCheckable(true);
|
2014-03-25 12:45:51 +01:00
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PAUSE)));
|
2011-06-20 17:30:38 +02:00
|
|
|
//action->setText(tr("Ignore"));
|
|
|
|
|
action->setToolTip(tr("Pause event logging. No events are counted which will speed up program execution during profiling."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::toggled, this, &CallgrindToolPrivate::pauseToggled);
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_pauseAction = action;
|
|
|
|
|
|
|
|
|
|
// navigation
|
|
|
|
|
// go back
|
|
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
2012-01-17 13:06:12 +02:00
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_PREV)));
|
2011-05-23 13:50:28 +02:00
|
|
|
action->setToolTip(tr("Go back one step in history. This will select the previously selected item."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::triggered, m_stackBrowser, &StackBrowser::goBack);
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_goBack = action;
|
|
|
|
|
|
2011-06-20 17:30:38 +02:00
|
|
|
// go forward
|
|
|
|
|
action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
2012-01-17 13:06:12 +02:00
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_NEXT)));
|
2011-06-20 17:30:38 +02:00
|
|
|
action->setToolTip(tr("Go forward one step in history."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::triggered, m_stackBrowser, &StackBrowser::goNext);
|
2011-06-20 17:30:38 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_goNext = action;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
layout->addWidget(new Utils::StyledSeparator);
|
|
|
|
|
|
|
|
|
|
// event selection
|
|
|
|
|
m_eventCombo = new QComboBox;
|
|
|
|
|
m_eventCombo->setToolTip(tr("Selects which events from the profiling data are shown and visualized."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_eventCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &CallgrindToolPrivate::setCostEvent);
|
2011-05-23 13:50:28 +02:00
|
|
|
updateEventCombo();
|
|
|
|
|
layout->addWidget(m_eventCombo);
|
|
|
|
|
|
|
|
|
|
// cost formatting
|
|
|
|
|
{
|
|
|
|
|
QMenu *menu = new QMenu(layout->parentWidget());
|
|
|
|
|
QActionGroup *group = new QActionGroup(this);
|
|
|
|
|
|
|
|
|
|
// show costs as absolute numbers
|
|
|
|
|
m_costAbsolute = new QAction(tr("Absolute Costs"), this);
|
|
|
|
|
m_costAbsolute->setToolTip(tr("Show costs as absolute numbers."));
|
|
|
|
|
m_costAbsolute->setCheckable(true);
|
|
|
|
|
m_costAbsolute->setChecked(true);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_costAbsolute, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
|
2011-05-23 13:50:28 +02:00
|
|
|
group->addAction(m_costAbsolute);
|
|
|
|
|
menu->addAction(m_costAbsolute);
|
|
|
|
|
|
|
|
|
|
// show costs in percentages
|
|
|
|
|
m_costRelative = new QAction(tr("Relative Costs"), this);
|
|
|
|
|
m_costRelative->setToolTip(tr("Show costs relative to total inclusive cost."));
|
|
|
|
|
m_costRelative->setCheckable(true);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_costRelative, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
|
2011-05-23 13:50:28 +02:00
|
|
|
group->addAction(m_costRelative);
|
|
|
|
|
menu->addAction(m_costRelative);
|
|
|
|
|
|
|
|
|
|
// show costs relative to parent
|
|
|
|
|
m_costRelativeToParent = new QAction(tr("Relative Costs to Parent"), this);
|
|
|
|
|
m_costRelativeToParent->setToolTip(tr("Show costs relative to parent functions inclusive cost."));
|
|
|
|
|
m_costRelativeToParent->setCheckable(true);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
|
2011-05-23 13:50:28 +02:00
|
|
|
group->addAction(m_costRelativeToParent);
|
|
|
|
|
menu->addAction(m_costRelativeToParent);
|
|
|
|
|
|
|
|
|
|
QToolButton *button = new QToolButton;
|
|
|
|
|
button->setMenu(menu);
|
|
|
|
|
button->setPopupMode(QToolButton::InstantPopup);
|
2012-08-22 23:35:02 +02:00
|
|
|
button->setText(QLatin1String("$"));
|
|
|
|
|
button->setToolTip(tr("Cost Format"));
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(button);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-05 18:00:36 +02:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings();
|
2013-08-05 18:00:36 +02:00
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
// cycle detection
|
2012-08-22 23:35:02 +02:00
|
|
|
//action = new QAction(QLatin1String("Cycle Detection"), this); ///FIXME: icon
|
|
|
|
|
action = new QAction(QLatin1String("O"), this); ///FIXME: icon
|
2011-05-23 13:50:28 +02:00
|
|
|
action->setToolTip(tr("Enable cycle detection to properly handle recursive or circular function calls."));
|
|
|
|
|
action->setCheckable(true);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::toggled, m_dataModel, &DataModel::enableCycleDetection);
|
|
|
|
|
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setDetectCycles);
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_cycleDetection = action;
|
2012-08-22 23:35:02 +02:00
|
|
|
|
|
|
|
|
// shorter template signature
|
|
|
|
|
action = new QAction(QLatin1String("<>"), this);
|
|
|
|
|
action->setToolTip(tr("This removes template parameter lists when displaying function names."));
|
|
|
|
|
action->setCheckable(true);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::toggled, m_dataModel, &DataModel::setShortenTemplates);
|
|
|
|
|
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setShortenTemplates);
|
2012-08-22 23:35:02 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_shortenTemplates = action;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
// filtering
|
|
|
|
|
action = new QAction(tr("Show Project Costs Only"), this);
|
2012-11-26 15:02:17 +02:00
|
|
|
action->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
2011-05-23 13:50:28 +02:00
|
|
|
action->setToolTip(tr("Show only profiling info that originated from this project source."));
|
|
|
|
|
action->setCheckable(true);
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(action, &QAction::toggled, this, &CallgrindToolPrivate::handleFilterProjectCosts);
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(createToolButton(action));
|
|
|
|
|
m_filterProjectCosts = action;
|
|
|
|
|
|
|
|
|
|
// filter
|
2014-12-15 09:31:53 +01:00
|
|
|
///FIXME: find workaround for https://bugreports.qt.io/browse/QTCREATORBUG-3247
|
2011-05-23 13:50:28 +02:00
|
|
|
QLineEdit *filter = new QLineEdit;
|
|
|
|
|
filter->setPlaceholderText(tr("Filter..."));
|
2015-02-04 00:18:51 +02:00
|
|
|
connect(filter, &QLineEdit::textChanged,
|
|
|
|
|
m_updateTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
|
2011-05-23 13:50:28 +02:00
|
|
|
layout->addWidget(filter);
|
|
|
|
|
m_searchFilter = filter;
|
|
|
|
|
|
2013-08-05 18:00:36 +02:00
|
|
|
setCostFormat(settings->costFormat());
|
|
|
|
|
enableCycleDetection(settings->detectCycles());
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
layout->addWidget(new Utils::StyledSeparator);
|
|
|
|
|
layout->addStretch();
|
|
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::clearTextMarks()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_textMarks);
|
|
|
|
|
m_textMarks.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:56:02 +02:00
|
|
|
void CallgrindToolPrivate::engineStarting(const AnalyzerRunControl *)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
// enable/disable actions
|
|
|
|
|
m_resetAction->setEnabled(true);
|
|
|
|
|
m_dumpAction->setEnabled(true);
|
2013-09-09 14:34:19 +02:00
|
|
|
m_loadExternalLogFile->setEnabled(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
clearTextMarks();
|
|
|
|
|
slotClear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::engineFinished()
|
|
|
|
|
{
|
|
|
|
|
// enable/disable actions
|
|
|
|
|
m_resetAction->setEnabled(false);
|
|
|
|
|
m_dumpAction->setEnabled(false);
|
2013-09-09 14:34:19 +02:00
|
|
|
m_loadExternalLogFile->setEnabled(true);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
const ParseData *data = m_dataModel->parseData();
|
|
|
|
|
if (data)
|
|
|
|
|
showParserResults(data);
|
|
|
|
|
else
|
2015-07-01 12:31:27 +02:00
|
|
|
AnalyzerManager::showStatusMessage(CallgrindToolId, tr("Profiling aborted."));
|
2011-12-13 14:01:52 +01:00
|
|
|
|
|
|
|
|
setBusyCursor(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::showParserResults(const ParseData *data)
|
|
|
|
|
{
|
|
|
|
|
QString msg;
|
|
|
|
|
if (data) {
|
|
|
|
|
// be careful, the list of events might be empty
|
|
|
|
|
if (data->events().isEmpty()) {
|
|
|
|
|
msg = tr("Parsing finished, no data.");
|
|
|
|
|
} else {
|
2012-11-26 15:02:17 +02:00
|
|
|
const QString costStr = QString::fromLatin1("%1 %2").arg(QString::number(data->totalCost(0)), data->events().first());
|
2011-05-23 13:50:28 +02:00
|
|
|
msg = tr("Parsing finished, total cost of %1 reported.").arg(costStr);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
msg = tr("Parsing failed.");
|
|
|
|
|
}
|
2015-07-01 12:31:27 +02:00
|
|
|
AnalyzerManager::showStatusMessage(CallgrindToolId, msg);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-29 17:17:24 +02:00
|
|
|
void CallgrindToolPrivate::editorOpened(IEditor *editor)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2014-09-30 16:54:26 +02:00
|
|
|
if (auto widget = qobject_cast<TextEditorWidget *>(editor->widget())) {
|
|
|
|
|
connect(widget, &TextEditorWidget::markContextMenuRequested,
|
|
|
|
|
this, &CallgrindToolPrivate::requestContextMenu);
|
|
|
|
|
}
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-30 16:54:26 +02:00
|
|
|
void CallgrindToolPrivate::requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2015-02-18 17:31:43 +01:00
|
|
|
// Find callgrind text mark that corresponds to this editor's file and line number
|
2011-05-23 13:50:28 +02:00
|
|
|
foreach (CallgrindTextMark *textMark, m_textMarks) {
|
2014-12-21 21:54:30 +02:00
|
|
|
if (textMark->fileName() == widget->textDocument()->filePath().toString() && textMark->lineNumber() == line) {
|
2015-02-18 17:31:43 +01:00
|
|
|
const Function *func = textMark->function();
|
|
|
|
|
QAction *action = menu->addAction(tr("Select this Function in the Analyzer Output"));
|
|
|
|
|
connect(action, &QAction::triggered, this, [this, func] { selectFunction(func); });
|
2011-05-23 13:50:28 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::handleShowCostsOfFunction()
|
|
|
|
|
{
|
|
|
|
|
CPlusPlus::Symbol *symbol = AnalyzerUtils::findSymbolUnderCursor();
|
|
|
|
|
if (!symbol)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!symbol->isFunction())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::Overview view;
|
|
|
|
|
const QString qualifiedFunctionName = view.prettyName(CPlusPlus::LookupContext::fullyQualifiedName(symbol));
|
|
|
|
|
|
2012-02-02 20:30:23 +01:00
|
|
|
m_toggleCollectFunction = qualifiedFunctionName + QLatin1String("()");
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2015-06-22 18:08:44 +02:00
|
|
|
AnalyzerManager::selectAction(CallgrindLocalActionId, /* alsoRunIt = */ true);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::slotRequestDump()
|
|
|
|
|
{
|
2011-12-13 14:01:52 +01:00
|
|
|
//setBusy(true);
|
2011-05-23 13:50:28 +02:00
|
|
|
m_visualisation->setText(tr("Populating..."));
|
|
|
|
|
dumpRequested();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-04 11:45:13 +02:00
|
|
|
void CallgrindToolPrivate::loadExternalLogFile()
|
2013-09-09 14:34:19 +02:00
|
|
|
{
|
2013-09-29 14:41:37 +03:00
|
|
|
const QString filePath = QFileDialog::getOpenFileName(
|
2015-02-03 23:56:02 +02:00
|
|
|
ICore::mainWindow(),
|
2014-02-19 22:37:55 +02:00
|
|
|
tr("Open Callgrind Log File"),
|
2013-09-29 14:41:37 +03:00
|
|
|
QString(),
|
2014-02-19 22:37:55 +02:00
|
|
|
tr("Callgrind Output (callgrind.out*);;All Files (*)"));
|
2013-09-09 14:34:19 +02:00
|
|
|
if (filePath.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QFile logFile(filePath);
|
|
|
|
|
if (!logFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
2015-03-03 12:13:21 +01:00
|
|
|
AnalyzerUtils::logToIssuesPane(Task::Error,
|
|
|
|
|
tr("Callgrind: Failed to open file for reading: %1").arg(filePath));
|
2013-09-09 14:34:19 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-01 12:31:27 +02:00
|
|
|
AnalyzerManager::showStatusMessage(CallgrindToolId, tr("Parsing Profile Data..."));
|
2013-09-09 14:34:19 +02:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
|
|
Parser parser;
|
|
|
|
|
parser.parse(&logFile);
|
|
|
|
|
takeParserData(parser.takeData());
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 00:18:51 +02:00
|
|
|
void CallgrindToolPrivate::takeParserDataFromRunControl(CallgrindRunControl *rc)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2013-09-09 14:34:19 +02:00
|
|
|
takeParserData(rc->takeParserData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::takeParserData(ParseData *data)
|
|
|
|
|
{
|
2011-05-23 13:50:28 +02:00
|
|
|
showParserResults(data);
|
|
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// clear first
|
|
|
|
|
clearTextMarks();
|
|
|
|
|
slotClear();
|
|
|
|
|
|
|
|
|
|
setParseData(data);
|
|
|
|
|
createTextMarks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolPrivate::createTextMarks()
|
|
|
|
|
{
|
|
|
|
|
DataModel *model = m_dataModel;
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(model, return);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
QList<QString> locations;
|
|
|
|
|
for (int row = 0; row < model->rowCount(); ++row) {
|
|
|
|
|
const QModelIndex index = model->index(row, DataModel::InclusiveCostColumn);
|
|
|
|
|
|
|
|
|
|
QString fileName = index.data(DataModel::FileNameRole).toString();
|
2012-11-26 15:02:17 +02:00
|
|
|
if (fileName.isEmpty() || fileName == QLatin1String("???"))
|
2011-05-23 13:50:28 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
const int lineNumber = index.data(DataModel::LineNumberRole).toInt(&ok);
|
|
|
|
|
QTC_ASSERT(ok, continue);
|
|
|
|
|
|
|
|
|
|
// sanitize filename, text marks need a canonical (i.e. no ".."s) path
|
|
|
|
|
// BaseTextMark::editorOpened(Core::IEditor *editor) compares file names on string basis
|
|
|
|
|
QFileInfo info(fileName);
|
|
|
|
|
fileName = info.canonicalFilePath();
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
continue; // isEmpty == true => file does not exist, continue then
|
|
|
|
|
|
|
|
|
|
// create only one text mark per location
|
2012-11-26 15:02:17 +02:00
|
|
|
const QString location = QString::fromLatin1("%1:%2").arg(fileName, QString::number(lineNumber));
|
2011-05-23 13:50:28 +02:00
|
|
|
if (locations.contains(location))
|
|
|
|
|
continue;
|
|
|
|
|
locations << location;
|
|
|
|
|
|
2014-07-19 11:27:28 +02:00
|
|
|
m_textMarks.append(new CallgrindTextMark(index, fileName, lineNumber));
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Valgrind
|
|
|
|
|
|
|
|
|
|
#include "callgrindtool.moc"
|