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

View File

@@ -271,11 +271,12 @@ qint64 PerfDataReader::adjustTimestamp(qint64 timestamp)
+ m_localProcessStart; + m_localProcessStart;
} }
return timestamp - m_remoteProcessStart; 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 bool PerfDataReader::acceptsSamples() const

View File

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