summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2019-09-27 11:23:58 +0200
committerMilian Wolff <milian.wolff@kdab.com>2019-09-30 07:43:52 +0000
commit5753a53b1fe184113d2a6448c90184617d1f68f4 (patch)
tree525da427f017bd5cf3e90940d47a1ece30c19f5b
parent4f78ea2a4fa3c1030e4045280f8113b9322d7c8c (diff)
Make perf2text code reusable for other auto tests
Change-Id: I4f716890cdf87385faf0019bec69fdddcd22c6df Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--tests/auto/shared/perfparsertestclient.cpp43
-rw-r--r--tests/auto/shared/perfparsertestclient.h6
-rw-r--r--tests/manual/perf2text/perf2text.cpp45
3 files changed, 52 insertions, 42 deletions
diff --git a/tests/auto/shared/perfparsertestclient.cpp b/tests/auto/shared/perfparsertestclient.cpp
index ac45c28..82eed31 100644
--- a/tests/auto/shared/perfparsertestclient.cpp
+++ b/tests/auto/shared/perfparsertestclient.cpp
@@ -20,6 +20,7 @@
#include "perffeatures.h"
#include "perfparsertestclient.h"
+#include <QTextStream>
#include <QtEndian>
#ifdef MANUAL_TEST
@@ -187,3 +188,45 @@ void PerfParserTestClient::extractTrace(QIODevice *device)
QVERIFY(stream.atEnd());
}
}
+
+void PerfParserTestClient::convertToText(QTextStream &out) const
+{
+ for (const auto &sample : samples()) {
+ out << string(command(sample.pid).name) << '\t'
+ << sample.pid << '\t' << sample.tid << '\t'
+ << sample.time / 1000000000 << '.' << qSetFieldWidth(9) << qSetPadChar(QLatin1Char('0'))
+ << sample.time % 1000000000 << qSetFieldWidth(0) << qSetPadChar(QLatin1Char(' ')) << '\n';
+ for (const auto &value : sample.values) {
+ const auto attribute = this->attribute(value.first);
+ const auto cost = attribute.usesFrequency ? value.second : attribute.frequencyOrPeriod;
+ out << '\t' << string(attribute.name) << ": ";
+ if (attribute.type == 2) {
+ const auto format = tracePointFormat(static_cast<qint32>(attribute.config));
+ out << string(format.system) << ' ' << string(format.name) << ' ' << hex << format.flags << dec << '\n';
+ for (auto it = sample.tracePointData.begin(); it != sample.tracePointData.end(); ++it) {
+ out << "\t\t" << string(it.key()) << '=' << it.value().toString() << '\n';
+ }
+ } else {
+ out << cost << '\n';
+ }
+ }
+ out << '\n';
+ auto printFrame = [&out, this](qint32 locationId) -> qint32 {
+ const auto location = this->location(locationId);
+ out << '\t' << hex << location.address << dec;
+ const auto symbol = this->symbol(locationId);
+ if (location.file != -1)
+ out << '\t' << string(location.file) << ':' << location.line << ':' << location.column;
+ if (symbol.path != -1)
+ out << '\t' << string(symbol.name) << ' ' << string(symbol.binary) << ' ' << string(symbol.path) << ' ' << (symbol.isKernel ? "[kernel]" : "");
+ out << '\n';
+ return location.parentLocationId;
+ };
+ for (const auto &frame : sample.frames) {
+ auto locationId = printFrame(frame);
+ while (locationId != -1)
+ locationId = printFrame(locationId);
+ }
+ out << '\n';
+ }
+}
diff --git a/tests/auto/shared/perfparsertestclient.h b/tests/auto/shared/perfparsertestclient.h
index 8e6b7d5..468d7ae 100644
--- a/tests/auto/shared/perfparsertestclient.h
+++ b/tests/auto/shared/perfparsertestclient.h
@@ -25,6 +25,8 @@
#include <QVariant>
#include <QVector>
+class QTextStream;
+
class PerfParserTestClient : public QObject
{
Q_OBJECT
@@ -113,7 +115,9 @@ public:
LocationEvent location(qint32 id) const { return m_locations.value(id); }
SymbolEvent symbol(qint32 id) const { return m_symbols.value(id); }
- TracePointFormatEvent tracePointFormat(qint32 id) { return m_tracePointFormats.value(id); }
+ TracePointFormatEvent tracePointFormat(qint32 id) const { return m_tracePointFormats.value(id); }
+
+ void convertToText(QTextStream &output) const;
private:
QVector<QByteArray> m_strings;
diff --git a/tests/manual/perf2text/perf2text.cpp b/tests/manual/perf2text/perf2text.cpp
index e57082f..d77f518 100644
--- a/tests/manual/perf2text/perf2text.cpp
+++ b/tests/manual/perf2text/perf2text.cpp
@@ -39,7 +39,6 @@ int main(int argc, char **argv)
args.removeFirst();
QProcess process;
- PerfParserTestClient client;
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
QObject::connect(&process, &QProcess::errorOccurred, &app, [&process](QProcess::ProcessError error) {
qWarning() << "perfparser process error:" << error << process.errorString();
@@ -53,47 +52,11 @@ int main(int argc, char **argv)
if (!process.waitForStarted() || !process.waitForFinished())
return 1;
- client.extractTrace(&process);
-
QTextStream out(stdout);
- for (const auto &sample : client.samples()) {
- out << client.string(client.command(sample.pid).name) << '\t'
- << sample.pid << '\t' << sample.tid << '\t'
- << sample.time / 1000000000 << '.' << qSetFieldWidth(9) << qSetPadChar(QLatin1Char('0'))
- << sample.time % 1000000000 << qSetFieldWidth(0) << qSetPadChar(QLatin1Char(' ')) << '\n';
- for (const auto &value : sample.values) {
- const auto attribute = client.attribute(value.first);
- const auto cost = attribute.usesFrequency ? value.second : attribute.frequencyOrPeriod;
- out << '\t' << client.string(attribute.name) << ": ";
- if (attribute.type == 2) {
- const auto format = client.tracePointFormat(static_cast<qint32>(attribute.config));
- out << client.string(format.system) << ' ' << client.string(format.name) << ' ' << hex << format.flags << dec << '\n';
- for (auto it = sample.tracePointData.begin(); it != sample.tracePointData.end(); ++it) {
- out << "\t\t" << client.string(it.key()) << '=' << it.value().toString() << '\n';
- }
- } else {
- out << cost << '\n';
- }
- }
- out << '\n';
- auto printFrame = [&out, &client](qint32 locationId) -> qint32 {
- const auto location = client.location(locationId);
- out << '\t' << hex << location.address << dec;
- const auto symbol = client.symbol(locationId);
- if (location.file != -1)
- out << '\t' << client.string(location.file) << ':' << location.line << ':' << location.column;
- if (symbol.path != -1)
- out << '\t' << client.string(symbol.name) << ' ' << client.string(symbol.binary) << ' ' << client.string(symbol.path) << ' ' << (symbol.isKernel ? "[kernel]" : "");
- out << '\n';
- return location.parentLocationId;
- };
- for (const auto &frame : sample.frames) {
- auto locationId = printFrame(frame);
- while (locationId != -1)
- locationId = printFrame(locationId);
- }
- out << '\n';
- }
+
+ PerfParserTestClient client;
+ client.extractTrace(&process);
+ client.convertToText(out);
return 0;
}