41
41
#include <valgrind/callgrind/callgrindfunction.h>
42
42
#include <valgrind/callgrind/callgrindfunctioncall.h>
43
43
#include <valgrind/callgrind/callgrindparsedata.h>
44
#include <valgrind/callgrind/callgrindparser.h>
44
45
#include <valgrind/callgrind/callgrindproxymodel.h>
45
46
#include <valgrind/callgrind/callgrindstackbrowser.h>
46
47
#include <valgrind/valgrindplugin.h>
47
48
#include <valgrind/valgrindsettings.h>
49
50
#include <analyzerbase/analyzermanager.h>
50
#include <analyzerbase/analyzersettings.h>
51
51
#include <analyzerbase/analyzerutils.h>
52
52
#include <analyzerbase/analyzerconstants.h>
54
#include <coreplugin/actionmanager/actioncontainer.h>
55
#include <coreplugin/actionmanager/actionmanager.h>
56
#include <coreplugin/actionmanager/command.h>
57
54
#include <coreplugin/coreconstants.h>
58
#include <coreplugin/icontext.h>
59
55
#include <coreplugin/icore.h>
61
57
#include <cplusplus/LookupContext.h>
62
58
#include <cplusplus/Overview.h>
63
#include <cppeditor/cppeditorconstants.h>
64
59
#include <extensionsystem/iplugin.h>
65
60
#include <texteditor/itexteditor.h>
540
518
return ReleaseMode;
543
void CallgrindTool::extensionsInitialized()
545
Core::Context analyzerContext = Core::Context(Analyzer::Constants::C_ANALYZEMODE);
547
// check if there is a CppEditor context menu, if true, add our own context menu actions
548
if (Core::ActionContainer *editorContextMenu =
549
Core::ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT)) {
551
Core::Command *cmd = 0;
553
editorContextMenu->addSeparator(analyzerContext);
555
action = new QAction(tr("Profile Costs of this Function and its Callees"), this);
556
action->setIcon(QIcon(QLatin1String(Analyzer::Constants::ANALYZER_CONTROL_START_ICON)));
557
connect(action, SIGNAL(triggered()), d, SLOT(handleShowCostsOfFunction()));
558
cmd = Core::ActionManager::registerAction(action, "Analyzer.Callgrind.ShowCostsOfFunction",
560
editorContextMenu->addAction(cmd);
561
cmd->setAttribute(Core::Command::CA_Hide);
562
cmd->setAttribute(Core::Command::CA_NonConfigurable);
563
d->m_showCostsOfFunctionAction = action;
567
IAnalyzerEngine *CallgrindTool::createEngine(const AnalyzerStartParameters &sp,
568
ProjectExplorer::RunConfiguration *runConfiguration)
570
return d->createEngine(sp, runConfiguration);
573
IAnalyzerEngine *CallgrindToolPrivate::createEngine(const AnalyzerStartParameters &sp,
574
ProjectExplorer::RunConfiguration *runConfiguration)
576
CallgrindEngine *engine = new CallgrindEngine(q, sp, runConfiguration);
578
connect(engine, SIGNAL(parserDataReady(CallgrindEngine*)),
579
SLOT(takeParserData(CallgrindEngine*)));
580
connect(engine, SIGNAL(starting(const Analyzer::IAnalyzerEngine*)),
581
SLOT(engineStarting(const Analyzer::IAnalyzerEngine*)));
582
connect(engine, SIGNAL(finished()),
521
AnalyzerRunControl *CallgrindTool::createRunControl(const AnalyzerStartParameters &sp,
522
RunConfiguration *runConfiguration)
524
return d->createRunControl(sp, runConfiguration);
527
AnalyzerRunControl *CallgrindToolPrivate::createRunControl(const AnalyzerStartParameters &sp,
528
RunConfiguration *runConfiguration)
530
CallgrindRunControl *rc = new CallgrindRunControl(sp, runConfiguration);
532
connect(rc, SIGNAL(parserDataReady(CallgrindRunControl*)),
533
SLOT(takeParserData(CallgrindRunControl*)));
534
connect(rc, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)),
535
SLOT(engineStarting(const Analyzer::AnalyzerRunControl*)));
536
connect(rc, SIGNAL(finished()),
583
537
SLOT(engineFinished()));
585
connect(this, SIGNAL(dumpRequested()), engine, SLOT(dump()));
586
connect(this, SIGNAL(resetRequested()), engine, SLOT(reset()));
587
connect(this, SIGNAL(pauseToggled(bool)), engine, SLOT(setPaused(bool)));
539
connect(this, SIGNAL(dumpRequested()), rc, SLOT(dump()));
540
connect(this, SIGNAL(resetRequested()), rc, SLOT(reset()));
541
connect(this, SIGNAL(pauseToggled(bool)), rc, SLOT(setPaused(bool)));
590
engine->setPaused(m_pauseAction->isChecked());
543
// initialize run control
544
rc->setPaused(m_pauseAction->isChecked());
592
546
// we may want to toggle collect for one function only in this run
593
engine->setToggleCollectFunction(m_toggleCollectFunction);
547
rc->setToggleCollectFunction(m_toggleCollectFunction);
594
548
m_toggleCollectFunction.clear();
596
AnalyzerManager::showStatusMessage(AnalyzerManager::msgToolStarted(q->displayName()));
598
QTC_ASSERT(m_visualisation, return engine);
550
QTC_ASSERT(m_visualisation, return rc);
600
552
// apply project settings
601
553
if (runConfiguration) {
602
if (const AnalyzerRunConfigurationAspect *analyzerSettings = runConfiguration->extraAspect<AnalyzerRunConfigurationAspect>()) {
603
if (const ValgrindProjectSettings *settings = analyzerSettings->subConfig<ValgrindProjectSettings>()) {
554
if (IRunConfigurationAspect *analyzerAspect = runConfiguration->extraAspect(ANALYZER_VALGRIND_SETTINGS)) {
555
if (const ValgrindBaseSettings *settings = qobject_cast<ValgrindBaseSettings *>(analyzerAspect->currentSettings())) {
604
556
m_visualisation->setMinimumInclusiveCostRatio(settings->visualisationMinimumInclusiveCostRatio() / 100.0);
605
557
m_proxyModel->setMinimumInclusiveCostRatio(settings->minimumInclusiveCostRatio() / 100.0);
606
558
m_dataModel->setVerboseToolTipsEnabled(settings->enableEventToolTips());
613
565
void CallgrindTool::startTool(StartMode mode)
615
ValgrindPlugin::startValgrindTool(this, mode);
567
ValgrindTool::startTool(mode);
616
568
d->setBusyCursor(true);
571
void CallgrindTool::loadExternalXmlLogFile()
573
d->loadExternalXmlLogFile();
576
void CallgrindTool::handleShowCostsOfFunction()
578
d->handleShowCostsOfFunction();
619
581
QWidget *CallgrindTool::createWidgets()
621
583
return d->createWidgets();
800
770
layout->addWidget(button);
774
ValgrindGlobalSettings *settings = ValgrindPlugin::globalSettings();
803
776
// cycle detection
804
777
//action = new QAction(QLatin1String("Cycle Detection"), this); ///FIXME: icon
805
778
action = new QAction(QLatin1String("O"), this); ///FIXME: icon
806
779
action->setToolTip(tr("Enable cycle detection to properly handle recursive or circular function calls."));
807
780
action->setCheckable(true);
808
781
connect(action, SIGNAL(toggled(bool)), m_dataModel, SLOT(enableCycleDetection(bool)));
809
connect(action, SIGNAL(toggled(bool)), m_settings, SLOT(setDetectCycles(bool)));
782
connect(action, SIGNAL(toggled(bool)), settings, SLOT(setDetectCycles(bool)));
810
783
layout->addWidget(createToolButton(action));
811
784
m_cycleDetection = action;
962
void CallgrindToolPrivate::takeParserData(CallgrindEngine *engine)
964
ParseData *data = engine->takeParserData();
937
void CallgrindToolPrivate::loadExternalXmlLogFile()
939
const QString filePath = QFileDialog::getOpenFileName(
940
Core::ICore::mainWindow(),
941
tr("Open Callgrind XML Log File"),
943
tr("XML Files (*.xml);;All Files (*)"));
944
if (filePath.isEmpty())
947
QFile logFile(filePath);
948
if (!logFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
949
QMessageBox::critical(AnalyzerManager::mainWindow(), tr("Internal Error"),
950
tr("Failed to open file for reading: %1").arg(filePath));
954
AnalyzerManager::showStatusMessage(tr("Parsing Profile Data..."));
955
QCoreApplication::processEvents();
958
parser.parse(&logFile);
959
takeParserData(parser.takeData());
962
void CallgrindToolPrivate::takeParserData(CallgrindRunControl *rc)
964
takeParserData(rc->takeParserData());
967
void CallgrindToolPrivate::takeParserData(ParseData *data)
965
969
showParserResults(data);