IVGCVSW-4722 Add missing m_TimelineEnabled bool to ConnectionAcknowledgedCommandHandler
authorFinn Williams <Finn.Williams@arm.com>
Thu, 23 Apr 2020 16:55:18 +0000 (17:55 +0100)
committerJim Flynn <jim.flynn@arm.com>
Mon, 27 Apr 2020 09:06:24 +0000 (09:06 +0000)
 * Added timeline bool to ConnectionAcknowledgedCommandHandler
 * Added option to enable timeline profiling in ExecuteNetwork
 * Added CommandHandler stub to allow gatordMock to ignore packets

Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I314f9411e0079cba8f103d3b8a89f2bf38bb21ab

CMakeLists.txt
src/profiling/ConnectionAcknowledgedCommandHandler.cpp
src/profiling/ConnectionAcknowledgedCommandHandler.hpp
src/profiling/ProfilingService.cpp
src/timelineDecoder/TimelineDecoder.cpp
tests/ExecuteNetwork/ExecuteNetwork.cpp
tests/profiling/gatordmock/GatordMockService.hpp
tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp
tests/profiling/gatordmock/StubCommandHandler.hpp [new file with mode: 0644]
tests/profiling/gatordmock/tests/GatordMockTests.cpp

index f744785..8f3aa03 100644 (file)
@@ -1019,6 +1019,7 @@ if(BUILD_GATORD_MOCK)
         tests/profiling/gatordmock/PeriodicCounterSelectionResponseHandler.hpp
         tests/profiling/gatordmock/StreamMetadataCommandHandler.cpp
         tests/profiling/gatordmock/StreamMetadataCommandHandler.hpp
+        tests/profiling/gatordmock/StubCommandHandler.hpp
         )
 
     include_directories(src/profiling tests/profiling tests/profiling/gatordmock src/timelineDecoder)
index 995562f..7690573 100644 (file)
@@ -40,8 +40,12 @@ void ConnectionAcknowledgedCommandHandler::operator()(const Packet& packet)
         m_StateMachine.TransitionToState(ProfilingState::Active);
         // Send the counter directory packet.
         m_SendCounterPacket.SendCounterDirectoryPacket(m_CounterDirectory);
-        m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
-        TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
+
+        if (m_TimelineEnabled)
+        {
+            m_SendTimelinePacket.SendTimelineMessageDirectoryPackage();
+            TimelineUtilityMethods::SendWellKnownLabelsAndEventClasses(m_SendTimelinePacket);
+        }
 
         if(m_BackendProfilingContext.has_value())
         {
index e2bdff8..053d3c3 100644 (file)
@@ -44,12 +44,18 @@ public:
 
     void operator()(const Packet& packet) override;
 
+    void setTimelineEnabled(bool timelineEnabled)
+    {
+        m_TimelineEnabled = timelineEnabled;
+    }
+
 private:
     const ICounterDirectory& m_CounterDirectory;
     ISendCounterPacket&      m_SendCounterPacket;
     ISendTimelinePacket&     m_SendTimelinePacket;
     ProfilingStateMachine&   m_StateMachine;
     Optional<BackendProfilingContexts> m_BackendProfilingContext;
+    bool m_TimelineEnabled = false;
 };
 
 } // namespace profiling
