diff options
author | telsoa01 <telmo.soares@arm.com> | 2018-08-31 09:22:23 +0100 |
---|---|---|
committer | telsoa01 <telmo.soares@arm.com> | 2018-08-31 09:22:23 +0100 |
commit | c577f2c6a3b4ddb6ba87a882723c53a248afbeba (patch) | |
tree | bd7d4c148df27f8be6649d313efb24f536b7cf34 /src/armnn/JsonPrinter.cpp | |
parent | 4c7098bfeab1ffe1cdc77f6c15548d3e73274746 (diff) | |
download | armnn-c577f2c6a3b4ddb6ba87a882723c53a248afbeba.tar.gz |
Release 18.08
Diffstat (limited to 'src/armnn/JsonPrinter.cpp')
-rw-r--r-- | src/armnn/JsonPrinter.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/armnn/JsonPrinter.cpp b/src/armnn/JsonPrinter.cpp new file mode 100644 index 0000000000..f7c1c68758 --- /dev/null +++ b/src/armnn/JsonPrinter.cpp @@ -0,0 +1,134 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include "JsonPrinter.hpp" + +#include <iomanip> +#include <iostream> + +namespace armnn +{ + +void JsonPrinter::PrintJsonChildObject(const JsonChildObject& object) +{ + PrintLabel(object.m_Label); + PrintMeasurementsList(object.m_Measurements); + PrintSeparator(); + PrintNewLine(); + PrintUnit(object.m_Unit); + + if (!object.m_Children.empty()) + { + PrintSeparator(); + PrintNewLine(); + for (unsigned int childIndex = 0; childIndex < object.m_Children.size(); ++childIndex) + { + PrintJsonChildObject(object.m_Children[childIndex]); + // Only print separator and new line if current child is not the last element. + if (&object.m_Children[childIndex] != &object.m_Children.back()) + { + PrintSeparator(); + PrintNewLine(); + } + } + } + PrintNewLine(); + PrintFooter(); +} + +void JsonPrinter::PrintHeader() +{ + m_OutputStream << "{" << std::endl; + IncrementNumberOfTabs(); +} + +void JsonPrinter::PrintArmNNHeader() +{ + PrintTabs(); + m_OutputStream << R"("ArmNN": {)" << std::endl; + IncrementNumberOfTabs(); +} + +void JsonPrinter::PrintLabel(const std::string& label) +{ + PrintTabs(); + m_OutputStream << R"(")" << label << R"(": {)" << std::endl; + IncrementNumberOfTabs(); +} + +void JsonPrinter::PrintUnit(armnn::Measurement::Unit unit) +{ + PrintTabs(); + m_OutputStream << R"("unit": ")"; + m_OutputStream << armnn::Measurement::ToString(unit); + m_OutputStream << R"(")"; +} + +void JsonPrinter::PrintMeasurementsList(const std::vector<double>& measurementsVector) +{ + if (measurementsVector.empty()) + { + return; + } + + PrintTabs(); + m_OutputStream << R"("raw": [)" << std::endl; + IncrementNumberOfTabs(); + PrintTabs(); + auto iter = measurementsVector.begin(); + m_OutputStream << *iter; + for (iter = std::next(iter); iter != measurementsVector.end(); ++iter) + { + m_OutputStream << "," << std::endl; + PrintTabs(); + m_OutputStream << *iter; + } + m_OutputStream << std::endl; + DecrementNumberOfTabs(); + PrintTabs(); + m_OutputStream << "]"; +} + +void JsonPrinter::PrintTabs() +{ + unsigned int numTabs = m_NumTabs; + while (numTabs-- > 0) + { + m_OutputStream << "\t"; + } +} + +void JsonPrinter::PrintSeparator() +{ + m_OutputStream << ","; +} + +void JsonPrinter::PrintNewLine() +{ + m_OutputStream << std::endl; +} + +void JsonPrinter::PrintFooter() +{ + DecrementNumberOfTabs(); + PrintTabs(); + m_OutputStream << "}"; +} + +void JsonPrinter::DecrementNumberOfTabs() +{ + if (m_NumTabs == 0) + { + return; + } + --m_NumTabs; +} + +void JsonPrinter::IncrementNumberOfTabs() +{ + ++m_NumTabs; +} + +} // namespace armnn
\ No newline at end of file |