qbenchmarkvalgrind.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/testlib/qbenchmarkvalgrind.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8bool QBenchmarkValgrindUtils::haveValgrind()-
9{-
10-
11-
12-
13 QProcess process;-
14 process.start(QLatin1String("valgrind"), QStringList(QLatin1String("--version")));-
15 return
never executed: return process.waitForStarted() && process.waitForFinished(-1);
process.waitForStarted() && process.waitForFinished(-1);
never executed: return process.waitForStarted() && process.waitForFinished(-1);
0
16-
17}-
18-
19-
20-
21bool QBenchmarkValgrindUtils::rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode)-
22{-
23 if (!QBenchmarkValgrindUtils::runCallgrindSubProcess(origAppArgs, exitCode)
!QBenchmarkVal...rgs, exitCode)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
24 QMessageLogger(__FILE__, 71, __PRETTY_FUNCTION__).warning("failed to run callgrind subprocess");-
25 return
never executed: return false;
false;
never executed: return false;
0
26 }-
27 return
never executed: return true;
true;
never executed: return true;
0
28}-
29-
30static 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-
37qint64 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()
!file.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
48 const QString line(QLatin1String(file.readLine()));-
49 if (rxValue.indexIn(line) != -1
rxValue.indexIn(line) != -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
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)
__builtin_expe...lSeen), false)Description
TRUEnever evaluated
FALSEnever evaluated
)
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: return val;
val;
never executed: return val;
0
61}-
62-
63-
64QString 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
suffix > hiSuffixDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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: return lastFileInfo.fileName();
lastFileInfo.fileName();
never executed: return lastFileInfo.fileName();
0
92}-
93-
94qint64 QBenchmarkValgrindUtils::extractLastResult()-
95{-
96 return
never executed: return extractResult(getNewestFileName());
extractResult(getNewestFileName());
never executed: return extractResult(getNewestFileName());
0
97}-
98-
99void 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-
115QString QBenchmarkValgrindUtils::outFileBase(qint64 pid)-
116{-
117 return
never executed: return QString::fromLatin1("callgrind.out.%1").arg( pid != -1 ? pid : QCoreApplication::applicationPid());
QString::fromLatin1("callgrind.out.%1").arg(
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-
124bool 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 < origAppArgs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
135 const QString arg(origAppArgs.at(i));-
136 if (arg == QLatin1String("-callgrind")
arg == QLatin1...("-callgrind")Description
TRUEnever evaluated
FALSEnever evaluated
)
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: return finishedOk;
finishedOk;
never executed: return finishedOk;
0
153}-
154-
155void 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-
160qint64 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: return result;
result;
never executed: return result;
0
165}-
166-
167qint64 QBenchmarkCallgrindMeasurer::stop()-
168{-
169 return
never executed: return checkpoint();
checkpoint();
never executed: return checkpoint();
0
170}-
171-
172bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement)-
173{-
174 (void)measurement;;-
175 return
never executed: return true;
true;
never executed: return true;
0
176}-
177-
178int QBenchmarkCallgrindMeasurer::adjustIterationCount(int)-
179{-
180 return
never executed: return 1;
1;
never executed: return 1;
0
181}-
182-
183int QBenchmarkCallgrindMeasurer::adjustMedianCount(int)-
184{-
185 return
never executed: return 1;
1;
never executed: return 1;
0
186}-
187-
188bool QBenchmarkCallgrindMeasurer::needsWarmupIteration()-
189{-
190 return
never executed: return true;
true;
never executed: return true;
0
191}-
192-
193QTest::QBenchmarkMetric QBenchmarkCallgrindMeasurer::metricType()-
194{-
195 return
never executed: return QTest::InstructionReads;
QTest::InstructionReads;
never executed: return QTest::InstructionReads;
0
196}-
197-
198-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9