index 4d7241e..d87ed0b 100644 (file)
@@ -35,6 +35,7 @@ void ProfilingService::ResetExternalProfilingOptions(const ExternalProfilingOpti
     // Update the profiling options
     m_Options = options;
     m_TimelineReporting = options.m_TimelineEnabled;
+    m_ConnectionAcknowledgedCommandHandler.setTimelineEnabled(options.m_TimelineEnabled);
 
     // Check if the profiling service needs to be reset
     if (resetProfilingService)
index f7f4663..9aa84d2 100644 (file)
@@ -151,6 +151,13 @@ void TimelineDecoder::SetDefaultCallbacks()
 
 void TimelineDecoder::print()
 {
+    if (m_Model.m_Labels.empty() && m_Model.m_Entities.empty() && m_Model.m_EventClasses.empty() &&
+        m_Model.m_Events.empty() && m_Model.m_Relationships.empty())
+    {
+        std::cout << "No timeline packets received" << std::endl;
+        return;
+    }
+
     printLabels();
     printEntities();
     printEventClasses();
index 9252a46..7dc9b65 100644 (file)
@@ -109,6 +109,8 @@ int main(int argc, const char* argv[])
              "If this option is enabled, the output of every graph layer will be printed.")
             ("enable-external-profiling,a", po::bool_switch()->default_value(false),
              "If enabled external profiling will be switched on")
+            ("timeline-profiling", po::bool_switch()->default_value(false),
+             "If enabled timeline profiling will be switched on, requires external profiling")
             ("outgoing-capture-file,j", po::value(&outgoingCaptureFile),
              "If specified the outgoing external profiling packets will be captured in this binary file")
             ("incoming-capture-file,k", po::value(&incomingCaptureFile),
@@ -168,6 +170,7 @@ int main(int argc, const char* argv[])
     bool enableExternalProfiling = vm["enable-external-profiling"].as<bool>();
     bool fileOnlyExternalProfiling = vm["file-only-external-profiling"].as<bool>();
     bool parseUnsupported = vm["parse-unsupported"].as<bool>();
+    bool timelineEnabled = vm["timeline-profiling"].as<bool>();
 
     if (enableBf16TurboMode && enableFp16TurboMode)
     {
@@ -175,6 +178,23 @@ int main(int argc, const char* argv[])
         return EXIT_FAILURE;
     }
 
+    // Create runtime
+    armnn::IRuntime::CreationOptions options;
+    options.m_EnableGpuProfiling                     = enableProfiling;
+    options.m_DynamicBackendsPath                    = dynamicBackendsPath;
+    options.m_ProfilingOptions.m_EnableProfiling     = enableExternalProfiling;
+    options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile;
+    options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
+    options.m_ProfilingOptions.m_FileOnly            = fileOnlyExternalProfiling;
+    options.m_ProfilingOptions.m_CapturePeriod       = counterCapturePeriod;
+    options.m_ProfilingOptions.m_FileFormat          = fileFormat;
+    options.m_ProfilingOptions.m_TimelineEnabled     = timelineEnabled;
+
+    if (timelineEnabled && !enableExternalProfiling)
+    {
+        ARMNN_LOG(fatal) << "Timeline profiling requires external profiling to be turned on";
+        return EXIT_FAILURE;
+    }
 
     // Check whether we have to load test cases from a file.
     if (CheckOption(vm, "test-cases"))
@@ -196,17 +216,7 @@ int main(int argc, const char* argv[])
             ARMNN_LOG(fatal) << "Given file \"" << testCasesFile << "\" has no test cases";
             return EXIT_FAILURE;
         }
-
         // Create runtime
-        armnn::IRuntime::CreationOptions options;
-        options.m_EnableGpuProfiling                     = enableProfiling;
-        options.m_DynamicBackendsPath                    = dynamicBackendsPath;
-        options.m_ProfilingOptions.m_EnableProfiling     = enableExternalProfiling;
-        options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile;
-        options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
-        options.m_ProfilingOptions.m_FileOnly            = fileOnlyExternalProfiling;
-        options.m_ProfilingOptions.m_CapturePeriod       = counterCapturePeriod;
-        options.m_ProfilingOptions.m_FileFormat          = fileFormat;
         std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options));
 
         const std::string executableName("ExecuteNetwork");
@@ -276,15 +286,6 @@ int main(int argc, const char* argv[])
             return EXIT_FAILURE;
         }
         // Create runtime
