From a0687eef149fbf57bb6db0621ec65724f550b1ed Mon Sep 17 00:00:00 2001 From: Isabella Gottardi Date: Wed, 11 Mar 2020 18:04:20 +0000 Subject: MLECO-755: ArmNN: Add file format external profiling option * Added new m_FileFormat variable in ExternalProfilingOptions * Added new profiling option to ExecuteNetwork * Added check for file format in ProfilingConnectionFactory * Added test in profiling tests Change-Id: I0e9cb8ecac919dc0ed03dcf77324a65621f07ae7 Signed-off-by: Isabella Gottardi --- src/profiling/ProfilingConnectionFactory.cpp | 6 +++++ src/profiling/test/ProfilingTests.cpp | 37 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'src/profiling') diff --git a/src/profiling/ProfilingConnectionFactory.cpp b/src/profiling/ProfilingConnectionFactory.cpp index 4af81a024e..1d264def57 100644 --- a/src/profiling/ProfilingConnectionFactory.cpp +++ b/src/profiling/ProfilingConnectionFactory.cpp @@ -18,6 +18,12 @@ namespace profiling std::unique_ptr ProfilingConnectionFactory::GetProfilingConnection( const Runtime::CreationOptions::ExternalProfilingOptions& options) const { + // Before proceed to create the IProfilingConnection, check if the file format is supported + if (!(options.m_FileFormat == "binary")) + { + throw armnn::UnimplementedException("Unsupported profiling file format, only binary is supported"); + } + // We can create 3 different types of IProfilingConnection. // 1: If no relevant options are specified then a SocketProfilingConnection is returned. // 2: If both incoming and outgoing capture files are specified then a SocketProfilingConnection decorated by a diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index 29c5299bd3..a631cb2356 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -3448,4 +3448,41 @@ BOOST_AUTO_TEST_CASE(CheckRegisterCounters) BOOST_TEST(93 == readValue); } +BOOST_AUTO_TEST_CASE(CheckFileFormat) { + // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output + LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); + + // Create profiling options. + armnn::Runtime::CreationOptions::ExternalProfilingOptions options; + options.m_EnableProfiling = true; + // Check the default value set to binary + BOOST_CHECK(options.m_FileFormat == "binary"); + + // Change file format to an unsupported value + options.m_FileFormat = "json"; + // Enable the profiling service + armnn::profiling::ProfilingService profilingService; + profilingService.ResetExternalProfilingOptions(options, true); + // Start the command handler and the send thread + profilingService.Update(); + BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::NotConnected); + + // Redirect the output to a local stream so that we can parse the warning message + std::stringstream ss; + StreamRedirector streamRedirector(std::cout, ss.rdbuf()); + + // When Update is called and the current state is ProfilingState::NotConnected + // an exception will be raised from GetProfilingConnection and displayed as warning in the output local stream + profilingService.Update(); + + streamRedirector.CancelRedirect(); + + // Check that the expected error has occurred and logged to the standard output + if (!boost::contains(ss.str(), "Unsupported profiling file format, only binary is supported")) + { + std::cout << ss.str(); + BOOST_FAIL("Expected string not found."); + } +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1