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 CallgrindLocalActionId[] = "Callgrind.Local.Action";
|
|
|
|
|
const char CallgrindRemoteActionId[] = "Callgrind.Remote.Action";
|
|
|
|
|
const char CALLGRIND_RUN_MODE[] = "CallgrindTool.CallgrindRunMode";
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
class CallgrindToolPrivate : public QObject
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindToolPrivate();
|
|
|
|
|
~CallgrindToolPrivate() override;
|
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
|
|
|
|
2018-11-07 23:55:59 +02:00
|
|
|
QString m_lastFileName;
|
|
|
|
|
|
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;
|
2018-11-07 23:55:59 +02:00
|
|
|
QAction *m_startKCachegrind = nullptr;
|
2018-03-15 21:48:44 +02:00
|
|
|
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;
|
2018-08-21 12:30:00 +02:00
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
Perspective m_perspective{"Callgrind.Perspective", CallgrindTool::tr("Callgrind")};
|
2011-05-23 13:50:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindToolPrivate::CallgrindToolPrivate()
|
2016-03-02 12:05:30 +01:00
|
|
|
{
|
2018-12-01 20:56:21 +02:00
|
|
|
setObjectName("CallgrindTool");
|
2016-03-02 12:05:30 +01:00
|
|
|
|
|
|
|
|
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,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::stackBrowserChanged);
|
2016-03-02 12:05:30 +01:00
|
|
|
connect(&m_updateTimer, &QTimer::timeout,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::updateFilterString);
|
2016-03-02 12:05:30 +01:00
|
|
|
|
|
|
|
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::editorOpened);
|
2016-03-02 12:05:30 +01:00
|
|
|
|
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);
|
2019-03-20 17:49:26 +01:00
|
|
|
QString toolTip = CallgrindTool::tr("Valgrind Function Profiler uses the "
|
2017-04-12 10:06:41 +02:00
|
|
|
"Callgrind tool to record function calls when a program runs.");
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
if (!Utils::HostOsInfo::isWindowsHost()) {
|
2019-03-20 17:49:26 +01:00
|
|
|
auto action = new QAction(CallgrindTool::tr("Valgrind Function Profiler"), this);
|
2017-04-12 10:06:41 +02:00
|
|
|
action->setToolTip(toolTip);
|
|
|
|
|
menu->addAction(ActionManager::registerAction(action, CallgrindLocalActionId),
|
|
|
|
|
Debugger::Constants::G_ANALYZER_TOOLS);
|
2018-08-22 10:53:34 +02:00
|
|
|
QObject::connect(action, &QAction::triggered, this, [this, action] {
|
2017-04-12 10:06:41 +02:00
|
|
|
if (!Debugger::wantRunTool(OptimizedMode, action->text()))
|
|
|
|
|
return;
|
2018-08-22 10:53:34 +02:00
|
|
|
m_perspective.select();
|
2017-04-12 10:06:41 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
auto action = new QAction(CallgrindTool::tr("Valgrind Function Profiler (External Application)"), this);
|
2017-04-12 10:06:41 +02:00
|
|
|
action->setToolTip(toolTip);
|
|
|
|
|
menu->addAction(ActionManager::registerAction(action, CallgrindRemoteActionId),
|
|
|
|
|
Debugger::Constants::G_ANALYZER_REMOTE_TOOLS);
|
2018-08-22 10:53:34 +02:00
|
|
|
QObject::connect(action, &QAction::triggered, this, [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;
|
2018-08-22 10:53:34 +02:00
|
|
|
m_perspective.select();
|
2019-03-12 15:53:54 +01:00
|
|
|
auto runControl = new RunControl(CALLGRIND_RUN_MODE);
|
|
|
|
|
runControl->setRunConfiguration(runConfig);
|
2019-03-13 15:34:44 +01:00
|
|
|
runControl->createMainWorker();
|
2016-03-02 12:05:30 +01:00
|
|
|
const auto runnable = dlg.runnable();
|
2017-04-27 17:23:28 +02:00
|
|
|
runControl->setRunnable(runnable);
|
2019-06-20 17:19:12 +02:00
|
|
|
runControl->setDisplayName(runnable.executable.toUserOutput());
|
2017-04-27 17:23:28 +02:00
|
|
|
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);
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
auto action = new QAction(CallgrindTool::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,
|
2019-03-20 17:49:26 +01:00
|
|
|
&CallgrindToolPrivate::handleShowCostsOfFunction);
|
2016-03-02 12:05:30 +01:00
|
|
|
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);
|
2018-12-01 20:56:21 +02:00
|
|
|
m_visualization->setObjectName("Valgrind.CallgrindTool.Visualisation");
|
2019-03-20 17:49:26 +01:00
|
|
|
m_visualization->setWindowTitle(CallgrindTool::tr("Visualization"));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_visualization->setModel(&m_dataModel);
|
2018-08-02 10:21:05 +02:00
|
|
|
connect(m_visualization, &Visualization::functionActivated,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::visualisationFunctionSelected);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_callersView = new CostView;
|
2018-12-01 20:56:21 +02:00
|
|
|
m_callersView->setObjectName("Valgrind.CallgrindTool.CallersView");
|
2019-03-20 17:49:26 +01:00
|
|
|
m_callersView->setWindowTitle(CallgrindTool::tr("Callers"));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_callersView->setSettings(coreSettings, "Valgrind.CallgrindTool.CallersView");
|
2019-02-26 17:48:18 +01:00
|
|
|
m_callersView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder);
|
2016-03-02 13:57:37 +01:00
|
|
|
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,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::callerFunctionSelected);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_calleesView = new CostView;
|
2018-12-01 20:56:21 +02:00
|
|
|
m_calleesView->setObjectName("Valgrind.CallgrindTool.CalleesView");
|
2019-03-20 17:49:26 +01:00
|
|
|
m_calleesView->setWindowTitle(CallgrindTool::tr("Callees"));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_calleesView->setSettings(coreSettings, "Valgrind.CallgrindTool.CalleesView");
|
2019-02-26 17:48:18 +01:00
|
|
|
m_calleesView->sortByColumn(CallModel::CostColumn, Qt::DescendingOrder);
|
2016-03-02 13:57:37 +01:00
|
|
|
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,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::calleeFunctionSelected);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-02 10:21:05 +02:00
|
|
|
m_flatView = new CostView;
|
2018-12-01 20:56:21 +02:00
|
|
|
m_flatView->setObjectName("Valgrind.CallgrindTool.FlatView");
|
2019-03-20 17:49:26 +01:00
|
|
|
m_flatView->setWindowTitle(CallgrindTool::tr("Functions"));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_flatView->setSettings(coreSettings, "Valgrind.CallgrindTool.FlatView");
|
2019-02-26 17:48:18 +01:00
|
|
|
m_flatView->sortByColumn(DataModel::SelfCostColumn, Qt::DescendingOrder);
|
2016-03-02 13:57:37 +01:00
|
|
|
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,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::dataFunctionSelected);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
updateCostFormat();
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance();
|
2018-11-07 23:55:59 +02:00
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
//
|
|
|
|
|
// 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());
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Load External Log File"));
|
|
|
|
|
connect(action, &QAction::triggered, this, &CallgrindToolPrivate::loadExternalLogFile);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-11-07 23:55:59 +02:00
|
|
|
action = m_startKCachegrind = new QAction(this);
|
|
|
|
|
action->setEnabled(false);
|
|
|
|
|
const Utils::Icon kCachegrindIcon({{":/valgrind/images/kcachegrind.png",
|
|
|
|
|
Theme::IconsBaseColor}});
|
|
|
|
|
action->setIcon(kCachegrindIcon.icon());
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Open results in KCachegrind."));
|
2018-11-07 23:55:59 +02:00
|
|
|
connect(action, &QAction::triggered, this, [this, settings] {
|
|
|
|
|
QProcess::startDetached(settings->kcachegrindExecutable(), { m_lastFileName });
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
// 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());
|
2019-03-20 17:49:26 +01:00
|
|
|
//action->setText(CallgrindTool::tr("Dump"));
|
|
|
|
|
action->setToolTip(CallgrindTool::tr("Request the dumping of profile information. This will update the Callgrind visualization."));
|
|
|
|
|
connect(action, &QAction::triggered, this, &CallgrindToolPrivate::slotRequestDump);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
// 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());
|
2019-03-20 17:49:26 +01:00
|
|
|
//action->setText(CallgrindTool::tr("Reset"));
|
|
|
|
|
action->setToolTip(CallgrindTool::tr("Reset all event counters."));
|
|
|
|
|
connect(action, &QAction::triggered, this, &CallgrindToolPrivate::resetRequested);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
// 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());
|
2019-03-20 17:49:26 +01:00
|
|
|
//action->setText(CallgrindTool::tr("Ignore"));
|
|
|
|
|
action->setToolTip(CallgrindTool::tr("Pause event logging. No events are counted which will speed up program execution during profiling."));
|
|
|
|
|
connect(action, &QAction::toggled, this, &CallgrindToolPrivate::pauseToggled);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-05-15 08:58:01 +02:00
|
|
|
// discard data action
|
|
|
|
|
m_discardAction = action = new QAction(this);
|
|
|
|
|
action->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon());
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Discard Data"));
|
2018-05-15 08:58:01 +02:00
|
|
|
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());
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Go back one step in history. This will select the previously selected item."));
|
2016-03-02 13:57:37 +01:00
|
|
|
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());
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Go forward one step in history."));
|
2016-03-02 13:57:37 +01:00
|
|
|
connect(action, &QAction::triggered, &m_stackBrowser, &StackBrowser::goNext);
|
|
|
|
|
|
|
|
|
|
// event selection
|
|
|
|
|
m_eventCombo = new QComboBox;
|
2019-03-20 17:49:26 +01:00
|
|
|
m_eventCombo->setToolTip(CallgrindTool::tr("Selects which events from the profiling data are shown and visualized."));
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(m_eventCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::setCostEvent);
|
2016-03-02 13:57:37 +01:00
|
|
|
updateEventCombo();
|
|
|
|
|
|
2018-08-21 12:30:00 +02:00
|
|
|
m_perspective.addToolBarAction(m_startAction);
|
|
|
|
|
m_perspective.addToolBarAction(m_stopAction);
|
|
|
|
|
m_perspective.addToolBarAction(m_loadExternalLogFile);
|
2018-11-07 23:55:59 +02:00
|
|
|
m_perspective.addToolBarAction(m_startKCachegrind);
|
2018-08-21 12:30:00 +02:00
|
|
|
m_perspective.addToolBarAction(m_dumpAction);
|
|
|
|
|
m_perspective.addToolBarAction(m_resetAction);
|
|
|
|
|
m_perspective.addToolBarAction(m_pauseAction);
|
|
|
|
|
m_perspective.addToolBarAction(m_discardAction);
|
|
|
|
|
m_perspective.addToolBarAction(m_goBack);
|
|
|
|
|
m_perspective.addToolBarAction(m_goNext);
|
|
|
|
|
m_perspective.addToolbarSeparator();
|
|
|
|
|
m_perspective.addToolBarWidget(m_eventCombo);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
// Cost formatting
|
|
|
|
|
{
|
|
|
|
|
auto group = new QActionGroup(this);
|
|
|
|
|
|
|
|
|
|
// Show costs as absolute numbers
|
2019-03-20 17:49:26 +01:00
|
|
|
m_costAbsolute = new QAction(CallgrindTool::tr("Absolute Costs"), this);
|
|
|
|
|
m_costAbsolute->setToolTip(CallgrindTool::tr("Show costs as absolute numbers."));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_costAbsolute->setCheckable(true);
|
|
|
|
|
m_costAbsolute->setChecked(true);
|
2019-03-20 17:49:26 +01:00
|
|
|
connect(m_costAbsolute, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
|
2016-03-02 13:57:37 +01:00
|
|
|
group->addAction(m_costAbsolute);
|
|
|
|
|
|
|
|
|
|
// Show costs in percentages
|
2019-03-20 17:49:26 +01:00
|
|
|
m_costRelative = new QAction(CallgrindTool::tr("Relative Costs"), this);
|
|
|
|
|
m_costRelative->setToolTip(CallgrindTool::tr("Show costs relative to total inclusive cost."));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_costRelative->setCheckable(true);
|
2019-03-20 17:49:26 +01:00
|
|
|
connect(m_costRelative, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
|
2016-03-02 13:57:37 +01:00
|
|
|
group->addAction(m_costRelative);
|
|
|
|
|
|
|
|
|
|
// Show costs relative to parent
|
2019-03-20 17:49:26 +01:00
|
|
|
m_costRelativeToParent = new QAction(CallgrindTool::tr("Relative Costs to Parent"), this);
|
|
|
|
|
m_costRelativeToParent->setToolTip(CallgrindTool::tr("Show costs relative to parent function's inclusive cost."));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_costRelativeToParent->setCheckable(true);
|
2019-03-20 17:49:26 +01:00
|
|
|
connect(m_costRelativeToParent, &QAction::toggled, this, &CallgrindToolPrivate::updateCostFormat);
|
2016-03-02 13:57:37 +01:00
|
|
|
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);
|
2018-12-01 20:56:21 +02:00
|
|
|
button->setText("$");
|
2019-03-20 17:49:26 +01:00
|
|
|
button->setToolTip(CallgrindTool::tr("Cost Format"));
|
2018-08-21 12:30:00 +02:00
|
|
|
m_perspective.addToolBarWidget(button);
|
2016-03-02 13:57:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cycle detection
|
2018-12-01 20:56:21 +02:00
|
|
|
//action = new QAction("Cycle Detection", this); ///FIXME: icon
|
|
|
|
|
action = m_cycleDetection = new QAction("O", this); ///FIXME: icon
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Enable cycle detection to properly handle recursive or circular function calls."));
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
|
connect(action, &QAction::toggled, &m_dataModel, &DataModel::enableCycleDetection);
|
|
|
|
|
connect(action, &QAction::toggled, settings, &ValgrindGlobalSettings::setDetectCycles);
|
|
|
|
|
|
|
|
|
|
// Shorter template signature
|
2018-12-01 20:56:21 +02:00
|
|
|
action = m_shortenTemplates = new QAction("<>", this);
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::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
|
2019-03-20 17:49:26 +01:00
|
|
|
action = m_filterProjectCosts = new QAction(CallgrindTool::tr("Show Project Costs Only"), this);
|
2016-08-03 17:55:54 +02:00
|
|
|
action->setIcon(Utils::Icons::FILTER.icon());
|
2019-03-20 17:49:26 +01:00
|
|
|
action->setToolTip(CallgrindTool::tr("Show only profiling info that originated from this project source."));
|
2016-03-02 13:57:37 +01:00
|
|
|
action->setCheckable(true);
|
2019-03-20 17:49:26 +01:00
|
|
|
connect(action, &QAction::toggled, this, &CallgrindToolPrivate::handleFilterProjectCosts);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
// Filter
|
|
|
|
|
///FIXME: find workaround for https://bugreports.qt.io/browse/QTCREATORBUG-3247
|
|
|
|
|
m_searchFilter = new QLineEdit;
|
2019-03-20 17:49:26 +01:00
|
|
|
m_searchFilter->setPlaceholderText(CallgrindTool::tr("Filter..."));
|
2016-03-02 13:57:37 +01:00
|
|
|
connect(m_searchFilter, &QLineEdit::textChanged,
|
2019-05-27 23:28:48 +02:00
|
|
|
&m_updateTimer, QOverload<>::of(&QTimer::start));
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
setCostFormat(settings->costFormat());
|
|
|
|
|
enableCycleDetection(settings->detectCycles());
|
|
|
|
|
|
2018-08-21 12:30:00 +02:00
|
|
|
m_perspective.addToolBarAction(m_cycleDetection);
|
|
|
|
|
m_perspective.addToolBarAction(m_shortenTemplates);
|
|
|
|
|
m_perspective.addToolBarAction(m_filterProjectCosts);
|
|
|
|
|
m_perspective.addToolBarWidget(m_searchFilter);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
2018-08-21 12:30:00 +02:00
|
|
|
m_perspective.addWindow(m_flatView, Perspective::SplitVertical, nullptr);
|
|
|
|
|
m_perspective.addWindow(m_calleesView, Perspective::SplitVertical, nullptr);
|
|
|
|
|
m_perspective.addWindow(m_callersView, Perspective::SplitHorizontal, m_calleesView);
|
|
|
|
|
m_perspective.addWindow(m_visualization, Perspective::SplitVertical, nullptr,
|
2018-07-31 16:13:11 +02:00
|
|
|
false, Qt::RightDockWidgetArea);
|
2016-03-02 13:57:37 +01:00
|
|
|
|
|
|
|
|
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::updateRunActions);
|
2016-03-02 12:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindToolPrivate::~CallgrindToolPrivate()
|
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
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +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);
|
2016-03-02 12:05:30 +01:00
|
|
|
m_visualization->setCursor(cursor);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::enableCycleDetection(bool enabled)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
m_cycleDetection->setChecked(enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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).
|
2019-03-20 17:49:26 +01:00
|
|
|
CostDelegate::CostFormat CallgrindToolPrivate::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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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);
|
|
|
|
|
}
|
2019-03-20 17:49:26 +01:00
|
|
|
if (ValgrindGlobalSettings *settings = ValgrindGlobalSettings::instance())
|
2013-08-05 18:00:36 +02:00
|
|
|
settings->setCostFormat(format);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::dataFunctionSelected(const QModelIndex &index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2018-12-10 08:11:18 +01:00
|
|
|
auto func = index.data(DataModel::FunctionRole).value<const Function *>();
|
2011-05-23 13:50:28 +02:00
|
|
|
QTC_ASSERT(func, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(func);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::calleeFunctionSelected(const QModelIndex &index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2018-12-10 08:11:18 +01:00
|
|
|
auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
|
2011-05-23 13:50:28 +02:00
|
|
|
QTC_ASSERT(call, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(call->callee());
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::callerFunctionSelected(const QModelIndex &index)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2018-12-10 08:11:18 +01:00
|
|
|
auto call = index.data(CallModel::FunctionCallRole).value<const FunctionCall *>();
|
2011-05-23 13:50:28 +02:00
|
|
|
QTC_ASSERT(call, return);
|
|
|
|
|
|
|
|
|
|
selectFunction(call->caller());
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
}
|
2018-11-07 23:55:59 +02:00
|
|
|
m_lastFileName = data ? data->fileName() : QString();
|
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
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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));
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
connect(toolRunner, &CallgrindToolRunner::parserDataReady, this, &CallgrindToolPrivate::takeParserDataFromRunControl);
|
|
|
|
|
connect(runControl, &RunControl::stopped, this, &CallgrindToolPrivate::engineFinished);
|
2011-07-06 16:52:14 +02:00
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
connect(this, &CallgrindToolPrivate::dumpRequested, toolRunner, &CallgrindToolRunner::dump);
|
|
|
|
|
connect(this, &CallgrindToolPrivate::resetRequested, toolRunner, &CallgrindToolRunner::reset);
|
|
|
|
|
connect(this, &CallgrindToolPrivate::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
|
2019-03-12 17:36:48 +01:00
|
|
|
auto settings
|
|
|
|
|
= qobject_cast<ValgrindBaseSettings *>(runControl->settings(ANALYZER_VALGRIND_SETTINGS));
|
|
|
|
|
if (settings) {
|
2018-09-13 15:48:16 +02:00
|
|
|
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
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::updateRunActions()
|
2016-03-02 13:57:37 +01:00
|
|
|
{
|
|
|
|
|
if (m_toolBusy) {
|
|
|
|
|
m_startAction->setEnabled(false);
|
2018-12-21 12:33:06 +02:00
|
|
|
m_startKCachegrind->setEnabled(false);
|
2019-03-20 17:49:26 +01:00
|
|
|
m_startAction->setToolTip(CallgrindTool::tr("A Valgrind Callgrind analysis is still in progress."));
|
2016-03-02 13:57:37 +01:00
|
|
|
m_stopAction->setEnabled(true);
|
|
|
|
|
} else {
|
2019-03-20 17:49:26 +01:00
|
|
|
QString whyNot = CallgrindTool::tr("Start a Valgrind Callgrind analysis.");
|
2016-03-09 15:34:55 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::clearTextMarks()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
|
|
|
|
qDeleteAll(m_textMarks);
|
|
|
|
|
m_textMarks.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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
|
2019-03-20 17:49:26 +01:00
|
|
|
Debugger::showPermanentStatusMessage(CallgrindTool::tr("Profiling aborted."));
|
2011-12-13 14:01:52 +01:00
|
|
|
|
|
|
|
|
setBusyCursor(false);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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()) {
|
2019-03-20 17:49:26 +01:00
|
|
|
msg = CallgrindTool::tr("Parsing finished, no data.");
|
2011-05-23 13:50:28 +02:00
|
|
|
} else {
|
2019-01-17 01:54:13 +01:00
|
|
|
const QString costStr = QString::fromLatin1("%1 %2")
|
|
|
|
|
.arg(QString::number(data->totalCost(0)), data->events().constFirst());
|
2019-03-20 17:49:26 +01:00
|
|
|
msg = CallgrindTool::tr("Parsing finished, total cost of %1 reported.").arg(costStr);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-03-20 17:49:26 +01:00
|
|
|
msg = CallgrindTool::tr("Parsing failed.");
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
2016-03-02 13:57:37 +01:00
|
|
|
Debugger::showPermanentStatusMessage(msg);
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01: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,
|
2019-03-20 17:49:26 +01:00
|
|
|
this, &CallgrindToolPrivate::requestContextMenu);
|
2014-09-30 16:54:26 +02:00
|
|
|
}
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01: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) {
|
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();
|
2019-03-20 17:49:26 +01:00
|
|
|
QAction *action = menu->addAction(CallgrindTool::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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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));
|
|
|
|
|
|
2018-12-01 20:56:21 +02:00
|
|
|
m_toggleCollectFunction = qualifiedFunctionName + "()";
|
2016-03-02 13:57:37 +01:00
|
|
|
m_startAction->trigger();
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::slotRequestDump()
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2011-12-13 14:01:52 +01:00
|
|
|
//setBusy(true);
|
2019-03-20 17:49:26 +01:00
|
|
|
m_visualization->setText(CallgrindTool::tr("Populating..."));
|
2019-01-16 18:06:21 +01:00
|
|
|
emit dumpRequested();
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01: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(),
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindTool::tr("Open Callgrind Log File"),
|
2013-09-29 14:41:37 +03:00
|
|
|
QString(),
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindTool::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)) {
|
2019-03-20 17:49:26 +01:00
|
|
|
QString msg = CallgrindTool::tr("Callgrind: Failed to open file for reading: %1").arg(filePath);
|
2016-05-31 16:09:48 +02:00
|
|
|
TaskHub::addTask(Task::Error, msg, Debugger::Constants::ANALYZERTASK_ID);
|
|
|
|
|
TaskHub::requestPopup();
|
2013-09-09 14:34:19 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
Debugger::showPermanentStatusMessage(CallgrindTool::tr("Parsing Profile Data..."));
|
2013-09-09 14:34:19 +02:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
|
|
Parser parser;
|
|
|
|
|
parser.parse(&logFile);
|
|
|
|
|
takeParserData(parser.takeData());
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::takeParserDataFromRunControl(CallgrindToolRunner *rc)
|
2011-05-23 13:50:28 +02:00
|
|
|
{
|
2013-09-09 14:34:19 +02:00
|
|
|
takeParserData(rc->takeParserData());
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::takeParserData(ParseData *data)
|
2013-09-09 14:34:19 +02:00
|
|
|
{
|
2011-05-23 13:50:28 +02:00
|
|
|
showParserResults(data);
|
|
|
|
|
|
2018-12-21 12:33:06 +02:00
|
|
|
if (!data)
|
2011-05-23 13:50:28 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// clear first
|
|
|
|
|
clearTextMarks();
|
2017-06-27 17:30:32 +02:00
|
|
|
doClear(true);
|
2011-05-23 13:50:28 +02:00
|
|
|
|
|
|
|
|
setParseData(data);
|
2019-03-20 17:49:26 +01:00
|
|
|
const QString kcachegrindExecutable = ValgrindGlobalSettings::instance()->kcachegrindExecutable();
|
2018-11-07 23:55:59 +02:00
|
|
|
const bool kcachegrindExists = !Utils::Environment::systemEnvironment().searchInPath(
|
|
|
|
|
kcachegrindExecutable).isEmpty();
|
|
|
|
|
m_startKCachegrind->setEnabled(kcachegrindExists && !m_lastFileName.isEmpty());
|
2011-05-23 13:50:28 +02:00
|
|
|
createTextMarks();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
void CallgrindToolPrivate::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();
|
2018-12-01 20:56:21 +02:00
|
|
|
if (fileName.isEmpty() || fileName == "???")
|
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;
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
m_textMarks.append(new CallgrindTextMark(index, FilePath::fromString(fileName), lineNumber));
|
2011-05-23 13:50:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-02 12:05:30 +01:00
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
// CallgrindTool
|
|
|
|
|
|
|
|
|
|
static CallgrindToolPrivate *dd = nullptr;
|
2016-03-07 17:33:58 +01:00
|
|
|
|
2018-05-29 13:54:07 +02:00
|
|
|
void setupCallgrindRunner(CallgrindToolRunner *toolRunner)
|
|
|
|
|
{
|
2019-03-20 17:49:26 +01:00
|
|
|
dd->setupRunner(toolRunner);
|
2018-05-29 13:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindTool::CallgrindTool()
|
2016-03-02 12:05:30 +01:00
|
|
|
{
|
2019-03-20 17:49:26 +01:00
|
|
|
dd = new CallgrindToolPrivate;
|
2018-05-29 13:54:07 +02:00
|
|
|
RunControl::registerWorker<CallgrindToolRunner>(CALLGRIND_RUN_MODE, {});
|
2016-03-02 12:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-20 17:49:26 +01:00
|
|
|
CallgrindTool::~CallgrindTool()
|
2016-03-02 12:05:30 +01:00
|
|
|
{
|
2019-03-20 17:49:26 +01:00
|
|
|
delete dd;
|
2016-03-02 12:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-23 13:50:28 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Valgrind
|
|
|
|
|
|
|
|
|
|
#include "callgrindtool.moc"
|