-        armnn::IRuntime::CreationOptions options;
-        options.m_EnableGpuProfiling                     = enableProfiling;
-        options.m_DynamicBackendsPath                    = dynamicBackendsPath;
-        options.m_ProfilingOptions.m_EnableProfiling     = enableExternalProfiling;
-        options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile;
-        options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile;
-        options.m_ProfilingOptions.m_FileOnly            = fileOnlyExternalProfiling;
-        options.m_ProfilingOptions.m_CapturePeriod       = counterCapturePeriod;
-        options.m_ProfilingOptions.m_FileFormat          = fileFormat;
         std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options));
 
         return RunTest(modelFormat, inputTensorShapes, computeDevices, dynamicBackendsPath, modelPath, inputNames,
index 9b72f72..232d256 100644 (file)
@@ -21,6 +21,7 @@
 #include "StreamMetadataCommandHandler.hpp"
 
 #include "PacketVersionResolver.hpp"
+#include "StubCommandHandler.hpp"
 
 namespace armnn
 {
@@ -56,10 +57,12 @@ public:
             , m_PacketVersionResolver()
             , m_HandlerRegistry()
             , m_TimelineDecoder()
-            , m_StreamMetadataCommandHandler(
-                    0, 0, m_PacketVersionResolver.ResolvePacketVersion(0, 0).GetEncodedValue(), !echoPackets)
             , m_CounterCaptureCommandHandler(
                     0, 4, m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), !echoPackets)
+            , m_StreamMetadataCommandHandler(
+                    0, 0, m_PacketVersionResolver.ResolvePacketVersion(0, 0).GetEncodedValue(), !echoPackets)
+            // This stub lets us ignore any counter capture packets we receive without throwing an error
+            , m_StubCommandHandler(3, 0, m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue())
             , m_DirectoryCaptureCommandHandler(
                     0, 2, m_PacketVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue(), !echoPackets)
             , m_TimelineCaptureCommandHandler(
@@ -70,8 +73,9 @@ public:
     {
         m_TimelineDecoder.SetDefaultCallbacks();
 
-        m_HandlerRegistry.RegisterFunctor(&m_StreamMetadataCommandHandler);
         m_HandlerRegistry.RegisterFunctor(&m_CounterCaptureCommandHandler);
+        m_HandlerRegistry.RegisterFunctor(&m_StreamMetadataCommandHandler);
+        m_HandlerRegistry.RegisterFunctor(&m_StubCommandHandler);
         m_HandlerRegistry.RegisterFunctor(&m_DirectoryCaptureCommandHandler);
         m_HandlerRegistry.RegisterFunctor(&m_TimelineDirectoryCaptureCommandHandler);
         m_HandlerRegistry.RegisterFunctor(&m_TimelineCaptureCommandHandler);
@@ -207,8 +211,9 @@ private:
 
     timelinedecoder::TimelineDecoder m_TimelineDecoder;
 
-    gatordmock::StreamMetadataCommandHandler m_StreamMetadataCommandHandler;
     gatordmock::PeriodicCounterCaptureCommandHandler m_CounterCaptureCommandHandler;
+    gatordmock::StreamMetadataCommandHandler m_StreamMetadataCommandHandler;
+    gatordmock::StubCommandHandler m_StubCommandHandler;
 
     profiling::DirectoryCaptureCommandHandler m_DirectoryCaptureCommandHandler;
 
index 6b82280..c075857 100644 (file)
@@ -2,6 +2,7 @@
 // Copyright © 2019 Arm Ltd. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
+#pragma once
 
 #include <CommandHandlerFunctor.hpp>
 #include <Packet.hpp>
@@ -14,8 +15,6 @@ namespace armnn
 namespace gatordmock
 {
 
-#pragma once
-
 class PeriodicCounterSelectionResponseHandler : public profiling::CommandHandlerFunctor
 {
 
diff --git a/tests/profiling/gatordmock/StubCommandHandler.hpp b/tests/profiling/gatordmock/StubCommandHandler.hpp
new file mode 100644 (file)
index 0000000..450f90f
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <CommandHandlerFunctor.hpp>
+#include <armnn/utility/IgnoreUnused.hpp>
+
+#include <vector>
+
+namespace armnn
+{
+
+namespace gatordmock
+{
+
+class StubCommandHandler : public profiling::CommandHandlerFunctor
+{
+
+public:
+    /**
+     *
+     * @param packetId The id of packets this handler will process.
+     * @param version The version of that id.
+     */
+    StubCommandHandler(uint32_t familyId,
+                       uint32_t packetId,
+                       uint32_t version)
+            : CommandHandlerFunctor(familyId, packetId, version)
+    {}
+
+    void operator()(const armnn::profiling::Packet& packet) override
+    {
+        //No op
+        IgnoreUnused(packet);
+    }
+
+};
+
+}    // namespace gatordmock
+}    // namespace armnn
index 11a96fd..1929c7a 100644 (file)
@@ -239,7 +239,9 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd)
 
     // Enable the profiling service.
     armnn::IRuntime::CreationOptions::ExternalProfilingOptions options;
-    options.m_EnableProfiling                     = true;
+    options.m_EnableProfiling = true;
+    options.m_TimelineEnabled = true;
+
     armnn::profiling::ProfilingService profilingService;
     profilingService.ResetExternalProfilingOptions(options, true);
 
@@ -396,6 +398,7 @@ BOOST_AUTO_TEST_CASE(GatorDMockTimeLineActivation)
 
     armnn::IRuntime::CreationOptions options;
     options.m_ProfilingOptions.m_EnableProfiling = true;
+    options.m_ProfilingOptions.m_TimelineEnabled = true;
     armnn::Runtime runtime(options);
 
     armnnUtils::Sockets::Socket clientConnection;