| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/testlib/qbenchmarkvalgrind.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | bool QBenchmarkValgrindUtils::haveValgrind() | - | ||||||
| 9 | { | - | ||||||
| 10 | - | |||||||
| 11 | - | |||||||
| 12 | - | |||||||
| 13 | QProcess process; | - | ||||||
| 14 | process.start(QLatin1String("valgrind"), QStringList(QLatin1String("--version"))); | - | ||||||
| 15 | return never executed: process.waitForStarted() && process.waitForFinished(-1);return process.waitForStarted() && process.waitForFinished(-1);never executed: return process.waitForStarted() && process.waitForFinished(-1); | 0 | ||||||
| 16 | - | |||||||
| 17 | } | - | ||||||
| 18 | - | |||||||
| 19 | - | |||||||
| 20 | - | |||||||
| 21 | bool QBenchmarkValgrindUtils::rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode) | - | ||||||
| 22 | { | - | ||||||
| 23 | if (!QBenchmarkValgrindUtils::runCallgrindSubProcess(origAppArgs, exitCode)
| 0 | ||||||
| 24 | QMessageLogger(__FILE__, 71, __PRETTY_FUNCTION__).warning("failed to run callgrind subprocess"); | - | ||||||
| 25 | return never executed: false;return false;never executed: return false; | 0 | ||||||
| 26 | } | - | ||||||
| 27 | return never executed: true;return true;never executed: return true; | 0 | ||||||
| 28 | } | - | ||||||
| 29 | - | |||||||
| 30 | static void dumpOutput(const QByteArray &data, FILE *fh) | - | ||||||
| 31 | { | - | ||||||
| 32 | QFile file; | - | ||||||
| 33 | file.open(fh, QIODevice::WriteOnly); | - | ||||||
| 34 | file.write(data); | - | ||||||
| 35 | } never executed: end of block | 0 | ||||||
| 36 | - | |||||||
| 37 | qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName) | - | ||||||
| 38 | { | - | ||||||
| 39 | QFile file(fileName); | - | ||||||
| 40 | const bool openOk = file.open(QIODevice::ReadOnly | QIODevice::Text); | - | ||||||
| 41 | ((!(openOk)) ? qt_assert("openOk",__FILE__,88) : qt_noop()); | - | ||||||
| 42 | (void)openOk;; | - | ||||||
| 43 | - | |||||||
| 44 | qint64 val = -1; | - | ||||||
| 45 | bool valSeen = false; | - | ||||||
| 46 | QRegExp rxValue(QLatin1String("^summary: (\\d+)")); | - | ||||||
| 47 | while (!file.atEnd()
| 0 | ||||||
| 48 | const QString line(QLatin1String(file.readLine())); | - | ||||||
| 49 | if (rxValue.indexIn(line) != -1
| 0 | ||||||
| 50 | ((!(rxValue.captureCount() == 1)) ? qt_assert("rxValue.captureCount() == 1",__FILE__,97) : qt_noop()); | - | ||||||
| 51 | bool ok; | - | ||||||
| 52 | val = rxValue.cap(1).toLongLong(&ok); | - | ||||||
| 53 | ((!(ok)) ? qt_assert("ok",__FILE__,100) : qt_noop()); | - | ||||||
| 54 | valSeen = true; | - | ||||||
| 55 | break; never executed: break; | 0 | ||||||
| 56 | } | - | ||||||
| 57 | } never executed: end of block | 0 | ||||||
| 58 | if (__builtin_expect(!!(!valSeen), false)
| 0 | ||||||
| 59 | QMessageLogger(__FILE__, 106, __PRETTY_FUNCTION__).fatal("Failed to extract result"); never executed: QMessageLogger(__FILE__, 106, __PRETTY_FUNCTION__).fatal("Failed to extract result"); | 0 | ||||||
| 60 | return never executed: val;return val;never executed: return val; | 0 | ||||||
| 61 | } | - | ||||||
| 62 | - | |||||||
| 63 | - | |||||||
| 64 | QString QBenchmarkValgrindUtils::getNewestFileName() | - | ||||||
| 65 | { | - | ||||||
| 66 | QStringList nameFilters; | - | ||||||
| 67 | QString base = QBenchmarkGlobalData::current->callgrindOutFileBase; | - | ||||||
| 68 | ((!(!base.isEmpty())) ? qt_assert("!base.isEmpty()",__FILE__,115) : qt_noop()); | - | ||||||
| 69 | - | |||||||
| 70 | nameFilters << QString::fromLatin1("%1.*").arg(base); | - | ||||||
| 71 | const QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable); | - | ||||||
| 72 | ((!(!fiList.empty())) ? qt_assert("!fiList.empty()",__FILE__,119) : qt_noop()); | - | ||||||
| 73 | int hiSuffix = -1; | - | ||||||
| 74 | QFileInfo lastFileInfo; | - | ||||||
| 75 | const QString pattern = QString::fromLatin1("%1.(\\d+)").arg(base); | - | ||||||
| 76 | QRegExp rx(pattern); | - | ||||||
| 77 | for (const QFileInfo &fileInfo : fiList) { | - | ||||||
| 78 | const int index = rx.indexIn(fileInfo.fileName()); | - | ||||||
| 79 | ((!(index == 0)) ? qt_assert("index == 0",__FILE__,126) : qt_noop()); | - | ||||||
| 80 | (void)index;; | - | ||||||
| 81 | bool ok; | - | ||||||
| 82 | const int suffix = rx.cap(1).toInt(&ok); | - | ||||||
| 83 | ((!(ok)) ? qt_assert("ok",__FILE__,130) : qt_noop()); | - | ||||||
| 84 | ((!(suffix >= 0)) ? qt_assert("suffix >= 0",__FILE__,131) : qt_noop()); | - | ||||||
| 85 | if (suffix > hiSuffix
| 0 | ||||||
| 86 | lastFileInfo = fileInfo; | - | ||||||
| 87 | hiSuffix = suffix; | - | ||||||
| 88 | } never executed: end of block | 0 | ||||||
| 89 | } never executed: end of block | 0 | ||||||
| 90 | - | |||||||
| 91 | return never executed: lastFileInfo.fileName();return lastFileInfo.fileName();never executed: return lastFileInfo.fileName(); | 0 | ||||||
| 92 | } | - | ||||||
| 93 | - | |||||||
| 94 | qint64 QBenchmarkValgrindUtils::extractLastResult() | - | ||||||
| 95 | { | - | ||||||
| 96 | return never executed: extractResult(getNewestFileName());return extractResult(getNewestFileName());never executed: return extractResult(getNewestFileName()); | 0 | ||||||
| 97 | } | - | ||||||
| 98 | - | |||||||
| 99 | void QBenchmarkValgrindUtils::cleanup() | - | ||||||
| 100 | { | - | ||||||
| 101 | QStringList nameFilters; | - | ||||||
| 102 | QString base = QBenchmarkGlobalData::current->callgrindOutFileBase; | - | ||||||
| 103 | ((!(!base.isEmpty())) ? qt_assert("!base.isEmpty()",__FILE__,150) : qt_noop()); | - | ||||||
| 104 | nameFilters | - | ||||||
| 105 | << base | - | ||||||
| 106 | << QString::fromLatin1("%1.*").arg(base); | - | ||||||
| 107 | const QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable); | - | ||||||
| 108 | for (const QFileInfo &fileInfo : fiList) { | - | ||||||
| 109 | const bool removeOk = QFile::remove(fileInfo.fileName()); | - | ||||||
| 110 | ((!(removeOk)) ? qt_assert("removeOk",__FILE__,157) : qt_noop()); | - | ||||||
| 111 | (void)removeOk;; | - | ||||||
| 112 | } never executed: end of block | 0 | ||||||
| 113 | } never executed: end of block | 0 | ||||||
| 114 | - | |||||||
| 115 | QString QBenchmarkValgrindUtils::outFileBase(qint64 pid) | - | ||||||
| 116 | { | - | ||||||
| 117 | return never executed: QString::fromLatin1("callgrind.out.%1").arg(return QString::fromLatin1("callgrind.out.%1").arg( pid != -1 ? pid : QCoreApplication::applicationPid());never executed: return QString::fromLatin1("callgrind.out.%1").arg( pid != -1 ? pid : QCoreApplication::applicationPid()); | 0 | ||||||
| 118 | pid != -1 ? pid : QCoreApplication::applicationPid()); never executed: return QString::fromLatin1("callgrind.out.%1").arg( pid != -1 ? pid : QCoreApplication::applicationPid()); | 0 | ||||||
| 119 | } | - | ||||||
| 120 | - | |||||||
| 121 | - | |||||||
| 122 | - | |||||||
| 123 | - | |||||||
| 124 | bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppArgs, int &exitCode) | - | ||||||
| 125 | { | - | ||||||
| 126 | const QString execFile(origAppArgs.at(0)); | - | ||||||
| 127 | QStringList args; | - | ||||||
| 128 | args << QLatin1String("--tool=callgrind") << QLatin1String("--instr-atstart=yes") | - | ||||||
| 129 | << QLatin1String("--quiet") | - | ||||||
| 130 | << execFile << QLatin1String("-callgrindchild"); | - | ||||||
| 131 | - | |||||||
| 132 | - | |||||||
| 133 | - | |||||||
| 134 | for (int i = 1; i < origAppArgs.size()
| 0 | ||||||
| 135 | const QString arg(origAppArgs.at(i)); | - | ||||||
| 136 | if (arg == QLatin1String("-callgrind")
| 0 | ||||||
| 137 | continue; never executed: continue; | 0 | ||||||
| 138 | args << arg; | - | ||||||
| 139 | } never executed: end of block | 0 | ||||||
| 140 | - | |||||||
| 141 | QProcess process; | - | ||||||
| 142 | process.start(QLatin1String("valgrind"), args); | - | ||||||
| 143 | process.waitForStarted(-1); | - | ||||||
| 144 | QBenchmarkGlobalData::current->callgrindOutFileBase = | - | ||||||
| 145 | QBenchmarkValgrindUtils::outFileBase(process.pid()); | - | ||||||
| 146 | const bool finishedOk = process.waitForFinished(-1); | - | ||||||
| 147 | exitCode = process.exitCode(); | - | ||||||
| 148 | - | |||||||
| 149 | dumpOutput(process.readAllStandardOutput(), stdout); | - | ||||||
| 150 | dumpOutput(process.readAllStandardError(), stderr); | - | ||||||
| 151 | - | |||||||
| 152 | return never executed: finishedOk;return finishedOk;never executed: return finishedOk; | 0 | ||||||
| 153 | } | - | ||||||
| 154 | - | |||||||
| 155 | void QBenchmarkCallgrindMeasurer::start() | - | ||||||
| 156 | { | - | ||||||
| 157 | {unsigned int _qzz_res; { volatile unsigned long long int _zzq_args[6]; volatile unsigned long long int _zzq_result; _zzq_args[0] = (unsigned long long int)(VG_USERREQ__ZERO_STATS); _zzq_args[1] = (unsigned long long int)(0); _zzq_args[2] = (unsigned long long int)(0); _zzq_args[3] = (unsigned long long int)(0); _zzq_args[4] = (unsigned long long int)(0); _zzq_args[5] = (unsigned long long int)(0); __asm__ volatile("rolq $3, %%rdi ; rolq $13, %%rdi\n\t" "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", "memory" ); _qzz_res = _zzq_result; (void)_qzz_res; }; }; | - | ||||||
| 158 | } never executed: end of block | 0 | ||||||
| 159 | - | |||||||
| 160 | qint64 QBenchmarkCallgrindMeasurer::checkpoint() | - | ||||||
| 161 | { | - | ||||||
| 162 | {unsigned int _qzz_res; { volatile unsigned long long int _zzq_args[6]; volatile unsigned long long int _zzq_result; _zzq_args[0] = (unsigned long long int)(VG_USERREQ__DUMP_STATS); _zzq_args[1] = (unsigned long long int)(0); _zzq_args[2] = (unsigned long long int)(0); _zzq_args[3] = (unsigned long long int)(0); _zzq_args[4] = (unsigned long long int)(0); _zzq_args[5] = (unsigned long long int)(0); __asm__ volatile("rolq $3, %%rdi ; rolq $13, %%rdi\n\t" "rolq $61, %%rdi ; rolq $51, %%rdi\n\t" "xchgq %%rbx,%%rbx" : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", "memory" ); _qzz_res = _zzq_result; (void)_qzz_res; }; }; | - | ||||||
| 163 | const qint64 result = QBenchmarkValgrindUtils::extractLastResult(); | - | ||||||
| 164 | return never executed: result;return result;never executed: return result; | 0 | ||||||
| 165 | } | - | ||||||
| 166 | - | |||||||
| 167 | qint64 QBenchmarkCallgrindMeasurer::stop() | - | ||||||
| 168 | { | - | ||||||
| 169 | return never executed: checkpoint();return checkpoint();never executed: return checkpoint(); | 0 | ||||||
| 170 | } | - | ||||||
| 171 | - | |||||||
| 172 | bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement) | - | ||||||
| 173 | { | - | ||||||
| 174 | (void)measurement;; | - | ||||||
| 175 | return never executed: true;return true;never executed: return true; | 0 | ||||||
| 176 | } | - | ||||||
| 177 | - | |||||||
| 178 | int QBenchmarkCallgrindMeasurer::adjustIterationCount(int) | - | ||||||
| 179 | { | - | ||||||
| 180 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 181 | } | - | ||||||
| 182 | - | |||||||
| 183 | int QBenchmarkCallgrindMeasurer::adjustMedianCount(int) | - | ||||||
| 184 | { | - | ||||||
| 185 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 186 | } | - | ||||||
| 187 | - | |||||||
| 188 | bool QBenchmarkCallgrindMeasurer::needsWarmupIteration() | - | ||||||
| 189 | { | - | ||||||
| 190 | return never executed: true;return true;never executed: return true; | 0 | ||||||
| 191 | } | - | ||||||
| 192 | - | |||||||
| 193 | QTest::QBenchmarkMetric QBenchmarkCallgrindMeasurer::metricType() | - | ||||||
| 194 | { | - | ||||||
| 195 | return never executed: QTest::InstructionReads;return QTest::InstructionReads;never executed: return QTest::InstructionReads; | 0 | ||||||
| 196 | } | - | ||||||
| 197 | - | |||||||
| 198 | - | |||||||
| Switch to Source code | Preprocessed file |