drop valgrind support

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-11-21 00:59:59 +00:00
parent 9ba355d55f
commit 13c98116fc
9 changed files with 3 additions and 7676 deletions

View file

@ -1,129 +0,0 @@
/*
----------------------------------------------------------------
Notice that the following BSD-style license applies to this one
file (callgrind.h) only. The rest of Valgrind is licensed under the
terms of the GNU General Public License, version 2, unless
otherwise indicated. See the COPYING file in the source
distribution for details.
----------------------------------------------------------------
This file is part of callgrind, a valgrind tool for cache simulation
and call tree tracing.
Copyright (C) 2003-2017 Josef Weidendorfer. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(callgrind.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
#ifndef __CALLGRIND_H
#define __CALLGRIND_H
#include "valgrind.h"
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end.
The identification ('C','T') for Callgrind has historical
reasons: it was called "Calltree" before. Besides, ('C','G') would
clash with cachegrind.
*/
typedef
enum {
VG_USERREQ__DUMP_STATS = VG_USERREQ_TOOL_BASE('C','T'),
VG_USERREQ__ZERO_STATS,
VG_USERREQ__TOGGLE_COLLECT,
VG_USERREQ__DUMP_STATS_AT,
VG_USERREQ__START_INSTRUMENTATION,
VG_USERREQ__STOP_INSTRUMENTATION
} Vg_CallgrindClientRequest;
/* Dump current state of cost centers, and zero them afterwards */
#define CALLGRIND_DUMP_STATS \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DUMP_STATS, \
0, 0, 0, 0, 0)
/* Dump current state of cost centers, and zero them afterwards.
The argument is appended to a string stating the reason which triggered
the dump. This string is written as a description field into the
profile data dump. */
#define CALLGRIND_DUMP_STATS_AT(pos_str) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DUMP_STATS_AT, \
pos_str, 0, 0, 0, 0)
/* Zero cost centers */
#define CALLGRIND_ZERO_STATS \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__ZERO_STATS, \
0, 0, 0, 0, 0)
/* Toggles collection state.
The collection state specifies whether the happening of events
should be noted or if they are to be ignored. Events are noted
by increment of counters in a cost center */
#define CALLGRIND_TOGGLE_COLLECT \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__TOGGLE_COLLECT, \
0, 0, 0, 0, 0)
/* Start full callgrind instrumentation if not already switched on.
When cache simulation is done, it will flush the simulated cache;
this will lead to an artificial cache warmup phase afterwards with
cache misses which would not have happened in reality. */
#define CALLGRIND_START_INSTRUMENTATION \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__START_INSTRUMENTATION, \
0, 0, 0, 0, 0)
/* Stop full callgrind instrumentation if not already switched off.
This flushes Valgrinds translation cache, and does no additional
instrumentation afterwards, which effectivly will run at the same
speed as the "none" tool (ie. at minimal slowdown).
Use this to bypass Callgrind aggregation for uninteresting code parts.
To start Callgrind in this mode to ignore the setup phase, use
the option "--instr-atstart=no". */
#define CALLGRIND_STOP_INSTRUMENTATION \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STOP_INSTRUMENTATION, \
0, 0, 0, 0, 0)
#endif /* __CALLGRIND_H */

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,7 @@ include_directories(
${CMAKE_BINARY_DIR}/privateinclude/QtCore
${CMAKE_BINARY_DIR}/include/QtTest
${CMAKE_BINARY_DIR}/privateinclude/QtTest
# for fftw and valgrind
# for fftw
${CMAKE_SOURCE_DIR}/src
)
@ -69,7 +69,6 @@ set(TEST_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/qsignaldumper_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmark_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkmeasurement_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkvalgrind_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkmetric_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkevent_p.h
${CMAKE_CURRENT_SOURCE_DIR}/qabstracttestlogger_p.h
@ -91,7 +90,6 @@ set(TEST_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/qabstracttestlogger.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmark.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkmeasurement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkvalgrind.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkevent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qbenchmarkmetric.cpp
${CMAKE_CURRENT_SOURCE_DIR}/qtestelement.cpp

View file

@ -74,10 +74,6 @@ void QBenchmarkGlobalData::setMode(Mode mode)
if (mode_ == EventCounter) {
measurer = new QBenchmarkEvent;
#ifdef QTESTLIB_USE_VALGRIND
} else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) {
measurer = new QBenchmarkCallgrindMeasurer;
#endif
#ifdef HAVE_TICK_COUNTER
} else if (mode_ == TickCounter) {
measurer = new QBenchmarkTickMeasurer;

View file

@ -49,18 +49,9 @@
#include <QtCore/qglobal.h>
#if defined(Q_OS_LINUX) && !defined(QT_NO_PROCESS)
#define QTESTLIB_USE_VALGRIND
#else
#undef QTESTLIB_USE_VALGRIND
#endif
#include "QtTest/qbenchmarkmeasurement_p.h"
#include <QtCore/QMap>
#include <QtTest/qtest_global.h>
#ifdef QTESTLIB_USE_VALGRIND
#include "QtTest/qbenchmarkvalgrind_p.h"
#endif
#include "QtTest/qbenchmarkevent_p.h"
#include "QtTest/qbenchmarkmetric_p.h"
@ -120,7 +111,7 @@ public:
QBenchmarkGlobalData();
~QBenchmarkGlobalData();
enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, TickCounter, EventCounter };
enum Mode { WallTime, TickCounter, EventCounter };
void setMode(Mode mode);
Mode mode() const { return mode_; }
int adjustMedianIterationCount();

View file

@ -45,7 +45,7 @@
// We mean it.
//
#include <QtCore/qelapsedtimer.h>
#include "qelapsedtimer.h"
#include "qbenchmark.h"
#include "3rdparty/fftw/cycle.h"

View file

@ -1,249 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016-2020 Ivailo Monev
**
** This file is part of the QtTest module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "QtTest/qbenchmark_p.h"
#ifdef QTESTLIB_USE_VALGRIND
#include "QtTest/qbenchmarkvalgrind_p.h"
#include <QtCore/qstringlist.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qprocess.h>
#include <QtCore/qdir.h>
#include <QtCore/qset.h>
#include "3rdparty/valgrind/valgrind.h"
#include "3rdparty/valgrind/callgrind.h"
QT_BEGIN_NAMESPACE
// Returns true iff a sufficiently recent valgrind is available.
bool QBenchmarkValgrindUtils::haveValgrind()
{
#ifdef NVALGRIND
return false;
#else
QProcess process;
QStringList args;
args << QLatin1String("--version");
process.start(QLatin1String("valgrind"), args);
if (!process.waitForFinished(-1))
return false;
const QByteArray out = process.readAllStandardOutput();
const QRegExp rx(QLatin1String("^valgrind-([0-9]).([0-9]).[0-9]"));
if (rx.indexIn(QLatin1String(out.data())) == -1)
return false;
bool ok;
const int major = rx.cap(1).toInt(&ok);
if (!ok)
return false;
const int minor = rx.cap(2).toInt(&ok);
if (!ok)
return false;
// return (major > 3 || (major == 3 && minor >= 3)); // v >= 3.3 for --callgrind-out-file option
Q_UNUSED(major);
Q_UNUSED(minor);
return true; // skip version restriction for now
#endif
}
// Reruns this program through callgrind.
// Returns true upon success, otherwise false.
bool QBenchmarkValgrindUtils::rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode)
{
if (!QBenchmarkValgrindUtils::runCallgrindSubProcess(origAppArgs, exitCode)) {
qWarning("failed to run callgrind subprocess");
return false;
}
return true;
}
static void dumpOutput(const QByteArray &data, FILE *fh)
{
QFile file;
file.open(fh, QIODevice::WriteOnly);
file.write(data);
}
qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName)
{
QFile file(fileName);
const bool openOk = file.open(QIODevice::ReadOnly | QIODevice::Text);
Q_ASSERT(openOk);
Q_UNUSED(openOk);
qint64 val = -1;
bool valSeen = false;
const QRegExp rxValue(QLatin1String("^summary: (\\d+)"));
while (!file.atEnd()) {
const QString line(QLatin1String(file.readLine()));
if (rxValue.indexIn(line) != -1) {
Q_ASSERT(rxValue.captureCount() == 1);
bool ok;
val = rxValue.cap(1).toLongLong(&ok);
Q_ASSERT(ok);
valSeen = true;
break;
}
}
if (!valSeen)
qFatal("failed to extract result");
return val;
}
// Gets the newest file name (i.e. the one with the highest integer suffix).
QString QBenchmarkValgrindUtils::getNewestFileName()
{
QStringList nameFilters;
QString base = QBenchmarkGlobalData::current->callgrindOutFileBase;
Q_ASSERT(!base.isEmpty());
nameFilters << QString::fromLatin1("%1.*").arg(base);
QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
Q_ASSERT(!fiList.empty());
int hiSuffix = -1;
QFileInfo lastFileInfo;
const QString pattern = QString::fromLatin1("%1.(\\d+)").arg(base);
const QRegExp rx(pattern);
foreach (QFileInfo fileInfo, fiList) {
const int index = rx.indexIn(fileInfo.fileName());
Q_ASSERT(index == 0);
Q_UNUSED(index);
bool ok;
const int suffix = rx.cap(1).toInt(&ok);
Q_ASSERT(ok);
Q_ASSERT(suffix >= 0);
if (suffix > hiSuffix) {
lastFileInfo = fileInfo;
hiSuffix = suffix;
}
}
return lastFileInfo.fileName();
}
qint64 QBenchmarkValgrindUtils::extractLastResult()
{
return extractResult(getNewestFileName());
}
void QBenchmarkValgrindUtils::cleanup()
{
QStringList nameFilters;
QString base = QBenchmarkGlobalData::current->callgrindOutFileBase;
Q_ASSERT(!base.isEmpty());
nameFilters
<< base // overall summary
<< QString::fromLatin1("%1.*").arg(base); // individual dumps
QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
foreach (QFileInfo fileInfo, fiList) {
const bool removeOk = QFile::remove(fileInfo.fileName());
Q_ASSERT(removeOk);
Q_UNUSED(removeOk);
}
}
QString QBenchmarkValgrindUtils::outFileBase(qint64 pid)
{
return QString::fromLatin1("callgrind.out.%1").arg(
pid != -1 ? pid : QCoreApplication::applicationPid());
}
// Reruns this program through callgrind, storing callgrind result files in the
// current directory.
// Returns true upon success, otherwise false.
bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppArgs, int &exitCode)
{
const QString execFile(origAppArgs.at(0));
QStringList args;
args << QLatin1String("--tool=callgrind") << QLatin1String("--instr-atstart=yes")
<< QLatin1String("--quiet")
<< execFile << QLatin1String("-callgrindchild");
// pass on original arguments that make sense (e.g. avoid wasting time producing output
// that will be ignored anyway) ...
for (int i = 1; i < origAppArgs.size(); ++i) {
const QString arg(origAppArgs.at(i));
if (arg == QLatin1String("-callgrind"))
continue;
args << arg; // ok to pass on
}
QProcess process;
process.start(QLatin1String("valgrind"), args);
process.waitForStarted(-1);
QBenchmarkGlobalData::current->callgrindOutFileBase =
QBenchmarkValgrindUtils::outFileBase(process.pid());
const bool finishedOk = process.waitForFinished(-1);
exitCode = process.exitCode();
dumpOutput(process.readAllStandardOutput(), stdout);
dumpOutput(process.readAllStandardError(), stderr);
return finishedOk;
}
void QBenchmarkCallgrindMeasurer::start()
{
CALLGRIND_ZERO_STATS;
}
qint64 QBenchmarkCallgrindMeasurer::checkpoint()
{
CALLGRIND_DUMP_STATS;
return QBenchmarkValgrindUtils::extractLastResult();
}
qint64 QBenchmarkCallgrindMeasurer::stop()
{
return checkpoint();
}
bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement)
{
Q_UNUSED(measurement);
return true;
}
bool QBenchmarkCallgrindMeasurer::needsWarmupIteration()
{
return true;
}
QTest::QBenchmarkMetric QBenchmarkCallgrindMeasurer::metricType()
{
return QTest::InstructionReads;
}
QT_END_NAMESPACE
#endif // QTESTLIB_USE_VALGRIND

