telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <ostream> |
| 9 | #include <string.h> |
| 10 | #include <map> |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 11 | #include <set> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | |
| 13 | #include "Instrument.hpp" |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 18 | enum class JsonObjectType |
| 19 | { |
| 20 | Measurement, |
| 21 | Event |
| 22 | }; |
| 23 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | struct JsonChildObject |
| 25 | { |
| 26 | JsonChildObject(const std::string& label) |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 27 | : m_Label(label), m_Unit(Measurement::Unit::TIME_MS), m_Type(JsonObjectType::Event) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 28 | {} |
| 29 | JsonChildObject(const JsonChildObject&) = default; |
| 30 | |
| 31 | void AddMeasurement(const double measurement) |
| 32 | { |
| 33 | m_Measurements.push_back(measurement); |
| 34 | } |
| 35 | |
| 36 | void AddChild(const JsonChildObject& childObject) |
| 37 | { |
| 38 | m_Children.push_back(childObject); |
| 39 | } |
| 40 | |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 41 | JsonChildObject& GetChild(const unsigned int index) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 42 | { |
| 43 | return m_Children[index]; |
| 44 | } |
| 45 | |
| 46 | void SetUnit(const Measurement::Unit unit) |
| 47 | { |
| 48 | m_Unit = unit; |
| 49 | } |
| 50 | |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 51 | size_t NumChildren() const |
| 52 | { |
| 53 | return m_Children.size(); |
| 54 | } |
| 55 | |
| 56 | void SetType(JsonObjectType type) |
| 57 | { |
| 58 | m_Type = type; |
| 59 | } |
| 60 | |
| 61 | JsonObjectType GetType() const |
| 62 | { |
| 63 | return m_Type; |
| 64 | } |
| 65 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 66 | ~JsonChildObject() = default; |
| 67 | |
| 68 | std::string m_Label; |
| 69 | Measurement::Unit m_Unit; |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 70 | JsonObjectType m_Type; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 71 | std::vector<double> m_Measurements; |
| 72 | std::vector<JsonChildObject> m_Children; |
| 73 | |
| 74 | private: |
| 75 | JsonChildObject() = delete; |
| 76 | }; |
| 77 | |
| 78 | class JsonPrinter |
| 79 | { |
| 80 | public: |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 81 | void PrintJsonChildObject(const JsonChildObject& object, size_t& id); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 82 | void PrintHeader(); |
| 83 | void PrintArmNNHeader(); |
| 84 | void PrintFooter(); |
| 85 | void PrintSeparator(); |
| 86 | void PrintNewLine(); |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 87 | void PrintLabel(const std::string& label, size_t id); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 88 | void PrintUnit(armnn::Measurement::Unit unit); |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 89 | void PrintType(armnn::JsonObjectType type); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 90 | void PrintMeasurementsList(const std::vector<double>& measurementsVector); |
| 91 | |
| 92 | public: |
| 93 | JsonPrinter(std::ostream &outputStream) |
| 94 | : m_OutputStream(outputStream), m_NumTabs(0) |
| 95 | {} |
| 96 | |
| 97 | private: |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame^] | 98 | std::string MakeKey(const std::string& label, size_t id); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 99 | void PrintTabs(); |
| 100 | void DecrementNumberOfTabs(); |
| 101 | void IncrementNumberOfTabs(); |
| 102 | |
| 103 | std::ostream &m_OutputStream; |
| 104 | unsigned int m_NumTabs; |
| 105 | }; |
| 106 | |
| 107 | } // namespace armnn |