From baa68e95a6c0f4df1ab04aa7cecefe95d360c691 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 18 May 2018 16:48:24 +0200 Subject: Send auxiliary timestamped messages in order with samples Having a common chronological ordering between all timestamped events, at least most of the time, makes it so much less painful to process the stream on the client side. Change-Id: I8531a9b66c599c1c35688ad907ab403a41c11ba6 Reviewed-by: Tobias Hunger --- app/perfunwind.cpp | 16 ++++++++++++---- app/perfunwind.h | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/perfunwind.cpp b/app/perfunwind.cpp index 179ea7e..0bf5e5a 100644 --- a/app/perfunwind.cpp +++ b/app/perfunwind.cpp @@ -134,6 +134,8 @@ PerfUnwind::~PerfUnwind() { finishedRound(); flushEventBuffer(0); + for (const QByteArray &aux : qAsConst(m_auxBuffer)) + sendBuffer(aux); delete[] m_debugInfoPath; qDeleteAll(m_symbolTables); @@ -207,7 +209,7 @@ void PerfUnwind::comm(const PerfRecordComm &comm) QDataStream(&buffer, QIODevice::WriteOnly) << static_cast(Command) << comm.pid() << comm.tid() << comm.time() << commId; - sendBuffer(buffer); + m_auxBuffer.insert(comm.time(), buffer); } void PerfUnwind::attr(const PerfRecordAttr &attr) @@ -266,7 +268,7 @@ void PerfUnwind::lost(const PerfRecordLost &lost) QByteArray buffer; QDataStream(&buffer, QIODevice::WriteOnly) << static_cast(LostDefinition) << lost.pid() << lost.tid() << lost.time(); - sendBuffer(buffer); + m_auxBuffer.insert(lost.time(), buffer); } void PerfUnwind::features(const PerfFeatures &features) @@ -601,6 +603,12 @@ void PerfUnwind::analyze(const PerfRecordSample &sample) } } + for (auto it = m_auxBuffer.begin(); + it != m_auxBuffer.end() && it.key() < sample.time(); + it = m_auxBuffer.erase(it)) { + sendBuffer(it.value()); + } + QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); stream << static_cast(type) << sample.pid() @@ -628,7 +636,7 @@ void PerfUnwind::fork(const PerfRecordFork &sample) QDataStream(&buffer, QIODevice::WriteOnly) << static_cast(ThreadStart) << sample.childPid() << sample.childTid() << sample.time(); - sendBuffer(buffer); + m_auxBuffer.insert(sample.time(), buffer); } void PerfUnwind::exit(const PerfRecordExit &sample) @@ -637,7 +645,7 @@ void PerfUnwind::exit(const PerfRecordExit &sample) QDataStream(&buffer, QIODevice::WriteOnly) << static_cast(ThreadEnd) << sample.childPid() << sample.childTid() << sample.time(); - sendBuffer(buffer); + m_auxBuffer.insert(sample.time(), buffer); } void PerfUnwind::sendString(qint32 id, const QByteArray& string) diff --git a/app/perfunwind.h b/app/perfunwind.h index b5bff8b..34f80e7 100644 --- a/app/perfunwind.h +++ b/app/perfunwind.h @@ -34,7 +34,7 @@ #include #include #include - +#include #include @@ -267,6 +267,7 @@ private: QString m_kallsymsPath; bool m_ignoreKallsymsBuildId; + QMultiMap m_auxBuffer; QList m_sampleBuffer; QList m_mmapBuffer; QHash m_symbolTables; -- cgit v1.2.3