View file

@ -1,83 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016-2020 Ivailo Monev
**
** This file is part of the QtTest module of the Katie Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QBENCHMARKVALGRIND_P_H
#define QBENCHMARKVALGRIND_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Katie API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "QtTest/qbenchmarkmeasurement_p.h"
#include "QtTest/qbenchmarkmetric_p.h"
#include <QtCore/qmap.h>
#include <QtCore/qstring.h>
class QStringList;
QT_BEGIN_NAMESPACE
class QBenchmarkValgrindUtils
{
public:
static bool haveValgrind();
static bool rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode);
static bool runCallgrindSubProcess(const QStringList &origAppArgs, int &exitCode);
static qint64 extractResult(const QString &fileName);
static QString getNewestFileName();
static qint64 extractLastResult();
static void cleanup();
static QString outFileBase(qint64 pid = -1);
};
class QBenchmarkCallgrindMeasurer : public QBenchmarkMeasurerBase
{
public:
void start();
qint64 checkpoint();
qint64 stop();
bool isMeasurementAccepted(qint64 measurement);
bool needsWarmupIteration();
QTest::QBenchmarkMetric metricType();
};
QT_END_NAMESPACE
#endif // QBENCHMARKVALGRIND_H

View file

@ -1093,9 +1093,6 @@ Q_TEST_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
#endif
"\n"
" Benchmark related options:\n"
#ifdef QTESTLIB_USE_VALGRIND
" -callgrind : Use callgrind to time benchmarks\n"
#endif
#ifdef HAVE_TICK_COUNTER
" -tickcounter : Use CPU tick counters to time benchmarks\n"
#endif
@ -1184,23 +1181,6 @@ Q_TEST_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
#endif
} else if (strcmp(argv[i], "-keyevent-verbose") == 0) {
QTest::keyVerbose = 1;
#ifdef QTESTLIB_USE_VALGRIND
} else if (strcmp(argv[i], "-callgrind") == 0) {
if (QBenchmarkValgrindUtils::haveValgrind())
if (QFileInfo(QDir::currentPath()).isWritable()) {
QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess);
} else {
printf("WARNING: Current directory not writable. Using the walltime measurer.\n");
}
else {
printf("WARNING: Valgrind not found or too old. Make sure it is installed and in your path. "
"Using the walltime measurer.\n");
}
} else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option
QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindChildProcess);
QBenchmarkGlobalData::current->callgrindOutFileBase =
QBenchmarkValgrindUtils::outFileBase();
#endif
#ifdef HAVE_TICK_COUNTER
} else if (strcmp(argv[i], "-tickcounter") == 0) {
QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::TickCounter);
@ -1795,10 +1775,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
QBenchmarkGlobalData benchmarkData;
QBenchmarkGlobalData::current = &benchmarkData;
#ifdef QTESTLIB_USE_VALGRIND
int callgrindChildExitCode = 0;
#endif
QT_TRY {
QTestResult::reset();
@ -1817,16 +1793,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
if (QTest::randomOrder) {
seedRandom();
}
#ifdef QTESTLIB_USE_VALGRIND
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
const QStringList origAppArgs(QCoreApplication::arguments());
if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode))
return -1;
QBenchmarkValgrindUtils::cleanup();
} else
#endif
{
#if defined(Q_OS_UNIX)
QScopedPointer<FatalSignalHandler> handler;
@ -1856,15 +1822,9 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
#if defined(QTEST_NOEXITCODE)
return 0;
#else
#ifdef QTESTLIB_USE_VALGRIND
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
return callgrindChildExitCode;
#endif
// make sure our exit code is never going above 127
// since that could wrap and indicate 0 test fails
return qMin(QTestResult::failCount(), 127);
#endif
}