55qint64 QBenchmarkValgrindUtils::extractResult(
const QString &fileName)
58 const bool openOk = file.open(QIODevice::ReadOnly | QIODevice::Text);
62 std::optional<qint64> val = std::nullopt;
64 while (file.readLineInto(&line)) {
65 constexpr QByteArrayView tag =
"summary: ";
66 if (line.startsWith(tag)) {
67 const auto maybeNumber = line.data() + tag.size();
68 const auto end = line.data() + line.size();
70 const auto r = std::from_chars(maybeNumber, end, v);
71 if (r.ec == std::errc{}) {
78 qFatal(
"Failed to extract result");
83QString QBenchmarkValgrindUtils::getNewestFileName()
85 QStringList nameFilters;
86 QString base = QBenchmarkGlobalData::current->callgrindOutFileBase;
87 Q_ASSERT(!base.isEmpty());
89 nameFilters << QString::fromLatin1(
"%1.*").arg(base);
90 const QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
91 Q_ASSERT(!fiList.empty());
93 QFileInfo lastFileInfo;
94 const QString pattern = QString::fromLatin1(
"%1.(\\d+)").arg(base);
95 QRegularExpression rx(pattern);
96 for (
const QFileInfo &fileInfo : fiList) {
97 QRegularExpressionMatch match = rx.match(fileInfo.fileName());
98 Q_ASSERT(match.hasMatch());
100 const int suffix = match.captured(1).toInt(&ok);
102 Q_ASSERT(suffix >= 0);
103 if (suffix > hiSuffix) {
104 lastFileInfo = fileInfo;
109 return lastFileInfo.fileName();
117void QBenchmarkValgrindUtils::cleanup()
119 QStringList nameFilters;
120 QString base = QBenchmarkGlobalData::current->callgrindOutFileBase;
121 Q_ASSERT(!base.isEmpty());
124 << QString::fromLatin1(
"%1.*").arg(base);
125 const QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
126 for (
const QFileInfo &fileInfo : fiList) {
127 const bool removeOk = QFile::remove(fileInfo.fileName());
142bool QBenchmarkValgrindUtils::runCallgrindSubProcess(
const QStringList &origAppArgs,
int &exitCode)
144 const QString &execFile = origAppArgs.at(0);
145 QStringList args{ u"--tool=callgrind"_s, u"--instr-atstart=yes"_s,
146 u"--quiet"_s, execFile, u"-callgrindchild"_s };
150 for (
int i = 1; i < origAppArgs.size(); ++i) {
151 const QString &arg = origAppArgs.at(i);
152 if (arg ==
"-callgrind"_L1)
158 process.start(u"valgrind"_s, args);
159 process.waitForStarted(-1);
160 QBenchmarkGlobalData::current->callgrindOutFileBase =
161 QBenchmarkValgrindUtils::outFileBase(process.processId());
162 const bool finishedOk = process.waitForFinished(-1);
163 exitCode = process.exitCode();
165 dumpOutput(process.readAllStandardOutput(), stdout);
166 dumpOutput(process.readAllStandardError(), stderr);