File indexing completed on 2024-04-14 04:31:19
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 2016-2017 Anton Anikin <anton@anikin.xyz> 0007 0008 This program is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This program is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 General Public License for more details. 0017 0018 You should have received a copy of the GNU General Public License 0019 along with this program; see the file COPYING. If not, write to 0020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 Boston, MA 02110-1301, USA. 0022 */ 0023 0024 0025 #include "cachegrind_job.h" 0026 0027 #include "cachegrind_config.h" 0028 #include "cachegrind_model.h" 0029 #include "cachegrind_parser.h" 0030 #include "cachegrind_tool.h" 0031 #include "cachegrind_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 CachegrindJob::CachegrindJob(KDevelop::ILaunchConfiguration* launchConfig) 0047 : Job(CachegrindTool::self(), launchConfig) 0048 , m_model(new CachegrindFunctionsModel) 0049 , m_outputFile(new QTemporaryFile(this)) 0050 { 0051 m_outputFile->open(); 0052 } 0053 0054 bool CachegrindJob::processEnded() 0055 { 0056 CachegrindConfig config; 0057 config.setConfigGroup(m_configGroup); 0058 config.load(); 0059 0060 QStringList cgArgs; 0061 cgArgs += KShell::splitArgs(config.cgAnnotateParameters()); 0062 cgArgs += m_outputFile->fileName(); 0063 0064 QByteArray cgOutput; 0065 if (executeProcess(config.cgAnnotateExecutablePath(), cgArgs, cgOutput) != 0) { 0066 return false; 0067 } 0068 0069 cachegrindParse(cgOutput, m_model); 0070 0071 return true; 0072 } 0073 0074 void CachegrindJob::addToolArgs(QStringList& args) const 0075 { 0076 CachegrindConfig config; 0077 config.setConfigGroup(m_configGroup); 0078 config.load(); 0079 0080 args += config.cmdArgs(); 0081 args += QStringLiteral("--cachegrind-out-file=%1").arg(m_outputFile->fileName()); 0082 } 0083 0084 QWidget* CachegrindJob::createView() 0085 { 0086 return new CachegrindView(m_model); 0087 } 0088 0089 }