File indexing completed on 2024-04-21 04:36:00

0001 /* This file is part of KDevelop
0002    Copyright 2011 Mathieu Lornac <mathieu.lornac@gmail.com>
0003    Copyright 2011 Damien Coppel <damien.coppel@gmail.com>
0004    Copyright 2011 Lionel Duc <lionel.data@gmail.com>
0005    Copyright 2011 Sebastien Rannou <mxs@sbrk.org>
0006    Copyright 2011 Lucas Sarie <lucas.sarie@gmail.com>
0007    Copyright 2016-2017 Anton Anikin <anton@anikin.xyz>
0008 
0009    This program is free software; you can redistribute it and/or
0010    modify it under the terms of the GNU General Public
0011    License as published by the Free Software Foundation; either
0012    version 2 of the License, or (at your option) any later version.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0017    General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program; see the file COPYING.  If not, write to
0021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0022    Boston, MA 02110-1301, USA.
0023 */
0024 
0025 #include "callgrind_job.h"
0026 
0027 #include "callgrind_config.h"
0028 #include "callgrind_model.h"
0029 #include "callgrind_parser.h"
0030 #include "callgrind_tool.h"
0031 #include "callgrind_view.h"
0032 #include "plugin.h"
0033 
0034 #include <interfaces/ilaunchconfiguration.h>
0035 
0036 #include <KConfigGroup>
0037 #include <KShell>
0038 
0039 #include <QBuffer>
0040 #include <QFile>
0041 #include <QTemporaryFile>
0042 
0043 namespace Valgrind
0044 {
0045 
0046 CallgrindJob::CallgrindJob(KDevelop::ILaunchConfiguration* launchConfig)
0047     : Job(CallgrindTool::self(), launchConfig)
0048     , m_model(new CallgrindFunctionsModel)
0049     , m_outputFile(new QTemporaryFile(this))
0050 {
0051     m_outputFile->open();
0052 }
0053 
0054 bool CallgrindJob::processEnded()
0055 {
0056     CallgrindConfig config;
0057     config.setConfigGroup(m_configGroup);
0058     config.load();
0059 
0060     QStringList caArgs;
0061     caArgs += KShell::splitArgs(config.callgrindAnnotateArgs());
0062     caArgs += QStringLiteral("--tree=calling");
0063     caArgs += QStringLiteral("--threshold=100");
0064     caArgs += m_outputFile->fileName();
0065 
0066     QByteArray caOutput;
0067     if (executeProcess(config.callgrindAnnotateExecutablePath(), caArgs, caOutput)) {
0068         return false;
0069     }
0070 
0071     callgrindParse(caOutput, m_model);
0072 
0073     return true;
0074 }
0075 
0076 void CallgrindJob::addToolArgs(QStringList& args) const
0077 {
0078     CallgrindConfig config;
0079     config.setConfigGroup(m_configGroup);
0080     config.load();
0081 
0082     args += config.cmdArgs();
0083     args += QStringLiteral("--callgrind-out-file=%1").arg(m_outputFile->fileName());
0084 }
0085 
0086 QWidget* CallgrindJob::createView()
0087 {
0088     return new CallgrindView(m_configGroup, m_outputFile, m_model);
0089 }
0090 
0091 }