blob: 04f56b013405a66c82d5d0bc1f43e75410e02275 [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
8#include <ostream>
9#include <string.h>
10#include <map>
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010011#include <set>
telsoa01c577f2c2018-08-31 09:22:23 +010012
13#include "Instrument.hpp"
14
15namespace armnn
16{
17
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010018enum class JsonObjectType
19{
20 Measurement,
21 Event
22};
23
telsoa01c577f2c2018-08-31 09:22:23 +010024struct JsonChildObject
25{
26 JsonChildObject(const std::string& label)
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010027 : m_Label(label), m_Unit(Measurement::Unit::TIME_MS), m_Type(JsonObjectType::Event)
telsoa01c577f2c2018-08-31 09:22:23 +010028 {}
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 Lamberti6b4dfc22019-08-07 17:01:57 +010041 JsonChildObject& GetChild(const unsigned int index)
telsoa01c577f2c2018-08-31 09:22:23 +010042 {
43 return m_Children[index];
44 }
45
46 void SetUnit(const Measurement::Unit unit)
47 {
48 m_Unit = unit;
49 }
50
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010051 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
telsoa01c577f2c2018-08-31 09:22:23 +010066 ~JsonChildObject() = default;
67
68 std::string m_Label;
69 Measurement::Unit m_Unit;
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010070 JsonObjectType m_Type;
telsoa01c577f2c2018-08-31 09:22:23 +010071 std::vector<double> m_Measurements;
72 std::vector<JsonChildObject> m_Children;
73
74private:
75 JsonChildObject() = delete;
76};
77
78class JsonPrinter
79{
80public:
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010081 void PrintJsonChildObject(const JsonChildObject& object, size_t& id);
telsoa01c577f2c2018-08-31 09:22:23 +010082 void PrintHeader();
83 void PrintArmNNHeader();
84 void PrintFooter();
85 void PrintSeparator();
86 void PrintNewLine();
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010087 void PrintLabel(const std::string& label, size_t id);
telsoa01c577f2c2018-08-31 09:22:23 +010088 void PrintUnit(armnn::Measurement::Unit unit);
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010089 void PrintType(armnn::JsonObjectType type);
telsoa01c577f2c2018-08-31 09:22:23 +010090 void PrintMeasurementsList(const std::vector<double>& measurementsVector);
91
92public:
93 JsonPrinter(std::ostream &outputStream)
94 : m_OutputStream(outputStream), m_NumTabs(0)
95 {}
96
97private:
Derek Lamberti6b4dfc22019-08-07 17:01:57 +010098 std::string MakeKey(const std::string& label, size_t id);
telsoa01c577f2c2018-08-31 09:22:23 +010099 void PrintTabs();
100 void DecrementNumberOfTabs();
101 void IncrementNumberOfTabs();
102
103 std::ostream &m_OutputStream;
104 unsigned int m_NumTabs;
105};
106
107} // namespace armnn