qbenchmarkvalgrind.cpp

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

Generated by Squish Coco Non-Commercial