PerfProfiler: Various style issues

Don't use else after return, initialize variables, cast enum to int when
comparing with an int, delete copy and move ctors and assignment
operators for QDataStream-derived classes.

Change-Id: If4c0e55cc458283c4bef3f819738a285f260a3dc
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2019-01-07 14:28:08 +01:00
parent 327fed3d19
commit dec9b7eb04
3 changed files with 29 additions and 19 deletions

View File

@@ -68,9 +68,8 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const
auto meta = QMetaEnum::fromType<EventType>();
return QString::fromLatin1(meta.valueToKey(description.eventType))
.mid(static_cast<int>(strlen("EventType"))).toLower();
} else {
return description.eventType;
}
return description.eventType;
}
case ColumnSubType: {
switch (description.eventType) {
@@ -79,8 +78,7 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const
case EventTypeCache:
if (role == Qt::DisplayRole)
return subTypeString(description.eventType, description.subType);
else
return description.subType;
return description.subType;
case EventTypeRaw:
if (role == Qt::DisplayRole)
return QString("r%1").arg(description.numericEvent, 3, 16, QLatin1Char('0'));
@@ -108,18 +106,20 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const
if (description.operation & OperationExecute)
result += 'x';
return result;
} else if (description.eventType == EventTypeCache) {
}
if (description.eventType == EventTypeCache) {
if (description.operation == OperationInvalid)
return QVariant();
auto meta = QMetaEnum::fromType<Operation>();
return QString::fromLatin1(meta.valueToKey(description.operation)).mid(
static_cast<int>(strlen("Operation"))).toLower();
} else {
return QVariant();
}
} else {
return description.operation;
return QVariant();
}
return description.operation;
case ColumnResult:
if (role == Qt::DisplayRole) {
if (description.result == ResultInvalid)
@@ -127,9 +127,8 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const
auto meta = QMetaEnum::fromType<Result>();
return QString::fromLatin1(meta.valueToKey(description.result)).mid(
static_cast<int>(strlen("Result"))).toLower();
} else {
return description.result;
}
return description.result;
default:
return QVariant();
}
@@ -352,7 +351,9 @@ PerfConfigEventsModel::EventDescription PerfConfigEventsModel::parseEvent(
}
}
return description;
} else if (event.startsWith('r') && event.length() == 4) {
}
if (event.startsWith('r') && event.length() == 4) {
bool ok = false;
const uint eventNumber = event.mid(1).toUInt(&ok, 16);
if (ok) {
@@ -385,9 +386,9 @@ PerfConfigEventsModel::EventDescription PerfConfigEventsModel::parseEvent(
if (subtype != -1) {
description.subType = SubType(subtype);
if (subtype < SubTypeEventTypeSoftware)
if (subtype < int(SubTypeEventTypeSoftware))
description.eventType = EventTypeHardware;
else if (subtype < SubTypeEventTypeCache)
else if (subtype < int(SubTypeEventTypeCache))
description.eventType = EventTypeSoftware;
else
description.eventType = EventTypeCache;

View File

@@ -271,11 +271,12 @@ qint64 PerfDataReader::adjustTimestamp(qint64 timestamp)
+ m_localProcessStart;
}
return timestamp - m_remoteProcessStart;
} else if (m_remoteProcessStart != std::numeric_limits<qint64>::max()) {
return m_remoteProcessStart;
} else {
return -1;
}
if (m_remoteProcessStart != std::numeric_limits<qint64>::max())
return m_remoteProcessStart;
return -1;
}
bool PerfDataReader::acceptsSamples() const

View File

@@ -133,7 +133,7 @@ struct PerfFeatures
PerfNrCpus nrCpus;
QByteArray cpuDesc;
QByteArray cpuId;
quint64 totalMem;
quint64 totalMem = 0;
QList<QByteArray> cmdline;
QList<PerfBuildId> buildIds;
PerfCpuTopology cpuTopology;
@@ -336,6 +336,7 @@ void PerfProfilerTraceFile::load(QIODevice *file)
}
class Packet : public QDataStream {
Q_DISABLE_COPY(Packet)
public:
Packet(QDataStream *parent) :
QDataStream(&m_content, QIODevice::WriteOnly), m_parent(parent)
@@ -347,12 +348,16 @@ public:
(*m_parent) << m_content;
}
Packet(Packet &&) = delete;
Packet &operator=(Packet &&) = delete;
private:
QByteArray m_content;
QDataStream *m_parent;
};
class CompressedDataStream : public QDataStream {
Q_DISABLE_COPY(CompressedDataStream)
public:
CompressedDataStream(QIODevice *device) :
QDataStream(&m_content, QIODevice::WriteOnly), m_device(device)
@@ -364,6 +369,9 @@ public:
flush();
}
CompressedDataStream(CompressedDataStream &&) = delete;
CompressedDataStream &operator=(CompressedDataStream &&) = delete;
void flush()
{
if (!m_device.isNull() && !m_content.isEmpty()) {