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