| 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 process.waitForStarted() && process.waitForFinished(-1); | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | } | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | - | |||||||||||||
| 20 | - | |||||||||||||
| 21 | bool QBenchmarkValgrindUtils::rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode) | - | ||||||||||||
| 22 | { | - | ||||||||||||
| 23 | if (!QBenchmarkValgrindUtils::runCallgrindSubProcess(origAppArgs, exitCode)) { | - | ||||||||||||
| 24 | QMessageLogger(__FILE__, 6571, __PRETTY_FUNCTION__).warning("failed to run callgrind subprocess"); | - | ||||||||||||
| 25 | return false; | - | ||||||||||||
| 26 | } | - | ||||||||||||
| 27 | return true; | - | ||||||||||||
| 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 | } | - | ||||||||||||
| 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__,8288) : 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__,9197) : qt_noop()); | - | ||||||||||||
| 51 | bool ok; | - | ||||||||||||
| 52 | val = rxValue.cap(1).toLongLong(&ok); | - | ||||||||||||
| 53 | ((!(ok)) ? qt_assert("ok",__FILE__,94100) : qt_noop()); | - | ||||||||||||
| 54 | valSeen = true; | - | ||||||||||||
| 55 |             break; never executed:  break; | 0 | ||||||||||||
| 56 | } | - | ||||||||||||
| 57 |     } never executed:  end of block | 0 | ||||||||||||
| 58 |     if (!(__builtin_expect(!!(!
 
  | 0 | ||||||||||||
| 59 |         QMessageLogger(__FILE__, 100106, __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__,109115) : 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__,113119) : 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 (QForeachContainer<typename QtPrivate::remove_reference<decltype(fiList)>::type> _container_((fiList)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QFileInfo &fileInfo = *_container_.i; _container_.control; _container_.control = 0: fiList) { | - | ||||||||||||
| 78 | const int index = rx.indexIn(fileInfo.fileName()); | - | ||||||||||||
| 79 | ((!(index == 0)) ? qt_assert("index == 0",__FILE__,120126) : qt_noop()); | - | ||||||||||||
| 80 | (void)index;; | - | ||||||||||||
| 81 | bool ok; | - | ||||||||||||
| 82 | const int suffix = rx.cap(1).toInt(&ok); | - | ||||||||||||
| 83 | ((!(ok)) ? qt_assert("ok",__FILE__,124130) : qt_noop()); | - | ||||||||||||
| 84 | ((!(suffix >= 0)) ? qt_assert("suffix >= 0",__FILE__,125131) : 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 extractResult(getNewestFileName()); | - | ||||||||||||
| 97 | } | - | ||||||||||||
| 98 | - | |||||||||||||
| 99 | void QBenchmarkValgrindUtils::cleanup() | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | QStringList nameFilters; | - | ||||||||||||
| 102 | QString base = QBenchmarkGlobalData::current->callgrindOutFileBase; | - | ||||||||||||
| 103 | ((!(!base.isEmpty())) ? qt_assert("!base.isEmpty()",__FILE__,144150) : 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 (QForeachContainer<typename QtPrivate::remove_reference<decltype(fiList)>::type> _container_((fiList)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QFileInfo &fileInfo = *_container_.i; _container_.control; _container_.control = 0: fiList) { | - | ||||||||||||
| 109 | const bool removeOk = QFile::remove(fileInfo.fileName()); | - | ||||||||||||
| 110 | ((!(removeOk)) ? qt_assert("removeOk",__FILE__,151157) : 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 QString::fromLatin1("callgrind.out.%1").arg( | - | ||||||||||||
| 118 | pid != -1 ? pid : QCoreApplication::applicationPid()); | - | ||||||||||||
| 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(); ++i) { | - | ||||||||||||
| 135 | const QString arg(origAppArgs.at(i)); | - | ||||||||||||
| 136 | if (arg == QLatin1String("-callgrind")) | - | ||||||||||||
| 137 | continue; | - | ||||||||||||
| 138 | args << arg; | - | ||||||||||||
| 139 | } | - | ||||||||||||
| 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 finishedOk; | - | ||||||||||||
| 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 | } | - | ||||||||||||
| 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 result; | - | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | qint64 QBenchmarkCallgrindMeasurer::stop() | - | ||||||||||||
| 168 | { | - | ||||||||||||
| 169 | return checkpoint(); | - | ||||||||||||
| 170 | } | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement) | - | ||||||||||||
| 173 | { | - | ||||||||||||
| 174 | (void)measurement;; | - | ||||||||||||
| 175 | return true; | - | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | int QBenchmarkCallgrindMeasurer::adjustIterationCount(int) | - | ||||||||||||
| 179 | { | - | ||||||||||||
| 180 | return 1; | - | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | int QBenchmarkCallgrindMeasurer::adjustMedianCount(int) | - | ||||||||||||
| 184 | { | - | ||||||||||||
| 185 | return 1; | - | ||||||||||||
| 186 | } | - | ||||||||||||
| 187 | - | |||||||||||||
| 188 | bool QBenchmarkCallgrindMeasurer::needsWarmupIteration() | - | ||||||||||||
| 189 | { | - | ||||||||||||
| 190 | return true; | - | ||||||||||||
| 191 | } | - | ||||||||||||
| 192 | - | |||||||||||||
| 193 | QTest::QBenchmarkMetric QBenchmarkCallgrindMeasurer::metricType() | - | ||||||||||||
| 194 | { | - | ||||||||||||
| 195 | return QTest::InstructionReads; | - | ||||||||||||
| 196 | } | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | - | |||||||||||||
| Switch to Source code | Preprocessed file |