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 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 8 | #include <string> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 9 | #include <map> |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 10 | #include <set> |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 11 | #include <sstream> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | |
| 13 | #include "Instrument.hpp" |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 14 | #include "JsonUtils.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 15 | |
| 16 | namespace armnn |
| 17 | { |
| 18 | |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 19 | enum class JsonObjectType |
| 20 | { |
| 21 | Measurement, |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 22 | Event, |
| 23 | ExecObjectDesc |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 24 | }; |
| 25 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 26 | struct JsonChildObject |
| 27 | { |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 28 | // Object type changes according to the JsonObjectType specified in enum |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | JsonChildObject(const std::string& label) |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 30 | : m_Label(label), m_Unit(Measurement::Unit::TIME_MS), m_Type(JsonObjectType::Event) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 31 | {} |
| 32 | JsonChildObject(const JsonChildObject&) = default; |
| 33 | |
| 34 | void AddMeasurement(const double measurement) |
| 35 | { |
| 36 | m_Measurements.push_back(measurement); |
| 37 | } |
| 38 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 39 | void SetAndParseDetails(std::string layerDetailsStr) |
| 40 | { |
| 41 | std::stringstream layerDetails(layerDetailsStr); |
| 42 | std::string stringLine; |
| 43 | while (std::getline(layerDetails, stringLine, '\n')) |
| 44 | { |
| 45 | m_LayerDetailsList.push_back(stringLine); |
| 46 | } |
| 47 | } |
| 48 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | void AddChild(const JsonChildObject& childObject) |
| 50 | { |
| 51 | m_Children.push_back(childObject); |
| 52 | } |
| 53 | |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 54 | JsonChildObject& GetChild(const unsigned int index) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 55 | { |
| 56 | return m_Children[index]; |
| 57 | } |
| 58 | |
| 59 | void SetUnit(const Measurement::Unit unit) |
| 60 | { |
| 61 | m_Unit = unit; |
| 62 | } |
| 63 | |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 64 | size_t NumChildren() const |
| 65 | { |
| 66 | return m_Children.size(); |
| 67 | } |
| 68 | |
| 69 | void SetType(JsonObjectType type) |
| 70 | { |
| 71 | m_Type = type; |
| 72 | } |
| 73 | |
| 74 | JsonObjectType GetType() const |
| 75 | { |
| 76 | return m_Type; |
| 77 | } |
| 78 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 79 | ~JsonChildObject() = default; |
| 80 | |
| 81 | std::string m_Label; |
| 82 | Measurement::Unit m_Unit; |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 83 | JsonObjectType m_Type; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 84 | std::vector<double> m_Measurements; |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 85 | std::vector<std::string> m_LayerDetailsList; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 86 | std::vector<JsonChildObject> m_Children; |
| 87 | |
| 88 | private: |
| 89 | JsonChildObject() = delete; |
| 90 | }; |
| 91 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 92 | class JsonPrinter : public JsonUtils |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 93 | { |
| 94 | public: |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 95 | void PrintJsonChildObject(const JsonChildObject& object, size_t& id); |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 96 | void PrintLabel(const std::string& label, size_t id); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 97 | void PrintUnit(armnn::Measurement::Unit unit); |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 98 | void PrintType(armnn::JsonObjectType type); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 99 | void PrintMeasurementsList(const std::vector<double>& measurementsVector); |
| 100 | |
| 101 | public: |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 102 | JsonPrinter(std::ostream& outputStream) |
| 103 | : JsonUtils(outputStream), m_OutputStream(outputStream) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 104 | {} |
| 105 | |
| 106 | private: |
Derek Lamberti | 6b4dfc2 | 2019-08-07 17:01:57 +0100 | [diff] [blame] | 107 | std::string MakeKey(const std::string& label, size_t id); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 108 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame^] | 109 | std::ostream& m_OutputStream; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace armnn |