PerfProfiler: Guard against some malformed input

If there is no attribute we actually set the attribute to be the invalid
one. Therefore an entry for the invalid attribute should exist. Also,
cycles in the parent location IDs need to be avoided.

Change-Id: Id1962744ef476ddad737cf108d9f9ab83a4eaf55
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
This commit is contained in:
Ulf Hermann
2019-05-03 15:44:49 +02:00
parent 63beec8921
commit d0839bc1de
4 changed files with 12 additions and 1 deletions

View File

@@ -51,7 +51,7 @@ public:
ThreadEndTypeId = -3,
LostTypeId = -4,
ContextSwitchTypeId = -5,
LastSpecialTypeId = -256
LastSpecialTypeId = -6
};
int numAttributes() const { return m_values.length() + 1; }

View File

@@ -143,6 +143,7 @@ public:
case ThreadEnd:
case LostDefinition:
case ContextSwitchDefinition:
case InvalidFeature:
return true;
default:
return false;

View File

@@ -177,6 +177,14 @@ void PerfProfilerTraceFile::readMessages(const QByteArray &buffer)
case PerfEventType::LocationDefinition: {
PerfEventType location(PerfEventType::LocationDefinition);
dataStream >> id >> location;
for (int parent = location.location().parentLocationId; parent != -1;
parent = traceManager->location(parent).parentLocationId) {
if (parent == id) {
qWarning() << "A location cannot be its own parent location:" << id;
location = PerfEventType(PerfEventType::LocationDefinition);
break;
}
}
traceManager->setEventType(id, std::move(location));
break;
}

View File

@@ -219,6 +219,8 @@ void PerfProfilerTraceManager::resetAttributes()
tr("Samples lost")));
setEventType(PerfEvent::ContextSwitchTypeId,
PerfEventType(PerfEventType::ContextSwitchDefinition, tr("Context switch")));
setEventType(PerfEvent::LastSpecialTypeId,
PerfEventType(PerfEventType::InvalidFeature, tr("Invalid")));
}
void PerfProfilerTraceManager::finalize()