blob: 4af1609ee36b7ece6e128d86ffbda59d3a8c698a [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
6#pragma once
7
Keith Davis554fa092021-07-20 11:25:22 +01008#include <string>
telsoa01c577f2c2018-08-31 09:22:23 +01009#include <map>
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010010#include <set>
Keith Davis554fa092021-07-20 11:25:22 +010011#include <sstream>
telsoa01c577f2c2018-08-31 09:22:23 +010012
13#include "Instrument.hpp"
Keith Davis554fa092021-07-20 11:25:22 +010014#include "JsonUtils.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +010015
16namespace armnn
17{
18
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010019enum class JsonObjectType
20{
21 Measurement,
Keith Davis554fa092021-07-20 11:25:22 +010022 Event,
23 ExecObjectDesc
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010024};
25
telsoa01c577f2c2018-08-31 09:22:23 +010026struct JsonChildObject
27{
Keith Davis554fa092021-07-20 11:25:22 +010028 // Object type changes according to the JsonObjectType specified in enum
telsoa01c577f2c2018-08-31 09:22:23 +010029 JsonChildObject(const std::string& label)
Keith Davis554fa092021-07-20 11:25:22 +010030 : m_Label(label), m_Unit(Measurement::Unit::TIME_MS), m_Type(JsonObjectType::Event)
telsoa01c577f2c2018-08-31 09:22:23 +010031 {}
32 JsonChildObject(const JsonChildObject&) = default;
33
34 void AddMeasurement(const double measurement)
35 {
36 m_Measurements.push_back(measurement);
37 }
38
Keith Davis554fa092021-07-20 11:25:22 +010039 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
telsoa01c577f2c2018-08-31 09:22:23 +010049 void AddChild(const JsonChildObject& childObject)
50 {
51 m_Children.push_back(childObject);
52 }
53
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010054 JsonChildObject& GetChild(const unsigned int index)
telsoa01c577f2c2018-08-31 09:22:23 +010055 {
56 return m_Children[index];
57 }
58
59 void SetUnit(const Measurement::Unit unit)
60 {
61 m_Unit = unit;
62 }
63
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010064 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
telsoa01c577f2c2018-08-31 09:22:23 +010079 ~JsonChildObject() = default;
80
81 std::string m_Label;
82 Measurement::Unit m_Unit;
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010083 JsonObjectType m_Type;
telsoa01c577f2c2018-08-31 09:22:23 +010084 std::vector<double> m_Measurements;
Keith Davis554fa092021-07-20 11:25:22 +010085 std::vector<std::string> m_LayerDetailsList;
telsoa01c577f2c2018-08-31 09:22:23 +010086 std::vector<JsonChildObject> m_Children;
87
88private:
89 JsonChildObject() = delete;
90};
91
Keith Davis554fa092021-07-20 11:25:22 +010092class JsonPrinter : public JsonUtils
telsoa01c577f2c2018-08-31 09:22:23 +010093{
94public:
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010095 void PrintJsonChildObject(const JsonChildObject& object, size_t& id);
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010096 void PrintLabel(const std::string& label, size_t id);
telsoa01c577f2c2018-08-31 09:22:23 +010097 void PrintUnit(armnn::Measurement::Unit unit);
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010098 void PrintType(armnn::JsonObjectType type);
telsoa01c577f2c2018-08-31 09:22:23 +010099 void PrintMeasurementsList(const std::vector<double>& measurementsVector);
100
101public:
Keith Davis554fa092021-07-20 11:25:22 +0100102 JsonPrinter(std::ostream& outputStream)
103 : JsonUtils(outputStream), m_OutputStream(outputStream)
telsoa01c577f2c2018-08-31 09:22:23 +0100104 {}
105
106private:
Derek Lamberti6b4dfc22019-08-07 17:01:57 +0100107 std::string MakeKey(const std::string& label, size_t id);
telsoa01c577f2c2018-08-31 09:22:23 +0100108
Keith Davis554fa092021-07-20 11:25:22 +0100109 std::ostream& m_OutputStream;
telsoa01c577f2c2018-08-31 09:22:23 +0100110};
111
112} // namespace armnn