diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 21:29:42 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 21:29:42 +0100 |
commit | 93b406d1914a5512aec6ca737ba8326a21191227 (patch) | |
tree | 0f869f201815ae862bc2853de0b2007ff1515bf1 | |
parent | ae7cc26c8350b427870f83687f83184c2c211250 (diff) | |
download | sink-93b406d1914a5512aec6ca737ba8326a21191227.tar.gz sink-93b406d1914a5512aec6ca737ba8326a21191227.zip |
HAWD: Ensure the column order is maintained
By turning the columns into an array instead of an object,
we can print the values in the same order as in the definition file.
Previosly the order was random, and even headers and values were
somtimes mixed up.
-rw-r--r-- | hawd_defs/buffer_creation | 10 | ||||
-rw-r--r-- | hawd_defs/storage_readwrite | 12 | ||||
-rw-r--r-- | tests/hawd/dataset.cpp | 43 | ||||
-rw-r--r-- | tests/hawd/dataset.h | 2 | ||||
-rw-r--r-- | tests/hawd/datasetdefinition.cpp | 11 | ||||
-rw-r--r-- | tests/hawd/datasetdefinition.h | 4 | ||||
-rw-r--r-- | tests/hawd/modules/list.cpp | 6 |
7 files changed, 43 insertions, 45 deletions
diff --git a/hawd_defs/buffer_creation b/hawd_defs/buffer_creation index 16c1f8c..38426d3 100644 --- a/hawd_defs/buffer_creation +++ b/hawd_defs/buffer_creation | |||
@@ -1,9 +1,9 @@ | |||
1 | { | 1 | { |
2 | "name": "Buffer Creation", | 2 | "name": "Buffer Creation", |
3 | "description": "Tests how fast buffer creation is", | 3 | "description": "Tests how fast buffer creation is", |
4 | "columns": { | 4 | "columns": [ |
5 | "numBuffers": { "type": "int" }, | 5 | { "name: "numBuffers", "type": "int" }, |
6 | "time": { "type": "int", "unit": "ms", "min": 0, "max": 100 }, | 6 | { "name: "time", "type": "int", "unit": "ms", "min": 0, "max": 100 }, |
7 | "ops": { "type": "float", "unit": "ops/ms" } | 7 | { "name: "ops", "type": "float", "unit": "ops/ms" } |
8 | } | 8 | ] |
9 | } | 9 | } |
diff --git a/hawd_defs/storage_readwrite b/hawd_defs/storage_readwrite index 4b5f6c7..d2504e3 100644 --- a/hawd_defs/storage_readwrite +++ b/hawd_defs/storage_readwrite | |||
@@ -1,10 +1,10 @@ | |||
1 | { | 1 | { |
2 | "name": "Storage Read/Write Performance", | 2 | "name": "Storage Read/Write Performance", |
3 | "description": "Measures performance of the storage class by writing and reading non-trivial datasets", | 3 | "description": "Measures performance of the storage class by writing and reading non-trivial datasets", |
4 | "columns": { | 4 | "columns": [ |
5 | "rows": { "type": "int" }, | 5 | { "name": "rows", "type": "int" }, |
6 | "dbWrite": { "type": "float", "unit": "ops/ms" }, | 6 | { "name": "dbWrite", "type": "float", "unit": "ops/ms" }, |
7 | "fileWrite": { "type": "float", "unit": "ops/ms" }, | 7 | { "name": "fileWrite", "type": "float", "unit": "ops/ms" }, |
8 | "dbRead": { "type": "float", "unit": "ops/ms" } | 8 | { "name": "dbRead", "type": "float", "unit": "ops/ms" } |
9 | } | 9 | ] |
10 | } | 10 | } |
diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp index 585406b..93eb5cd 100644 --- a/tests/hawd/dataset.cpp +++ b/tests/hawd/dataset.cpp | |||
@@ -49,10 +49,8 @@ Dataset::Row::Row(const Dataset &dataset, qint64 key) | |||
49 | m_dataset(&dataset) | 49 | m_dataset(&dataset) |
50 | { | 50 | { |
51 | // TODO: pre-populate m_data, or do that on buffer creation? | 51 | // TODO: pre-populate m_data, or do that on buffer creation? |
52 | QHashIterator<QString, DataDefinition> it(dataset.definition().columns()); | 52 | for (const auto &colum : dataset.definition().columns()) { |
53 | while (it.hasNext()) { | 53 | m_data.insert(colum.first, QVariant()); |
54 | it.next(); | ||
55 | m_data.insert(it.key(), QVariant()); | ||
56 | } | 54 | } |
57 | } | 55 | } |
58 | 56 | ||
@@ -67,13 +65,16 @@ Dataset::Row &Dataset::Row::operator=(const Row &rhs) | |||
67 | return *this; | 65 | return *this; |
68 | } | 66 | } |
69 | 67 | ||
70 | void Dataset::Row::setValue(const QString &column, const QVariant &value) | 68 | void Dataset::Row::setValue(const QString &col, const QVariant &value) |
71 | { | 69 | { |
72 | if (!m_columns.contains(column) || !value.canConvert(m_columns[column].type())) { | 70 | for (const auto &column : m_columns) { |
73 | return; | 71 | if (column.first == col) { |
72 | if (value.canConvert(column.second.type())) { | ||
73 | m_data[col] = value; | ||
74 | } | ||
75 | return; | ||
76 | } | ||
74 | } | 77 | } |
75 | |||
76 | m_data[column] = value; | ||
77 | } | 78 | } |
78 | 79 | ||
79 | void Dataset::Row::annotate(const QString ¬e) | 80 | void Dataset::Row::annotate(const QString ¬e) |
@@ -158,13 +159,11 @@ QString Dataset::tableHeaders(const QStringList &cols, int standardCols, const Q | |||
158 | strings << QObject::tr("Commit").leftJustified(s_fieldWidth, ' '); | 159 | strings << QObject::tr("Commit").leftJustified(s_fieldWidth, ' '); |
159 | } | 160 | } |
160 | 161 | ||
161 | QHashIterator<QString, DataDefinition> it(m_definition.columns()); | 162 | for (const auto &column : m_definition.columns()) { |
162 | while (it.hasNext()) { | 163 | QString header = column.first; |
163 | it.next(); | ||
164 | QString header = it.key(); | ||
165 | if (cols.isEmpty() || cols.contains(header)) { | 164 | if (cols.isEmpty() || cols.contains(header)) { |
166 | if (!it.value().unit().isEmpty()) { | 165 | if (!column.second.unit().isEmpty()) { |
167 | header.append(" (").append(it.value().unit()).append(")"); | 166 | header.append(" (").append(column.second.unit()).append(")"); |
168 | } | 167 | } |
169 | strings << header.leftJustified(s_fieldWidth, ' '); | 168 | strings << header.leftJustified(s_fieldWidth, ' '); |
170 | } | 169 | } |
@@ -195,14 +194,14 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const | |||
195 | strings << m_commitHash.leftJustified(s_fieldWidth, ' '); | 194 | strings << m_commitHash.leftJustified(s_fieldWidth, ' '); |
196 | } | 195 | } |
197 | 196 | ||
198 | QHashIterator<QString, QVariant> it(m_data); | 197 | for (const auto &column : m_columns) { |
199 | while (it.hasNext()) { | 198 | const auto key = column.first; |
200 | it.next(); | 199 | if (cols.isEmpty() || cols.contains(key)) { |
201 | if (cols.isEmpty() || cols.contains(it.key())) { | 200 | const auto value = m_data.value(key); |
202 | if (it.value().canConvert<double>()) { | 201 | if (value.canConvert<double>()) { |
203 | strings << QString("%1").arg(it.value().toDouble(), s_fieldWidth, 'f', 3); | 202 | strings << QString("%1").arg(value.toDouble(), s_fieldWidth, 'f', 3); |
204 | } else { | 203 | } else { |
205 | strings << it.value().toString().leftJustified(s_fieldWidth, ' '); | 204 | strings << value.toString().leftJustified(s_fieldWidth, ' '); |
206 | } | 205 | } |
207 | } | 206 | } |
208 | } | 207 | } |
diff --git a/tests/hawd/dataset.h b/tests/hawd/dataset.h index cf84d7b..cdfd3f2 100644 --- a/tests/hawd/dataset.h +++ b/tests/hawd/dataset.h | |||
@@ -60,7 +60,7 @@ public: | |||
60 | void fromBinary(QByteArray binary); | 60 | void fromBinary(QByteArray binary); |
61 | 61 | ||
62 | qint64 m_key; | 62 | qint64 m_key; |
63 | QHash<QString, DataDefinition> m_columns; | 63 | QList<QPair<QString, DataDefinition> > m_columns; |
64 | QHash<QString, QVariant> m_data; | 64 | QHash<QString, QVariant> m_data; |
65 | QString m_annotation; | 65 | QString m_annotation; |
66 | QString m_commitHash; | 66 | QString m_commitHash; |
diff --git a/tests/hawd/datasetdefinition.cpp b/tests/hawd/datasetdefinition.cpp index a4a95dd..e2af2b9 100644 --- a/tests/hawd/datasetdefinition.cpp +++ b/tests/hawd/datasetdefinition.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <QFile> | 25 | #include <QFile> |
26 | #include <QJsonDocument> | 26 | #include <QJsonDocument> |
27 | #include <QJsonObject> | 27 | #include <QJsonObject> |
28 | #include <QJsonArray> | ||
28 | 29 | ||
29 | #include <iostream> | 30 | #include <iostream> |
30 | 31 | ||
@@ -119,11 +120,11 @@ DatasetDefinition::DatasetDefinition(const QString &path) | |||
119 | } | 120 | } |
120 | 121 | ||
121 | m_description = json.value("description").toString(); | 122 | m_description = json.value("description").toString(); |
122 | QJsonObject cols = json.value("columns").toObject(); | 123 | auto cols = json.value("columns").toArray(); |
123 | for (const QString &key: cols.keys()) { | 124 | for (const auto &entry: cols) { |
124 | QJsonObject def = cols.value(key).toObject(); | 125 | QJsonObject def = entry.toObject(); |
125 | if (!def.isEmpty()) { | 126 | if (!def.isEmpty()) { |
126 | m_columns.insert(key, DataDefinition(def)); | 127 | m_columns << qMakePair(def.value("name").toString(), DataDefinition(def)); |
127 | } | 128 | } |
128 | } | 129 | } |
129 | } | 130 | } |
@@ -152,7 +153,7 @@ QString DatasetDefinition::description() const | |||
152 | return m_description; | 153 | return m_description; |
153 | } | 154 | } |
154 | 155 | ||
155 | QHash<QString, DataDefinition> DatasetDefinition::columns() const | 156 | QList<QPair<QString, DataDefinition> > DatasetDefinition::columns() const |
156 | { | 157 | { |
157 | return m_columns; | 158 | return m_columns; |
158 | } | 159 | } |
diff --git a/tests/hawd/datasetdefinition.h b/tests/hawd/datasetdefinition.h index cf1a797..6c844ba 100644 --- a/tests/hawd/datasetdefinition.h +++ b/tests/hawd/datasetdefinition.h | |||
@@ -60,14 +60,14 @@ public: | |||
60 | QString lastError() const; | 60 | QString lastError() const; |
61 | QString name() const; | 61 | QString name() const; |
62 | QString description() const; | 62 | QString description() const; |
63 | QHash<QString, DataDefinition> columns() const; | 63 | QList<QPair<QString, DataDefinition> > columns() const; |
64 | 64 | ||
65 | private: | 65 | private: |
66 | bool m_valid; | 66 | bool m_valid; |
67 | QString m_name; | 67 | QString m_name; |
68 | QString m_description; | 68 | QString m_description; |
69 | QString m_lastError; | 69 | QString m_lastError; |
70 | QHash<QString, DataDefinition> m_columns; | 70 | QList<QPair<QString, DataDefinition> > m_columns; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | } // namespace HAWD | 73 | } // namespace HAWD |
diff --git a/tests/hawd/modules/list.cpp b/tests/hawd/modules/list.cpp index efb000b..aa80126 100644 --- a/tests/hawd/modules/list.cpp +++ b/tests/hawd/modules/list.cpp | |||
@@ -60,10 +60,8 @@ bool List::list(const QStringList &commands, State &state) | |||
60 | if (dataset.isValid()) { | 60 | if (dataset.isValid()) { |
61 | DatasetDefinition dataset(project.absoluteFilePath(file)); | 61 | DatasetDefinition dataset(project.absoluteFilePath(file)); |
62 | std::cout << '\t' << QObject::tr("Dataset: %1").arg(dataset.name()).toStdString() << std::endl; | 62 | std::cout << '\t' << QObject::tr("Dataset: %1").arg(dataset.name()).toStdString() << std::endl; |
63 | QHashIterator<QString, DataDefinition> it(dataset.columns()); | 63 | for (const auto &column : dataset.columns()) { |
64 | while (it.hasNext()) { | 64 | std::cout << "\t\t" << column.second.typeString().toStdString() << ' ' << column.first.toStdString() << std::endl; |
65 | it.next(); | ||
66 | std::cout << "\t\t" << it.value().typeString().toStdString() << ' ' << it.key().toStdString() << std::endl; | ||
67 | } | 65 | } |
68 | } else { | 66 | } else { |
69 | std::cout << QObject::tr("Problem with dataset %1. Check with 'check' command.").arg(file).toStdString() << std::endl; | 67 | std::cout << QObject::tr("Problem with dataset %1. Check with 'check' command.").arg(file).toStdString() << std::endl; |