diff options
author | Derek Lamberti <derek.lamberti@arm.com> | 2019-08-07 17:01:57 +0100 |
---|---|---|
committer | Derek Lamberti <derek.lamberti@arm.com> | 2019-08-09 12:17:50 +0000 |
commit | 6b4dfc2df9271b2e9e0b9e0e0a78f715ddebf36e (patch) | |
tree | 7fe9cc2e8b023cb138e5e2af07feeec7c3857dc4 /src/armnn/JsonPrinter.cpp | |
parent | 3d8a9eda15c7732c689a80ddde916d6e3373542c (diff) | |
download | armnn-6b4dfc2df9271b2e9e0b9e0e0a78f715ddebf36e.tar.gz |
IVGCVSW-3603 *Json printer prints full profiling hierarchy
Change-Id: Ide5acbf993c2bcff5265b72fc979caa6f183bb22
Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
Diffstat (limited to 'src/armnn/JsonPrinter.cpp')
-rw-r--r-- | src/armnn/JsonPrinter.cpp | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/src/armnn/JsonPrinter.cpp b/src/armnn/JsonPrinter.cpp index 97cd5f2b4b..9dc648c538 100644 --- a/src/armnn/JsonPrinter.cpp +++ b/src/armnn/JsonPrinter.cpp @@ -7,25 +7,41 @@ #include <iomanip> #include <iostream> +#include <sstream> namespace armnn { -void JsonPrinter::PrintJsonChildObject(const JsonChildObject& object) +void JsonPrinter::PrintJsonChildObject(const JsonChildObject& object, size_t& id) { - PrintLabel(object.m_Label); - PrintMeasurementsList(object.m_Measurements); - PrintSeparator(); - PrintNewLine(); - PrintUnit(object.m_Unit); + if (object.GetType() == JsonObjectType::Event) + { + // Increase the Id for new events. This ensures a new event has a unique ID and any measurements belonging + // to the event have the same id. This id is appended to the name during the call to PrintLabel() below. + id++; + } - if (!object.m_Children.empty()) + PrintLabel(object.m_Label, id); + PrintType(object.m_Type); + + if (!object.m_Measurements.empty() || !object.m_Children.empty()) { PrintSeparator(); PrintNewLine(); + } + + if (object.GetType() == JsonObjectType::Measurement) + { + PrintMeasurementsList(object.m_Measurements); + PrintSeparator(); + PrintNewLine(); + PrintUnit(object.m_Unit); + } + if (!object.m_Children.empty()) + { for (unsigned int childIndex = 0; childIndex < object.m_Children.size(); ++childIndex) { - PrintJsonChildObject(object.m_Children[childIndex]); + PrintJsonChildObject(object.m_Children[childIndex], id); // Only print separator and new line if current child is not the last element. if (&object.m_Children[childIndex] != &object.m_Children.back()) { @@ -51,10 +67,17 @@ void JsonPrinter::PrintArmNNHeader() IncrementNumberOfTabs(); } -void JsonPrinter::PrintLabel(const std::string& label) +std::string JsonPrinter::MakeKey(const std::string& label, size_t id) +{ + std::stringstream ss; + ss << label << std::string("_#") << id; + return ss.str(); +} + +void JsonPrinter::PrintLabel(const std::string& label, size_t id) { PrintTabs(); - m_OutputStream << R"(")" << label << R"(": {)" << std::endl; + m_OutputStream << R"(")" << MakeKey(label, id) << R"(": {)" << std::endl; IncrementNumberOfTabs(); } @@ -66,6 +89,33 @@ void JsonPrinter::PrintUnit(armnn::Measurement::Unit unit) m_OutputStream << R"(")"; } +void JsonPrinter::PrintType(armnn::JsonObjectType type) +{ + auto ToString = [](armnn::JsonObjectType type) + { + switch (type) + { + case JsonObjectType::Measurement: + { + return "Measurement"; + } + case JsonObjectType::Event: + { + return "Event"; + } + default: + { + return "Unknown"; + } + } + }; + PrintTabs(); + m_OutputStream << R"("type": ")"; + m_OutputStream << ToString(type); + m_OutputStream << R"(")"; +} + + void JsonPrinter::PrintMeasurementsList(const std::vector<double>& measurementsVector) { if (measurementsVector.empty()) |