2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-05-23 13:50:28 +02:00
|
|
|
**
|
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
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
#include <debugger/debuggerconstants.h>
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <debugger/analyzer/analyzerconstants.h>
|
2016-02-24 14:42:52 +01:00
|
|
|
#include <debugger/analyzer/analyzermanager.h>
|
|
|
|
|
#include <debugger/analyzer/analyzerutils.h>
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <debugger/analyzer/startremotedialog.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <coreplugin/icore.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>
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
2015-02-18 12:25:39 +01:00
|
|
|
|
2016-03-07 17:33:58 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
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 <projectexplorer/project.h>
|
2015-02-18 12:25:39 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2016-03-07 17:33:58 +01:00
|
|
|
#include <projectexplorer/projectexplorericons.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>
|
2016-05-31 16:09:48 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-03-07 17:33:58 +01:00
|
|
|
#include <utils/fancymainwindow.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/styledbar.h>
|
2016-05-23 14:15:06 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2016-03-07 17:33:58 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QActionGroup>
|
|
|
|
|
#include <QComboBox>
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <QFile>
|
2013-09-09 14:34:19 +02:00
|
|
|
#include <QFileDialog>
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <QFileInfo>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
2016-03-02 12:05:30 +01:00
|
|
|
#include <QTimer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QToolBar>
|
|
|
|
|
#include <QToolButton>
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
using namespace Debugger;
|
2011-05-23 13:50:28 +02:00
|
|
|
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;
|
2016-03-02 13:57:37 +01:00
|
|
|
using namespace Utils;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
namespace Valgrind {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-03-07 17:33:58 +01:00
|
|
|
const char CallgrindPerspectiveId[] = "Callgrind.Perspective";
|
|
|
|
|
const char CallgrindLocalActionId[] = "Callgrind.Local.Action";
|
|
|
|
|
const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action";
|
|
|
|
|
const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode";
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
class CallgrindTool : public QObject
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2017-07-03 13:55:25 +02:00
|
|
|
CallgrindTool();
|
2016-03-02 12:05:30 +01:00
|
|
|
~CallgrindTool();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2018-05-29 13:54:07 +02:00
|
|
|
void setupRunner(CallgrindToolRunner *runner);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
void setParseData(ParseData *data);
|
|
|
|
|
CostDelegate::CostFormat costFormat() const;
|
|
|
|
|
|
|
|
|
|
void doClear(bool clearParseData);
|
|
|
|
|
void updateEventCombo();
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void dumpRequested();
|
|
|
|
|
void resetRequested();
|
|
|
|
|
void pauseToggled(bool checked);
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
public:
|
2011-05-23 13:50:28 +02:00
|
|
|
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 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
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void takeParserDataFromRunControl(CallgrindToolRunner *rc);
|
2013-09-09 14:34:19 +02:00
|
|
|
void takeParserData(ParseData *data);
|
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);
|
2016-03-02 13:57:37 +01:00
|
|
|
void updateRunActions();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
public:
|
2016-03-02 12:05:30 +01:00
|
|
|
DataModel m_dataModel;
|
|
|
|
|
DataProxyModel m_proxyModel;
|
|
|
|
|
StackBrowser m_stackBrowser;
|
|
|
|
|
|
|
|
|
|
CallModel m_callersModel;
|
|
|
|
|
CallModel m_calleesModel;
|
|
|
|
|
|
|
|
|
|
QSortFilterProxyModel m_callersProxy;
|
|
|
|
|
QSortFilterProxyModel m_calleesProxy;
|
|
|
|
|
|
|
|
|
|
// Callgrind widgets
|
2018-08-02 10:21:05 +02:00
|
|
|
QPointer<CostView> m_flatView;
|
|
|
|
|
QPointer<CostView> m_callersView;
|
|
|
|
|
QPointer<CostView> m_calleesView;
|
|
|
|
|
QPointer<Visualization> m_visualization;
|
2016-03-02 12:05:30 +01:00
|
|
|
|
|
|
|
|
// Navigation
|
2018-03-15 21:48:44 +02:00
|
|
|
QAction *m_goBack = nullptr;
|
|
|
|
|
QAction *m_goNext = nullptr;
|
|
|
|
|
QLineEdit *m_searchFilter = nullptr;
|
2016-03-02 12:05:30 +01:00
|
|
|
|
|
|
|
|
// Cost formatting
|
2018-03-15 21:48:44 +02:00
|
|
|
QAction *m_filterProjectCosts = nullptr;
|
|
|
|
|
QAction *m_costAbsolute = nullptr;
|
|
|
|
|
QAction *m_costRelative = nullptr;
|
|
|
|
|
QAction *m_costRelativeToParent = nullptr;
|
|
|
|
|
QAction *m_cycleDetection = nullptr;
|
|
|
|
|
QAction *m_shortenTemplates = nullptr;
|
|
|
|
|
QComboBox *m_eventCombo = nullptr;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
QTimer m_updateTimer;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
QVector<CallgrindTextMark *> m_textMarks;
|
|
|
|
|
|
2018-03-15 21:48:44 +02:00
|
|
|
QAction *m_startAction = nullptr;
|
|
|
|
|
QAction *m_stopAction = nullptr;
|
|
|
|
|
QAction *m_loadExternalLogFile = nullptr;
|
|
|
|
|
QAction *m_dumpAction = nullptr;
|
|
|
|
|
QAction *m_resetAction = nullptr;
|
|
|
|
|
QAction *m_pauseAction = nullptr;
|
2018-05-15 08:58:01 +02:00
|
|
|
QAction *m_discardAction = nullptr;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
QString m_toggleCollectFunction;
|
2016-03-02 13:57:37 +01:00
|
|
|
bool m_toolBusy = false;
|
2011-05-23 13:50:28 +02:00
|
|
|
};
|
|
|
|
|
|
2017-07-03 13:55:25 +02:00
|
|
|
CallgrindTool::CallgrindTool()
|
2016-03-02 12:05:30 +01:00
|
|
|
{
|
|
|
|
|
setObjectName(QLatin1String("CallgrindTool"));
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
connect(&m_stackBrowser, &StackBrowser::currentChanged,
|
|
|
|
|
this, &CallgrindTool::stackBrowserChanged);
|
|
|
|
|
connect(&m_updateTimer, &QTimer::timeout,
|
|
|
|
|
this, &CallgrindTool::updateFilterString);
|
|
|
|
|
|
|
|
|
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
|
|
|
|
this, &CallgrindTool::editorOpened);
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
m_startAction = Debugger::createStartAction();
|
|
|
|
|
m_stopAction = Debugger::createStopAction();
|
|
|
|
|
|
2017-04-12 10:06:41 +02:00
|
|
|
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
|
|
|
|
|
QString toolTip = tr("Valgrind Function Profiler uses the "
|
|
|
|
|
"Callgrind tool to record function calls when a program runs.");
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
if (!Utils::HostOsInfo::isWindowsHost()) {
|
2017-04-12 10:06:41 +02:00
|
|
|
auto action = new QAction(tr("Valgrind Function Profiler"), this);
|
|
|
|
|
action->setToolTip(toolTip);
|
|
|
|
|
menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId),
|
|
|
|
|
Debugger::Constants::G_ANALYZER_TOOLS);
|
|
|
|
|
QObject::connect(action, &QAction::triggered, this, [action] {
|
|
|
|
|
if (!Debugger::wantRunTool(OptimizedMode, action->text()))
|
|
|
|
|
return;
|
|
|
|
|
Debugger::selectPerspective(CallgrindPerspectiveId);
|
|
|
|
|
ProjectExplorerPlugin::runStartupProject(CALLGRIND_RUN_MODE);
|
|
|
|
|
});
|
|
|
|
|
QObject::connect(m_startAction, &QAction::triggered, action, &QAction::triggered);
|
|
|
|
|
QObject::connect(m_startAction, &QAction::changed, action, [action, this] {
|
|
|
|
|
action->setEnabled(m_startAction->isEnabled());
|
2016-03-02 12:05:30 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-12 10:06:41 +02:00
|
|
|
auto action = new QAction(tr("Valgrind Function Profiler (External Application)"), this);
|
|
|
|
|
action->setToolTip(toolTip);
|
|
|
|
|
menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId),
|
|
|
|
|
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
|
2018-05-29 13:54:07 +02:00
|
|
|
QObject::connect(action, &QAction::triggered, this, [action] {
|
2017-06-30 08:41:08 +02:00
|
|
|
auto runConfig = RunConfiguration::startupRunConfiguration();
|
2017-04-12 10:06:41 +02:00
|
|
|
if (!runConfig) {
|
|
|
|
|
showCannotStartDialog(action->text());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-03-02 12:05:30 +01:00
|
|
|
StartRemoteDialog dlg;
|
|
|
|
|
if (dlg.exec() != QDialog::Accepted)
|
|
|
|
|
return;
|
2017-04-12 10:06:41 +02:00
|
|
|
Debugger::selectPerspective(CallgrindPerspectiveId);
|
2017-04-27 17:23:28 +02:00
|
|
|
auto runControl = new RunControl(runConfig, CALLGRIND_RUN_MODE);
|
2018-05-29 13:54:07 +02:00
|
|
|
if (auto creator = RunControl::producer(runConfig, CALLGRIND_RUN_MODE))
|
|
|
|
|
creator(runControl);
|
2016-03-02 12:05:30 +01:00
|
|
|
const auto runnable = dlg.runnable();
|
2017-04-27 17:23:28 +02:00
|
|
|
runControl->setRunnable(runnable);
|
|
|
|
|
runControl->setDisplayName(runnable.executable);
|
|
|
|
|
ProjectExplorerPlugin::startRunControl(runControl);
|
2016-03-02 12:05:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// If there is a CppEditor context menu add our own context menu actions.
|
|
|
|
|
if (ActionContainer *editorContextMenu =
|
|
|
|
|
ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT)) {
|
2016-03-02 13:57:37 +01:00
|
|
|
Context analyzerContext = Context(Debugger::Constants::C_DEBUGMODE);
|
2016-03-02 12:05:30 +01:00
|
|
|
editorContextMenu->addSeparator(analyzerContext);
|
|
|
|
|
|
|
|
|
|
auto action = new QAction(tr("Profile Costs of This Function and Its Callees"), this);
|
2016-05-30 16:29:51 +02:00
|
|
|
action->setIcon(ProjectExplorer::Icons::ANALYZER_START_SMALL.icon());
|
2016-03-02 12:05:30 +01:00
|
|
|
connect(action, &QAction::triggered, this,
|
|
|
|
|
&CallgrindTool::handleShowCostsOfFunction);
|
|
|
|
|
Command *cmd = ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction",
|
|
|
|
|
analyzerContext);
|
|
|
|
|
editorContextMenu->addAction(cmd);
|
|
|
|
|
cmd->setAttribute(Command::CA_Hide);
|
|
|
|
|
cmd->setAttribute(Command::CA_NonConfigurable);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
QSettings *coreSettings = ICore::settings();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// DockWidgets
|
|
|
|
|
//
|
2018-08-02 10:21:05 +02:00
|
|
|
m_visualization = new Visualization;
|
2016-03-02 13:57:37 +01:00
|
|
|
m_visualization->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
m_visualization->setObjectName(QLatin1String("Valgrind.CallgrindTool.Visualisation"));
|
|
|
|
|
m_visualization->setWindowTitle(tr("Visualization"));
|
|
|
|
|
m_visualization->setModel(&m_dataModel);
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(m_visualization, &Visualization::functionActivated,
|
2016-03-02 13:57:37 +01:00
|
|
|
this, &CallgrindTool::visualisationFunctionSelected);
|
|
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_callersView = new CostView;
|
2016-03-02 13:57:37 +01:00
|
|
|
m_callersView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CallersView"));
|
|
|
|
|
m_callersView->setWindowTitle(tr("Callers"));
|
|
|
|
|
m_callersView->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView");
|
|
|
|
|
m_callersView->sortByColumn(CallModel::CostColumn);
|
|
|
|
|
m_callersView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
// enable sorting
|
|
|
|
|
m_callersProxy.setSourceModel(&m_callersModel);
|
|
|
|
|
m_callersView->setModel(&m_callersProxy);
|
|
|
|
|
m_callersView->hideColumn(CallModel::CalleeColumn);
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(m_callersView, &QAbstractItemView::activated,
|
2016-03-02 13:57:37 +01:00
|
|
|
this, &CallgrindTool::callerFunctionSelected);
|
|
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_calleesView = new CostView;
|
2016-03-02 13:57:37 +01:00
|
|
|
m_calleesView->setObjectName(QLatin1String("Valgrind.CallgrindTool.CalleesView"));
|
|
|
|
|
m_calleesView->setWindowTitle(tr("Callees"));
|
|
|
|
|
m_calleesView->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView");
|
|
|
|
|
m_calleesView->sortByColumn(CallModel::CostColumn);
|
|
|
|
|
m_calleesView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
// enable sorting
|
|
|
|
|
m_calleesProxy.setSourceModel(&m_calleesModel);
|
|
|
|
|
m_calleesView->setModel(&m_calleesProxy);
|
|
|
|
|
m_calleesView->hideColumn(CallModel::CallerColumn);
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(m_calleesView, &QAbstractItemView::activated,
|
2016-03-02 13:57:37 +01:00
|
|
|
this, &CallgrindTool::calleeFunctionSelected);
|
|
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_flatView = new CostView;
|
2016-03-02 13:57:37 +01:00
|
|
|
m_flatView->setObjectName(QLatin1String("Valgrind.CallgrindTool.FlatView"));
|
|
|
|
|
m_flatView->setWindowTitle(tr("Functions"));
|
|
|
|
|
m_flatView->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView");
|
|
|
|
|
m_flatView->sortByColumn(DataModel::SelfCostColumn);
|
|
|
|
|
m_flatView->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
m_flatView->setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
m_flatView->setModel(&m_proxyModel);
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(m_flatView, &QAbstractItemView::activated,
|
2016-03-02 13:57:37 +01:00
|
|
|
this, &CallgrindTool::dataFunctionSelected);
|
|
|
|
|
|
|
|
|
|
updateCostFormat();
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Control Widget
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
// load external log file
|
2017-04-12 10:06:41 +02:00
|
|
|
action = m_loadExternalLogFile = new QAction(this);
|
2018-02-12 11:40:14 +01:00
|
|
|
action->setIcon(Utils::Icons::OPENFILE_TOOLBAR.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setToolTip(tr("Load External Log File"));
|
|
|
|
|
connect(action, &QAction::triggered, this, &CallgrindTool::loadExternalLogFile);
|
|
|
|
|
|
|
|
|
|
// dump action
|
|
|
|
|
m_dumpAction = action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
2016-08-03 17:55:54 +02:00
|
|
|
action->setIcon(Utils::Icons::REDO.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
//action->setText(tr("Dump"));
|
|
|
|
|
action->setToolTip(tr("Request the dumping of profile information. This will update the Callgrind visualization."));
|
|
|
|
|
connect(action, &QAction::triggered, this, &CallgrindTool::slotRequestDump);
|
|
|
|
|
|
|
|
|
|
// reset action
|
|
|
|
|
m_resetAction = action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
2016-08-03 17:55:54 +02:00
|
|
|
action->setIcon(Utils::Icons::RELOAD.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
//action->setText(tr("Reset"));
|
|
|
|
|
action->setToolTip(tr("Reset all event counters."));
|
|
|
|
|
connect(action, &QAction::triggered, this, &CallgrindTool::resetRequested);
|
|
|
|
|
|
|
|
|
|
// pause action
|
|
|
|
|
m_pauseAction = action = new QAction(this);
|
|
|
|
|
action->setCheckable(true);
|
2016-08-03 17:55:54 +02:00
|
|
|
action->setIcon(Utils::Icons::INTERRUPT_SMALL_TOOLBAR.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
//action->setText(tr("Ignore"));
|
|
|
|
|
action->setToolTip(tr("Pause event logging. No events are counted which will speed up program execution during profiling."));
|
|
|
|
|
connect(action, &QAction::toggled, this, &CallgrindTool::pauseToggled);
|
|
|
|
|
|
2018-05-15 08:58:01 +02:00
|
|
|
// discard data action
|
|
|
|
|
m_discardAction = action = new QAction(this);
|
|
|
|
|
action->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon());
|
|
|
|
|
action->setToolTip(tr("Discard Data"));
|
|
|
|
|
connect(action, &QAction::triggered, this, [this](bool) {
|
|
|
|
|
clearTextMarks();
|
|
|
|
|
doClear(true);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
// navigation
|
|
|
|
|
// go back
|
|
|
|
|
m_goBack = action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
2016-05-23 14:15:06 +02:00
|
|
|
action->setIcon(Utils::Icons::PREV_TOOLBAR.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setToolTip(tr("Go back one step in history. This will select the previously selected item."));
|
|
|
|
|
connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goBack);
|
|
|
|
|
|
|
|
|
|
// go forward
|
|
|
|
|
m_goNext = action = new QAction(this);
|
|
|
|
|
action->setDisabled(true);
|
2016-05-23 14:15:06 +02:00
|
|
|
action->setIcon(Utils::Icons::NEXT_TOOLBAR.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setToolTip(tr("Go forward one step in history."));
|
|
|
|
|
connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goNext);
|
|
|
|
|
|
|
|
|
|
// event selection
|
|
|
|
|
m_eventCombo = new QComboBox;
|
|
|
|
|
m_eventCombo->setToolTip(tr("Selects which events from the profiling data are shown and visualized."));
|
|
|
|
|
connect(m_eventCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &CallgrindTool::setCostEvent);
|
|
|
|
|
updateEventCombo();
|
|
|
|
|
|
2018-08-13 09:34:47 +02:00
|
|
|
auto perspective = new Perspective(CallgrindPerspectiveId, tr("Callgrind"));
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
perspective->addToolBarAction(m_startAction);
|
|
|
|
|
perspective->addToolBarAction(m_stopAction);
|
|
|
|
|
perspective->addToolBarAction(m_loadExternalLogFile);
|
|
|
|
|
perspective->addToolBarAction(m_dumpAction);
|
|
|
|
|
perspective->addToolBarAction(m_resetAction);
|
|
|
|
|
perspective->addToolBarAction(m_pauseAction);
|
|
|
|
|
perspective->addToolBarAction(m_discardAction);
|
|
|
|
|
perspective->addToolBarAction(m_goBack);
|
|
|
|
|
perspective->addToolBarAction(m_goNext);
|
2018-08-01 17:33:41 +02:00
|
|
|
perspective->addToolbarSeparator();
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
perspective->addToolBarWidget(m_eventCombo);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
// Cost formatting
|
|
|
|
|
{
|
|
|
|
|
auto 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);
|
|
|
|
|
connect(m_costAbsolute, &QAction::toggled, this, &CallgrindTool::updateCostFormat);
|
|
|
|
|
group->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);
|
|
|
|
|
connect(m_costRelative, &QAction::toggled, this, &CallgrindTool::updateCostFormat);
|
|
|
|
|
group->addAction(m_costRelative);
|
|
|
|
|
|
|
|
|
|
// Show costs relative to parent
|
|
|
|
|
m_costRelativeToParent = new QAction(tr("Relative Costs to Parent"), this);
|
2016-04-05 15:11:30 +02:00
|
|
|
m_costRelativeToParent->setToolTip(tr("Show costs relative to parent function's inclusive cost."));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_costRelativeToParent->setCheckable(true);
|
|
|
|
|
connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindTool::updateCostFormat);
|
|
|
|
|
group->addAction(m_costRelativeToParent);
|
|
|
|
|
|
|
|
|
|
auto button = new QToolButton;
|
2016-03-31 13:32:08 +02:00
|
|
|
button->addActions(group->actions());
|
2016-03-02 13:57:37 +01:00
|
|
|
button->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
button->setText(QLatin1String("$"));
|
|
|
|
|
button->setToolTip(tr("Cost Format"));
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
perspective->addToolBarWidget(button);
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings();
|
|
|
|
|
|
|
|
|
|
// Cycle detection
|
|
|
|
|
//action = new QAction(QLatin1String("Cycle Detection"), this); ///FIXME: icon
|
|
|
|
|
action = m_cycleDetection = new QAction(QLatin1String("O"), this); ///FIXME: icon
|
|
|
|
|
action->setToolTip(tr("Enable cycle detection to properly handle recursive or circular function calls."));
|
|
|
|
|
action->setCheckable(true);
|
|
|
|
|
connect(action, &QAction::toggled, &m_dataModel, &DataModel::enableCycleDetection);
|
|
|
|
|
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setDetectCycles);
|
|
|
|
|
|
|
|
|
|
// Shorter template signature
|
|
|
|
|
action = m_shortenTemplates = new QAction(QLatin1String("<>"), this);
|
2016-04-05 15:11:30 +02:00
|
|
|
action->setToolTip(tr("Remove template parameter lists when displaying function names."));
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
|
connect(action, &QAction::toggled, &m_dataModel, &DataModel::setShortenTemplates);
|
|
|
|
|
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setShortenTemplates);
|
|
|
|
|
|
|
|
|
|
// Filtering
|
|
|
|
|
action = m_filterProjectCosts = new QAction(tr("Show Project Costs Only"), this);
|
2016-08-03 17:55:54 +02:00
|
|
|
action->setIcon(Utils::Icons::FILTER.icon());
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setToolTip(tr("Show only profiling info that originated from this project source."));
|
|
|
|
|
action->setCheckable(true);
|
|
|
|
|
connect(action, &QAction::toggled, this, &CallgrindTool::handleFilterProjectCosts);
|
|
|
|
|
|
|
|
|
|
// Filter
|
|
|
|
|
///FIXME: find workaround for https://bugreports.qt.io/browse/QTCREATORBUG-3247
|
|
|
|
|
m_searchFilter = new QLineEdit;
|
|
|
|
|
m_searchFilter->setPlaceholderText(tr("Filter..."));
|
|
|
|
|
connect(m_searchFilter, &QLineEdit::textChanged,
|
|
|
|
|
&m_updateTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
|
|
|
|
|
|
|
|
|
|
setCostFormat(settings->costFormat());
|
|
|
|
|
enableCycleDetection(settings->detectCycles());
|
|
|
|
|
|
Debugger: Make most views per-engine instead of singletons
This is a step towards properly supporting multiple debugger
sessions side-by-side.
The combined C++-and-QML engine has been removed, instead a
combined setup creates now two individual engines, under a single
DebuggerRunTool but mostly independent with no combined state
machine. This requires a few more clicks in some cases, but
makes it easier to direct e.g. interrupt requests to the
interesting engine.
Care has been taken to not change the UX of the single debugger
session use case if possible. The fat debug button operates
as-before in that case, i.e. switches to Interrupt if the
single active runconfiguration runs in the debugger etc.
Most views are made per-engine, running an engine creates
a new Perspective, which is destroyed when the run control dies.
The snapshot view remains global and becomes primary source
of information on a "current engine" that receives all menu
and otherwise global input.
There is a new global "Breakpoint Preset" view containing
all "static" breakpoint data. When an engine starts up it
"claims" breakpoint it believes it can handle, but operates
on a copy of the static data. The markers of the static
version are suppressed as long as an engine controls a
breakpoint (that inclusive all resolved locations), but are
re-instatet once the engine quits.
The old Breakpoint class that already contained this split
per-instance was split into a new Breakpoint and a
GlobalBreakpoint class, with a per-engine model for Breakpoints,
and a singleton model containing GlobalBreakpoints.
There is a new CppDebuggerEngine intermediate level serving as
base for C++ (or, rather, "compiled") binary debugging, i.e.
{Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine
base that are not applicable to non-binary debuggers.
Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
|
|
|
perspective->addToolBarAction(m_cycleDetection);
|
|
|
|
|
perspective->addToolBarAction(m_shortenTemplates);
|
|
|
|
|
perspective->addToolBarAction(m_filterProjectCosts);
|
|
|
|
|
perspective->addToolBarWidget(m_searchFilter);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
perspective->addWindow(m_flatView, Perspective::SplitVertical, nullptr);
|
|
|
|
|
perspective->addWindow(m_calleesView, Perspective::SplitVertical, nullptr);
|
|
|
|
|
perspective->addWindow(m_callersView, Perspective::SplitHorizontal, m_calleesView);
|
|
|
|
|
perspective->addWindow(m_visualization, Perspective::SplitVertical, nullptr,
|
2018-07-31 16:13:11 +02:00
|
|
|
false, Qt::RightDockWidgetArea);
|
2018-08-13 09:34:47 +02:00
|
|
|
Debugger::registerPerspective(perspective);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
|
|
|
|
|
this, &CallgrindTool::updateRunActions);
|
2016-03-02 12:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallgrindTool::~CallgrindTool()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
qDeleteAll(m_textMarks);
|
2018-08-02 10:21:05 +02:00
|
|
|
delete m_flatView;
|
|
|
|
|
delete m_callersView;
|
|
|
|
|
delete m_calleesView;
|
|
|
|
|
delete m_visualization;
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::doClear(bool clearParseData)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
if (clearParseData) // Crashed when done from destructor.
|
2018-03-15 21:48:44 +02:00
|
|
|
setParseData(nullptr);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
// clear filters
|
|
|
|
|
if (m_filterProjectCosts)
|
|
|
|
|
m_filterProjectCosts->setChecked(false);
|
2016-03-02 12:05:30 +01:00
|
|
|
m_proxyModel.setFilterBaseDir(QString());
|
2011-05-23 13:50:28 +02:00
|
|
|
if (m_searchFilter)
|
2014-07-23 09:53:06 +02:00
|
|
|
m_searchFilter->clear();
|
2016-03-02 12:05:30 +01:00
|
|
|
m_proxyModel.setFilterFixedString(QString());
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::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);
|
2016-03-02 12:05:30 +01:00
|
|
|
m_visualization->setCursor(cursor);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::selectFunction(const Function *func)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
if (!func) {
|
|
|
|
|
m_flatView->clearSelection();
|
2018-03-15 21:48:44 +02:00
|
|
|
m_visualization->setFunction(nullptr);
|
2016-03-02 12:05:30 +01:00
|
|
|
m_callersModel.clear();
|
|
|
|
|
m_calleesModel.clear();
|
2011-05-23 13:50:28 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
const QModelIndex index = m_dataModel.indexForObject(func);
|
|
|
|
|
const QModelIndex proxyIndex = m_proxyModel.mapFromSource(index);
|
2011-05-23 13:50:28 +02:00
|
|
|
m_flatView->selectionModel()->clearSelection();
|
|
|
|
|
m_flatView->selectionModel()->setCurrentIndex(proxyIndex,
|
|
|
|
|
QItemSelectionModel::ClearAndSelect |
|
|
|
|
|
QItemSelectionModel::Rows);
|
|
|
|
|
m_flatView->scrollTo(proxyIndex);
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
m_callersModel.setCalls(func->incomingCalls(), func);
|
|
|
|
|
m_calleesModel.setCalls(func->outgoingCalls(), func);
|
|
|
|
|
m_visualization->setFunction(func);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
const Function *item = m_stackBrowser.current();
|
2011-05-23 13:50:28 +02:00
|
|
|
if (!item || item != func)
|
2016-03-02 12:05:30 +01:00
|
|
|
m_stackBrowser.select(func);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::stackBrowserChanged()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2016-03-02 12:05:30 +01:00
|
|
|
m_goBack->setEnabled(m_stackBrowser.hasPrevious());
|
|
|
|
|
m_goNext->setEnabled(m_stackBrowser.hasNext());
|
|
|
|
|
const Function *item = m_stackBrowser.current();
|
2011-05-23 13:50:28 +02:00
|
|
|
selectFunction(item);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::updateFilterString()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2016-03-02 12:05:30 +01:00
|
|
|
m_proxyModel.setFilterFixedString(m_searchFilter->text());
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::setCostFormat(CostDelegate::CostFormat format)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::setCostEvent(int index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
// prevent assert in model, don't try to set event to -1
|
|
|
|
|
// happens when we clear the eventcombo
|
|
|
|
|
if (index == -1)
|
|
|
|
|
index = 0;
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
m_dataModel.setCostEvent(index);
|
|
|
|
|
m_calleesModel.setCostEvent(index);
|
|
|
|
|
m_callersModel.setCostEvent(index);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::enableCycleDetection(bool enabled)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
m_cycleDetection->setChecked(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::shortenTemplates(bool enabled)
|
2012-08-22 23:35:02 +02:00
|
|
|
{
|
|
|
|
|
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).
|
2016-03-02 12:05:30 +01:00
|
|
|
CostDelegate::CostFormat CallgrindTool::costFormat() const
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
if (m_costRelativeToParent && m_costRelativeToParent->isChecked())
|
|
|
|
|
return CostDelegate::FormatRelativeToParent;
|
|
|
|
|
if (m_costRelative && m_costRelative->isChecked())
|
|
|
|
|
return CostDelegate::FormatRelative;
|
|
|
|
|
return CostDelegate::FormatAbsolute;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::updateCostFormat()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::handleFilterProjectCosts()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2015-02-03 23:56:02 +02:00
|
|
|
Project *pro = ProjectTree::currentProject();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-02-29 13:37:35 +01:00
|
|
|
if (pro && m_filterProjectCosts->isChecked()) {
|
2014-05-02 12:53:36 +02:00
|
|
|
const QString projectDir = pro->projectDirectory().toString();
|
2016-03-02 12:05:30 +01:00
|
|
|
m_proxyModel.setFilterBaseDir(projectDir);
|
2013-07-17 00:01:45 +03:00
|
|
|
} else {
|
2016-03-02 12:05:30 +01:00
|
|
|
m_proxyModel.setFilterBaseDir(QString());
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::dataFunctionSelected(const QModelIndex &index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
const Function *func = index.data(DataModel::FunctionRole).value<const Function *>();
|
|
|
|
|
QTC_ASSERT(func, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(func);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::calleeFunctionSelected(const QModelIndex &index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
const FunctionCall *call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
|
|
|
|
|
QTC_ASSERT(call, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(call->callee());
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::callerFunctionSelected(const QModelIndex &index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
const FunctionCall *call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
|
|
|
|
|
QTC_ASSERT(call, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(call->caller());
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::visualisationFunctionSelected(const Function *function)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2016-03-02 12:05:30 +01:00
|
|
|
if (function && function == m_visualization->function())
|
2011-05-23 13:50:28 +02:00
|
|
|
// up-navigation when the initial function was activated
|
2016-03-02 12:05:30 +01:00
|
|
|
m_stackBrowser.goBack();
|
2011-05-23 13:50:28 +02:00
|
|
|
else
|
|
|
|
|
selectFunction(function);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::setParseData(ParseData *data)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
// we have new parse data, invalidate filters in the proxy model
|
2018-03-15 21:48:44 +02:00
|
|
|
m_visualization->setFunction(nullptr);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
// invalidate parse data in the data model
|
2016-03-02 12:05:30 +01:00
|
|
|
delete m_dataModel.parseData();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
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;
|
2018-03-15 21:48:44 +02:00
|
|
|
data = nullptr;
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
2016-03-02 12:05:30 +01:00
|
|
|
m_dataModel.setParseData(data);
|
|
|
|
|
m_calleesModel.setParseData(data);
|
|
|
|
|
m_callersModel.setParseData(data);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
updateEventCombo();
|
|
|
|
|
|
|
|
|
|
// clear history for new data
|
2016-03-02 12:05:30 +01:00
|
|
|
m_stackBrowser.clear();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
// unset busy state
|
2011-12-13 14:01:52 +01:00
|
|
|
//setBusy(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::updateEventCombo()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(m_eventCombo, return);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
m_eventCombo->clear();
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
const ParseData *data = m_dataModel.parseData();
|
2011-05-23 13:50:28 +02:00
|
|
|
if (!data || data->events().isEmpty()) {
|
|
|
|
|
m_eventCombo->hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_eventCombo->show();
|
|
|
|
|
foreach (const QString &event, data->events())
|
|
|
|
|
m_eventCombo->addItem(ParseData::prettyStringForEvent(event));
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 13:54:07 +02:00
|
|
|
void CallgrindTool::setupRunner(CallgrindToolRunner *toolRunner)
|
2011-07-06 16:52:14 +02:00
|
|
|
{
|
2018-05-29 13:54:07 +02:00
|
|
|
RunControl *runControl = toolRunner->runControl();
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
connect(toolRunner, &CallgrindToolRunner::parserDataReady, this, &CallgrindTool::takeParserDataFromRunControl);
|
2017-07-11 17:25:33 +02:00
|
|
|
connect(runControl, &RunControl::stopped, this, &CallgrindTool::engineFinished);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
connect(this, &CallgrindTool::dumpRequested, toolRunner, &CallgrindToolRunner::dump);
|
|
|
|
|
connect(this, &CallgrindTool::resetRequested, toolRunner, &CallgrindToolRunner::reset);
|
|
|
|
|
connect(this, &CallgrindTool::pauseToggled, toolRunner, &CallgrindToolRunner::setPaused);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2017-06-26 18:40:11 +02:00
|
|
|
connect(m_stopAction, &QAction::triggered, toolRunner, [runControl] { runControl->initiateStop(); });
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2013-07-30 14:08:01 +02:00
|
|
|
// initialize run control
|
2017-04-27 17:23:28 +02:00
|
|
|
toolRunner->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
|
2017-04-27 17:23:28 +02:00
|
|
|
toolRunner->setToggleCollectFunction(m_toggleCollectFunction);
|
2011-07-06 16:52:14 +02:00
|
|
|
m_toggleCollectFunction.clear();
|
|
|
|
|
|
2018-05-29 13:54:07 +02:00
|
|
|
QTC_ASSERT(m_visualization, return);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2011-07-18 16:10:25 +02:00
|
|
|
// apply project settings
|
2017-04-27 17:23:28 +02:00
|
|
|
if (IRunConfigurationAspect *analyzerAspect = runControl->runConfiguration()->extraAspect(ANALYZER_VALGRIND_SETTINGS)) {
|
|
|
|
|
if (const ValgrindBaseSettings *settings = qobject_cast<ValgrindBaseSettings *>(analyzerAspect->currentSettings())) {
|
|
|
|
|
m_visualization->setMinimumInclusiveCostRatio(settings->visualisationMinimumInclusiveCostRatio() / 100.0);
|
|
|
|
|
m_proxyModel.setMinimumInclusiveCostRatio(settings->minimumInclusiveCostRatio() / 100.0);
|
|
|
|
|
m_dataModel.setVerboseToolTipsEnabled(settings->enableEventToolTips());
|
2011-07-18 16:10:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
m_toolBusy = true;
|
|
|
|
|
updateRunActions();
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2017-06-27 17:30:32 +02:00
|
|
|
// enable/disable actions
|
|
|
|
|
m_resetAction->setEnabled(true);
|
|
|
|
|
m_dumpAction->setEnabled(true);
|
|
|
|
|
m_loadExternalLogFile->setEnabled(false);
|
|
|
|
|
clearTextMarks();
|
|
|
|
|
doClear(true);
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
2011-05-23 13:50:28 +02:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
void CallgrindTool::updateRunActions()
|
|
|
|
|
{
|
|
|
|
|
if (m_toolBusy) {
|
|
|
|
|
m_startAction->setEnabled(false);
|
|
|
|
|
m_startAction->setToolTip(tr("A Valgrind Callgrind analysis is still in progress."));
|
|
|
|
|
m_stopAction->setEnabled(true);
|
|
|
|
|
} else {
|
2016-03-09 15:34:55 +01:00
|
|
|
QString whyNot = tr("Start a Valgrind Callgrind analysis.");
|
|
|
|
|
bool canRun = ProjectExplorerPlugin::canRunStartupProject(CALLGRIND_RUN_MODE, &whyNot);
|
|
|
|
|
m_startAction->setToolTip(whyNot);
|
|
|
|
|
m_startAction->setEnabled(canRun);
|
|
|
|
|
m_stopAction->setEnabled(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::clearTextMarks()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
qDeleteAll(m_textMarks);
|
|
|
|
|
m_textMarks.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::engineFinished()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2016-03-02 13:57:37 +01:00
|
|
|
m_toolBusy = false;
|
|
|
|
|
updateRunActions();
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
// Enable/disable actions
|
2011-05-23 13:50:28 +02:00
|
|
|
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
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
const ParseData *data = m_dataModel.parseData();
|
2011-05-23 13:50:28 +02:00
|
|
|
if (data)
|
|
|
|
|
showParserResults(data);
|
|
|
|
|
else
|
2016-03-02 13:57:37 +01:00
|
|
|
Debugger::showPermanentStatusMessage(tr("Profiling aborted."));
|
2011-12-13 14:01:52 +01:00
|
|
|
|
|
|
|
|
setBusyCursor(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::showParserResults(const ParseData *data)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
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.");
|
|
|
|
|
}
|
2016-03-02 13:57:37 +01:00
|
|
|
Debugger::showPermanentStatusMessage(msg);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::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,
|
2016-03-02 12:05:30 +01:00
|
|
|
this, &CallgrindTool::requestContextMenu);
|
2014-09-30 16:54:26 +02:00
|
|
|
}
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::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) {
|
2018-05-02 15:02:00 +02:00
|
|
|
if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) {
|
2015-02-18 17:31:43 +01:00
|
|
|
const Function *func = textMark->function();
|
2016-04-05 15:11:30 +02:00
|
|
|
QAction *action = menu->addAction(tr("Select This Function in the Analyzer Output"));
|
2015-02-18 17:31:43 +01:00
|
|
|
connect(action, &QAction::triggered, this, [this, func] { selectFunction(func); });
|
2011-05-23 13:50:28 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::handleShowCostsOfFunction()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
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("()");
|
2016-03-02 13:57:37 +01:00
|
|
|
m_startAction->trigger();
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::slotRequestDump()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2011-12-13 14:01:52 +01:00
|
|
|
//setBusy(true);
|
2016-03-02 12:05:30 +01:00
|
|
|
m_visualization->setText(tr("Populating..."));
|
2011-05-23 13:50:28 +02:00
|
|
|
dumpRequested();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::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)) {
|
2016-05-31 16:09:48 +02:00
|
|
|
QString msg = tr("Callgrind: Failed to open file for reading: %1").arg(filePath);
|
|
|
|
|
TaskHub::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID);
|
|
|
|
|
TaskHub::requestPopup();
|
2013-09-09 14:34:19 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
Debugger::showPermanentStatusMessage(tr("Parsing Profile Data..."));
|
2013-09-09 14:34:19 +02:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
|
|
Parser parser;
|
|
|
|
|
parser.parse(&logFile);
|
|
|
|
|
takeParserData(parser.takeData());
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindTool::takeParserDataFromRunControl(CallgrindToolRunner *rc)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2013-09-09 14:34:19 +02:00
|
|
|
takeParserData(rc->takeParserData());
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::takeParserData(ParseData *data)
|
2013-09-09 14:34:19 +02:00
|
|
|
{
|
2011-05-23 13:50:28 +02:00
|
|
|
showParserResults(data);
|
|
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// clear first
|
|
|
|
|
clearTextMarks();
|
2017-06-27 17:30:32 +02:00
|
|
|
doClear(true);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
setParseData(data);
|
|
|
|
|
createTextMarks();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
void CallgrindTool::createTextMarks()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
QList<QString> locations;
|
2016-03-02 12:05:30 +01:00
|
|
|
for (int row = 0; row < m_dataModel.rowCount(); ++row) {
|
|
|
|
|
const QModelIndex index = m_dataModel.index(row, DataModel::InclusiveCostColumn);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
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);
|
2016-04-14 15:39:56 +02:00
|
|
|
// avoid creating invalid text marks
|
|
|
|
|
if (lineNumber <= 0)
|
|
|
|
|
continue;
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
2018-05-02 15:02:00 +02:00
|
|
|
m_textMarks.append(new CallgrindTextMark(index, FileName::fromString(fileName), lineNumber));
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
|
2017-07-03 13:55:25 +02:00
|
|
|
static CallgrindTool *theCallgrindTool;
|
2016-03-07 17:33:58 +01:00
|
|
|
|
2018-05-29 13:54:07 +02:00
|
|
|
void setupCallgrindRunner(CallgrindToolRunner *toolRunner)
|
|
|
|
|
{
|
|
|
|
|
theCallgrindTool->setupRunner(toolRunner);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 17:33:58 +01:00
|
|
|
void initCallgrindTool()
|
2016-03-02 12:05:30 +01:00
|
|
|
{
|
2017-07-03 13:55:25 +02:00
|
|
|
theCallgrindTool = new CallgrindTool;
|
|
|
|
|
|
2018-05-29 13:54:07 +02:00
|
|
|
RunControl::registerWorker<CallgrindToolRunner>(CALLGRIND_RUN_MODE, {});
|
2016-03-02 12:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroyCallgrindTool()
|
|
|
|
|
{
|
2017-07-03 13:55:25 +02:00
|
|
|
delete theCallgrindTool;
|
|
|
|
|
theCallgrindTool = nullptr;
|
2016-03-02 12:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Valgrind
|
|
|
|
|
|
|
|
|
|
#include "callgrindtool.moc"
|