diff options
-rw-r--r-- | src/timelineDecoder/JSONTimelineDecoder.cpp | 13 | ||||
-rw-r--r-- | src/timelineDecoder/JSONTimelineDecoder.hpp | 8 | ||||
-rw-r--r-- | src/timelineDecoder/tests/JSONTimelineDecoderTests.cpp | 20 |
3 files changed, 21 insertions, 20 deletions
diff --git a/src/timelineDecoder/JSONTimelineDecoder.cpp b/src/timelineDecoder/JSONTimelineDecoder.cpp index a0392149ed..c0e81370ed 100644 --- a/src/timelineDecoder/JSONTimelineDecoder.cpp +++ b/src/timelineDecoder/JSONTimelineDecoder.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd. All rights reserved. +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -242,12 +242,10 @@ void JSONTimelineDecoder::JSONEntity::SetParent(JSONEntity& parent) parent.childEntities.push_back(GetGuid()); } -void JSONTimelineDecoder::PrintJSON(JSONTimelineDecoder::JSONEntity& rootEntity) +void JSONTimelineDecoder::PrintJSON(JSONTimelineDecoder::JSONEntity& rootEntity, std::ostream& os) { std::string jsonString = GetJSONString(rootEntity); - std::ofstream ofs{this->outputJSONFile}; - ofs << jsonString; - ofs.close(); + os << jsonString; } std::string JSONTimelineDecoder::GetJSONString(JSONTimelineDecoder::JSONEntity& rootEntity) @@ -377,11 +375,6 @@ const JSONTimelineDecoder::Model &JSONTimelineDecoder::GetModel() return m_Model; } -void JSONTimelineDecoder::SetOutgoingCaptureFile(const std::string& outgoingCaptureFile) -{ - this->outputJSONFile = outgoingCaptureFile; -} - void JSONTimelineDecoder::JSONEntity::SetName(std::string entityName) { this->name = entityName; diff --git a/src/timelineDecoder/JSONTimelineDecoder.hpp b/src/timelineDecoder/JSONTimelineDecoder.hpp index 4d6fcecebd..a6e2579b45 100644 --- a/src/timelineDecoder/JSONTimelineDecoder.hpp +++ b/src/timelineDecoder/JSONTimelineDecoder.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd. All rights reserved. +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -49,7 +49,7 @@ public: std::map<uint64_t, EventClass> eventClasses; }; - void PrintJSON(JSONEntity& entity); + void PrintJSON(JSONEntity& entity, std::ostream& os); std::string GetJSONString(JSONEntity& rootEntity); std::string GetJSONEntityString(JSONEntity& entity, int& counter); @@ -60,13 +60,9 @@ public: virtual TimelineStatus CreateRelationship(const Relationship&) override; const Model& GetModel(); - void SetOutgoingCaptureFile(const std::string& basicString); private: Model m_Model; - fs::path p = armnnUtils::Filesystem::NamedTempFile("output.json"); - - std::string outputJSONFile = p.string(); void HandleRetentionLink(const Relationship& relationship); void HandleLabelLink(const Relationship& relationship); diff --git a/src/timelineDecoder/tests/JSONTimelineDecoderTests.cpp b/src/timelineDecoder/tests/JSONTimelineDecoderTests.cpp index 82414192f2..3961f9bfb5 100644 --- a/src/timelineDecoder/tests/JSONTimelineDecoderTests.cpp +++ b/src/timelineDecoder/tests/JSONTimelineDecoderTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd. All rights reserved. +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -795,14 +795,23 @@ BOOST_AUTO_TEST_CASE(JSONTimelineDecoderTestJSON) BOOST_CHECK(jsonString.find("normalization_2: {")!=std::string::npos); BOOST_CHECK(jsonString.find("output_4: {")!=std::string::npos); - timelineDecoder.PrintJSON(rootEntity); + // Create a temporary file to write Json output to + fs::path tempFile = armnnUtils::Filesystem::NamedTempFile("JSONTimelineDecoderTestJSON.json"); + // open temp file + std::ofstream ofs{tempFile}; + // tell the timeline decoder to print into our temp file (you could also use std::cout) + timelineDecoder.PrintJSON(rootEntity, ofs); + // close temp file + ofs.close(); + // Now everything in opposite order fs::ifstream inFile; - fs::path p{fs::temp_directory_path() / "output.json"}; - inFile.open(p); //open the input file + //reopen the file this time for reading + inFile.open(tempFile); std::stringstream strStream; strStream << inFile.rdbuf(); //read the file + inFile.close(); std::string outfileJson = strStream.str(); BOOST_CHECK(outfileJson != ""); @@ -811,5 +820,8 @@ BOOST_AUTO_TEST_CASE(JSONTimelineDecoderTestJSON) "\t\t\tbackendId :CpuRef,")!=std::string::npos); BOOST_CHECK(outfileJson.find("normalization_2: {")!=std::string::npos); BOOST_CHECK(outfileJson.find("output_4: {")!=std::string::npos); + + // Remove temporary file + fs::remove(tempFile); } BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file |