Skip to content

Commit

Permalink
Transmit the number of lost events in the LostDefinition
Browse files Browse the repository at this point in the history
This allows a more detailed report on the GUI side then. Because the
count has a quint64 type, we now use a QVariant to store the task
event payload. To reduce the padding overhead, the struct is slightly
reordered.

Change-Id: I01d16da2ba4d3df9f32d6ae53bcff120355eb2c9
  • Loading branch information
milianw committed Sep 25, 2020
1 parent a316f26 commit 80f3c62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions app/perfdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ class PerfRecordLost : public PerfRecord {
public:
PerfRecordLost(PerfEventHeader *header = nullptr, quint64 sampleType = 0,
bool sampleIdAll = false);

quint64 lost() const { return m_lost; }
private:
quint64 m_id;
quint64 m_lost;
Expand Down
19 changes: 11 additions & 8 deletions app/perfunwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void PerfUnwind::comm(const PerfRecordComm &comm)
const qint32 commId = resolveString(comm.comm());

bufferEvent(TaskEvent{comm.pid(), comm.tid(), comm.time(), comm.cpu(),
commId, Command},
Command, commId},
&m_taskEventsBuffer, &m_stats.numTaskEventsInRound);
}

Expand Down Expand Up @@ -294,7 +294,7 @@ void PerfUnwind::sendEventFormat(qint32 id, const EventFormat &format)
void PerfUnwind::lost(const PerfRecordLost &lost)
{
bufferEvent(TaskEvent{lost.pid(), lost.tid(), lost.time(), lost.cpu(),
0, LostDefinition},
LostDefinition, lost.lost()},
&m_taskEventsBuffer, &m_stats.numTaskEventsInRound);
}

Expand Down Expand Up @@ -684,14 +684,14 @@ void PerfUnwind::analyze(const PerfRecordSample &sample)
void PerfUnwind::fork(const PerfRecordFork &sample)
{
bufferEvent(TaskEvent{sample.childPid(), sample.childTid(), sample.time(), sample.cpu(),
sample.parentPid(), ThreadStart},
ThreadStart, sample.parentPid()},
&m_taskEventsBuffer, &m_stats.numTaskEventsInRound);
}

void PerfUnwind::exit(const PerfRecordExit &sample)
{
bufferEvent(TaskEvent{sample.childPid(), sample.childTid(), sample.time(), sample.cpu(),
0, ThreadEnd},
ThreadEnd, {}},
&m_taskEventsBuffer, &m_stats.numTaskEventsInRound);
}

Expand Down Expand Up @@ -950,7 +950,7 @@ void PerfUnwind::flushEventBuffer(uint desiredBufferSize)
if (taskEventIt->m_type == ThreadStart && taskEventIt->m_pid != taskEventIt->m_payload) {
forwardMmapBuffer(mmapIt, mmapEnd, taskEventIt->time());
const auto childPid = taskEventIt->m_pid;
const auto parentPid = taskEventIt->m_payload;
const auto parentPid = taskEventIt->m_payload.value<qint32>();
symbolTable(childPid)->initAfterFork(symbolTable(parentPid));
} else if (taskEventIt->m_type == ThreadEnd && taskEventIt->m_pid == taskEventIt->m_tid) {
delete m_symbolTables.take(taskEventIt->m_pid);
Expand Down Expand Up @@ -1025,7 +1025,8 @@ void PerfUnwind::contextSwitch(const PerfRecordContextSwitch& contextSwitch)
{
bufferEvent(TaskEvent{contextSwitch.pid(), contextSwitch.tid(),
contextSwitch.time(), contextSwitch.cpu(),
contextSwitch.misc() & PERF_RECORD_MISC_SWITCH_OUT, ContextSwitchDefinition},
ContextSwitchDefinition,
static_cast<bool>(contextSwitch.misc() & PERF_RECORD_MISC_SWITCH_OUT)},
&m_taskEventsBuffer, &m_stats.numTaskEventsInRound);
}

Expand All @@ -1038,9 +1039,11 @@ void PerfUnwind::sendTaskEvent(const TaskEvent& taskEvent)
<< taskEvent.m_time << taskEvent.m_cpu;

if (taskEvent.m_type == ContextSwitchDefinition)
stream << static_cast<bool>(taskEvent.m_payload);
stream << taskEvent.m_payload.value<bool>();
else if (taskEvent.m_type == Command || taskEvent.m_type == ThreadStart)
stream << taskEvent.m_payload;
stream << taskEvent.m_payload.value<qint32>();
else if (taskEvent.m_type == LostDefinition)
stream << taskEvent.m_payload.value<quint64>();

sendBuffer(buffer);
}
3 changes: 2 additions & 1 deletion app/perfunwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QObject>
#include <QString>
#include <QMap>
#include <QVariant>

#include <limits>

Expand Down Expand Up @@ -280,8 +281,8 @@ class PerfUnwind : public QObject
qint32 m_tid;
quint64 m_time;
quint32 m_cpu;
qint32 m_payload;
EventType m_type;
QVariant m_payload;

quint64 time() const { return m_time; }
quint64 size() const { return sizeof(TaskEvent); }
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/perfdata/tst_perfdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void TestPerfData::testTracingData()
QCOMPARE(stats.numBufferFlushes, flushes);
QCOMPARE(stats.numTimeViolatingSamples, 0u);
QCOMPARE(stats.numTimeViolatingMmaps, 0u);
QCOMPARE(stats.maxBufferSize, 15584u);
QCOMPARE(stats.maxBufferSize, 15608u);
QCOMPARE(stats.maxTime, maxTime);
return;
}
Expand Down

0 comments on commit 80f3c62

Please sign in to comment.