2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-04 14:39:29 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-04-04 14:39:29 +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-04-04 14:39:29 +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-04-04 14:39:29 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
#include "callgrindengine.h"
|
|
|
|
|
|
2015-07-01 12:31:27 +02:00
|
|
|
#include "callgrindtool.h"
|
2011-07-12 16:47:32 +02:00
|
|
|
#include "valgrindsettings.h"
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
#include <valgrind/callgrind/callgrindcontroller.h>
|
|
|
|
|
#include <valgrind/callgrind/callgrindparser.h>
|
|
|
|
|
|
2016-02-24 14:42:52 +01:00
|
|
|
#include <debugger/analyzer/analyzermanager.h>
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2016-03-02 13:57:37 +01:00
|
|
|
using namespace Debugger;
|
2011-05-23 13:50:28 +02:00
|
|
|
using namespace Valgrind;
|
|
|
|
|
using namespace Valgrind::Internal;
|
2017-06-20 18:01:25 +02:00
|
|
|
using namespace Valgrind::Callgrind;
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
CallgrindToolRunner::CallgrindToolRunner(ProjectExplorer::RunControl *runControl)
|
|
|
|
|
: ValgrindToolRunner(runControl)
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2017-05-16 07:53:03 +02:00
|
|
|
setDisplayName("CallgrindToolRunner");
|
2017-06-20 18:01:25 +02:00
|
|
|
m_runner.setToolName("callgrind");
|
|
|
|
|
|
|
|
|
|
connect(&m_runner, &ValgrindRunner::finished,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &CallgrindToolRunner::slotFinished);
|
2017-06-20 18:01:25 +02:00
|
|
|
connect(&m_parser, &Callgrind::Parser::parserDataReady,
|
2017-04-27 17:23:28 +02:00
|
|
|
this, &CallgrindToolRunner::slotFinished);
|
2017-06-20 18:01:25 +02:00
|
|
|
|
|
|
|
|
connect(&m_controller, &CallgrindController::finished,
|
|
|
|
|
this, &CallgrindToolRunner::controllerFinished);
|
|
|
|
|
connect(&m_controller, &CallgrindController::localParseDataAvailable,
|
|
|
|
|
this, &CallgrindToolRunner::localParseDataAvailable);
|
|
|
|
|
connect(&m_controller, &CallgrindController::statusMessage,
|
|
|
|
|
this, &CallgrindToolRunner::showStatusMessage);
|
|
|
|
|
|
|
|
|
|
connect(&m_runner, &ValgrindRunner::extraStart, this, [this] {
|
|
|
|
|
m_controller.setValgrindProcess(m_runner.valgrindProcess());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&m_runner, &ValgrindRunner::extraProcessFinished, this, [this] {
|
|
|
|
|
triggerParse();
|
|
|
|
|
m_controller.setValgrindProcess(nullptr);
|
|
|
|
|
});
|
2011-06-30 13:44:22 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
QStringList CallgrindToolRunner::toolArguments() const
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
QStringList arguments;
|
|
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
QTC_ASSERT(m_settings, return arguments);
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
if (m_settings->enableCacheSim())
|
2012-11-26 15:02:17 +02:00
|
|
|
arguments << QLatin1String("--cache-sim=yes");
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
if (m_settings->enableBranchSim())
|
2012-11-26 15:02:17 +02:00
|
|
|
arguments << QLatin1String("--branch-sim=yes");
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
if (m_settings->collectBusEvents())
|
2012-11-26 15:02:17 +02:00
|
|
|
arguments << QLatin1String("--collect-bus=yes");
|
2011-04-04 14:39:29 +02:00
|
|
|
|
2013-08-08 17:37:37 +02:00
|
|
|
if (m_settings->collectSystime())
|
2012-11-26 15:02:17 +02:00
|
|
|
arguments << QLatin1String("--collect-systime=yes");
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
if (m_markAsPaused)
|
2012-11-26 15:02:17 +02:00
|
|
|
arguments << QLatin1String("--instr-atstart=no");
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
// add extra arguments
|
2012-02-02 20:26:12 +01:00
|
|
|
if (!m_argumentForToggleCollect.isEmpty())
|
|
|
|
|
arguments << m_argumentForToggleCollect;
|
2011-04-04 14:39:29 +02:00
|
|
|
|
|
|
|
|
return arguments;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
QString CallgrindToolRunner::progressTitle() const
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
return tr("Profiling");
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
ValgrindRunner * CallgrindToolRunner::runner()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
return &m_runner;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::start()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2013-10-17 13:48:04 +02:00
|
|
|
appendMessage(tr("Profiling %1").arg(executable()) + QLatin1Char('\n'), Utils::NormalMessageFormat);
|
2017-04-27 17:23:28 +02:00
|
|
|
return ValgrindToolRunner::start();
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::dump()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2017-06-20 18:01:25 +02:00
|
|
|
m_controller.run(CallgrindController::Dump);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::setPaused(bool paused)
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
if (m_markAsPaused == paused)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_markAsPaused = paused;
|
|
|
|
|
|
2011-05-11 16:26:34 +02:00
|
|
|
// call controller only if it is attached to a valgrind process
|
2017-06-20 18:01:25 +02:00
|
|
|
if (m_controller.valgrindProcess()) {
|
2011-05-11 16:26:34 +02:00
|
|
|
if (paused)
|
|
|
|
|
pause();
|
|
|
|
|
else
|
|
|
|
|
unpause();
|
|
|
|
|
}
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::setToggleCollectFunction(const QString &toggleCollectFunction)
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
if (toggleCollectFunction.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2012-02-02 20:26:12 +01:00
|
|
|
m_argumentForToggleCollect = QLatin1String("--toggle-collect=") + toggleCollectFunction;
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::reset()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2017-06-20 18:01:25 +02:00
|
|
|
m_controller.run(Callgrind::CallgrindController::ResetEventCounters);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::pause()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2017-06-20 18:01:25 +02:00
|
|
|
m_controller.run(Callgrind::CallgrindController::Pause);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::unpause()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2017-06-20 18:01:25 +02:00
|
|
|
m_controller.run(Callgrind::CallgrindController::UnPause);
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
Callgrind::ParseData *CallgrindToolRunner::takeParserData()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
2017-06-20 18:01:25 +02:00
|
|
|
return m_parser.takeData();
|
2011-04-04 14:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-27 17:23:28 +02:00
|
|
|
void CallgrindToolRunner::slotFinished()
|
2011-04-04 14:39:29 +02:00
|
|
|
{
|
|
|
|
|
emit parserDataReady(this);
|
|
|
|
|
}
|
2017-06-20 18:01:25 +02:00
|
|
|
|
|
|
|
|
void CallgrindToolRunner::showStatusMessage(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
Debugger::showPermanentStatusMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolRunner::triggerParse()
|
|
|
|
|
{
|
|
|
|
|
m_controller.getLocalDataFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolRunner::localParseDataAvailable(const QString &file)
|
|
|
|
|
{
|
|
|
|
|
// parse the callgrind file
|
|
|
|
|
QTC_ASSERT(!file.isEmpty(), return);
|
|
|
|
|
QFile outputFile(file);
|
|
|
|
|
QTC_ASSERT(outputFile.exists(), return);
|
|
|
|
|
if (outputFile.open(QIODevice::ReadOnly)) {
|
|
|
|
|
showStatusMessage(tr("Parsing Profile Data..."));
|
|
|
|
|
m_parser.parse(&outputFile);
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Could not open file for parsing:" << outputFile.fileName();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallgrindToolRunner::controllerFinished(CallgrindController::Option option)
|
|
|
|
|
{
|
|
|
|
|
switch (option)
|
|
|
|
|
{
|
|
|
|
|
case CallgrindController::Pause:
|
|
|
|
|
m_paused = true;
|
|
|
|
|
break;
|
|
|
|
|
case CallgrindController::UnPause:
|
|
|
|
|
m_paused = false;
|
|
|
|
|
break;
|
|
|
|
|
case CallgrindController::Dump:
|
|
|
|
|
triggerParse();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break; // do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|