IVGCVSW-5095 Make timeline report the Linux Thread ID not the pthread ID
authorJim Flynn <jim.flynn@arm.com>
Thu, 9 Jul 2020 06:28:37 +0000 (07:28 +0100)
committerJim Flynn <jim.flynn@arm.com>
Thu, 9 Jul 2020 12:48:46 +0000 (13:48 +0100)
Change-Id: Id69519fd9ef57716de4e389ed4156710a904c701
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
16 files changed:
Android.mk
CMakeLists.txt
include/armnn/profiling/ISendTimelinePacket.hpp
src/armnnUtils/Threads.cpp [new file with mode: 0644]
src/armnnUtils/Threads.hpp [new file with mode: 0644]
src/profiling/ProfilingUtils.cpp
src/profiling/ProfilingUtils.hpp
src/profiling/SendTimelinePacket.cpp
src/profiling/SendTimelinePacket.hpp
src/profiling/TimelineUtilityMethods.cpp
src/profiling/test/ProfilingTestUtils.cpp
src/profiling/test/ProfilingTestUtils.hpp
src/profiling/test/SendTimelinePacketTests.cpp
src/profiling/test/TimelinePacketTests.cpp
src/timelineDecoder/tests/TimelineTests.cpp
tests/profiling/gatordmock/tests/GatordMockTests.cpp

index 38b2ad4..781aba6 100644 (file)
@@ -131,6 +131,7 @@ LOCAL_SRC_FILES := \
         src/armnnUtils/VerificationHelpers.cpp \
         src/armnnUtils/Filesystem.cpp \
         src/armnnUtils/Processes.cpp \
+        src/armnnUtils/Threads.cpp \
         src/armnnUtils/Transpose.cpp \
         src/armnn/layers/ActivationLayer.cpp \
         src/armnn/layers/AdditionLayer.cpp \
index 968c57f..2586d22 100644 (file)
@@ -45,8 +45,6 @@ list(APPEND armnnUtils_sources
     src/armnnUtils/BFloat16.hpp
     src/armnnUtils/Filesystem.hpp
     src/armnnUtils/Filesystem.cpp
-    src/armnnUtils/Processes.hpp
-    src/armnnUtils/Processes.cpp
     src/armnnUtils/GraphTopologicalSort.hpp
     src/armnnUtils/Half.hpp
     src/armnnUtils/Permute.cpp
@@ -67,11 +65,15 @@ list(APPEND armnnUtils_sources
     src/armnnUtils/ParserHelper.hpp
     src/armnnUtils/ParserHelper.cpp
     src/armnnUtils/ParserPrototxtFixture.hpp
+    src/armnnUtils/Processes.hpp
+    src/armnnUtils/Processes.cpp
     src/armnnUtils/PrototxtConversions.hpp
     src/armnnUtils/PrototxtConversions.cpp
     src/armnnUtils/QuantizeHelper.hpp
     src/armnnUtils/TensorIOUtils.hpp
     src/armnnUtils/TensorUtils.cpp
+    src/armnnUtils/Threads.hpp
+    src/armnnUtils/Threads.cpp
     src/armnnUtils/Transpose.cpp
     src/armnnUtils/WindowsWrapper.hpp
     )
index 0eba333..c5da521 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright © 2019 Arm Ltd. All rights reserved.
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -7,7 +7,6 @@
 
 #include <algorithm>
 #include <string>
-#include <thread>
 #include <vector>
 
 namespace armnn
@@ -38,7 +37,7 @@ public:
 
     /// Create and write a TimelineEventBinaryPacket from the parameters to the buffer.
     virtual void
-        SendTimelineEventBinaryPacket(uint64_t timestamp, std::thread::id threadId, uint64_t profilingGuid) = 0;
+        SendTimelineEventBinaryPacket(uint64_t timestamp, int threadId, uint64_t profilingGuid) = 0;
 
     /// Create and write a TimelineEventClassBinaryPacket from the parameters to the buffer.
     virtual void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid, uint64_t nameGuid) = 0;
diff --git a/src/armnnUtils/Threads.cpp b/src/armnnUtils/Threads.cpp
new file mode 100644 (file)
index 0000000..561edcb
--- /dev/null
@@ -0,0 +1,31 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "Threads.hpp"
+
+#if defined(__linux__)
+#include <unistd.h>
+#include <sys/syscall.h>
+#define gettid() syscall(SYS_gettid)
+#elif defined(_MSC_VER)
+#include "WindowsWrapper.hpp"
+#endif
+
+namespace armnnUtils
+{
+namespace Threads
+{
+
+int GetCurrentThreadId()
+{
+#if defined(__linux__)
+    return static_cast<int>(gettid());
+#elif defined(_MSC_VER)
+    return ::GetCurrentThreadId();
+#endif
+}
+
+}
+}
diff --git a/src/armnnUtils/Threads.hpp b/src/armnnUtils/Threads.hpp
new file mode 100644 (file)
index 0000000..4cecfd5
--- /dev/null
@@ -0,0 +1,16 @@
+//
+// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+namespace armnnUtils
+{
+namespace Threads
+{
+
+int GetCurrentThreadId();
+
+}
+}
index d67694f..3f6e563 100644 (file)
@@ -802,7 +802,7 @@ TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid,
 }
 
 TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp,
-                                              std::thread::id threadId,
+                                              int threadId,
                                               uint64_t profilingGuid,
                                               unsigned char* buffer,
                                               unsigned int remainingBufferSize,
@@ -1093,7 +1093,7 @@ Packet ReceivePacket(const unsigned char* buffer, uint32_t length)
 namespace std
 {
 
-bool operator==(const std::vector<uint8_t>& left, std::thread::id right)
+bool operator==(const std::vector<uint8_t>& left, int right)
 {
     return std::memcmp(left.data(), &right, left.size()) == 0;
 }
index 95fa780..2ead316 100644 (file)
@@ -28,7 +28,7 @@ namespace armnn
 namespace profiling
 {
 
-constexpr unsigned int ThreadIdSize = sizeof(std::thread::id); // Is platform dependent
+constexpr unsigned int ThreadIdSize = sizeof(int); // Is platform dependent
 
 struct SwTraceHeader
 {
@@ -245,7 +245,7 @@ TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid,
                                                    unsigned int& numberOfBytesWritten);
 
 TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp,
-                                              std::thread::id threadId,
+                                              int threadId,
                                               uint64_t profilingGuid,
                                               unsigned char* buffer,
                                               unsigned int bufferSize,
@@ -271,6 +271,6 @@ Packet ReceivePacket(const unsigned char* buffer, uint32_t length);
 namespace std
 {
 
-bool operator==(const std::vector<uint8_t>& left, std::thread::id right);
+bool operator==(const std::vector<uint8_t>& left, int right);
 
 } // namespace std
index 2ca5f54..11e3d2f 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright © 2019 Arm Ltd. All rights reserved.
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -89,7 +89,7 @@ void SendTimelinePacket::SendTimelineEntityBinaryPacket(uint64_t profilingGuid)
 }
 
 void SendTimelinePacket::SendTimelineEventBinaryPacket(uint64_t timestamp,
-                                                       std::thread::id threadId,
+                                                       int threadId,
                                                        uint64_t profilingGuid)
 {
     ForwardWriteBinaryFunction(WriteTimelineEventBinary,
index 2b710c7..90016d0 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright © 2019 Arm Ltd. All rights reserved.
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -36,7 +36,7 @@ public:
     void SendTimelineEntityBinaryPacket(uint64_t profilingGuid) override;
 
     /// Create and write a TimelineEventBinaryPacket from the parameters to the buffer.
-    void SendTimelineEventBinaryPacket(uint64_t timestamp, std::thread::id threadId, uint64_t profilingGuid) override;
+    void SendTimelineEventBinaryPacket(uint64_t timestamp, int threadId, uint64_t profilingGuid) override;
 
     /// Create and write a TimelineEventClassBinaryPacket from the parameters to the buffer.
     void SendTimelineEventClassBinaryPacket(uint64_t profilingGuid, uint64_t nameGuid) override;
index 2727bd6..fe5c6b1 100644 (file)
@@ -2,9 +2,9 @@
 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
-
-#include "TimelineUtilityMethods.hpp"
 #include "LabelsAndEventClasses.hpp"
+#include <Threads.hpp>
+#include "TimelineUtilityMethods.hpp"
 
 namespace armnn
 {
@@ -368,7 +368,7 @@ ProfilingDynamicGuid TimelineUtilityMethods::RecordEvent(ProfilingGuid entityGui
     uint64_t timestamp = GetTimestamp();
 
     // Get the thread id
-    std::thread::id threadId = std::this_thread::get_id();
+    int threadId = armnnUtils::Threads::GetCurrentThreadId();
 
     // Generate a GUID for the event
     ProfilingDynamicGuid eventGuid = profiling::ProfilingService::GetNextGuid();
index 9f6bc43..526f3f9 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <armnn/Descriptors.hpp>
 #include <LabelsAndEventClasses.hpp>
+#include <Threads.hpp>
 #include <ProfilingService.hpp>
 
 #include <test/TestUtils.hpp>
@@ -295,7 +296,7 @@ ProfilingGuid VerifyTimelineEntityBinaryPacketData(Optional<ProfilingGuid> guid,
 }
 
 ProfilingGuid VerifyTimelineEventBinaryPacket(Optional<uint64_t> timestamp,
-                                              Optional<std::thread::id> threadId,
+                                              Optional<int> threadId,
                                               Optional<ProfilingGuid> eventGuid,
                                               const unsigned char* readableData,
                                               unsigned int& offset)
@@ -333,7 +334,7 @@ ProfilingGuid VerifyTimelineEventBinaryPacket(Optional<uint64_t> timestamp,
     }
     else
     {
-        BOOST_CHECK(readThreadId == std::this_thread::get_id());
+        BOOST_CHECK(readThreadId == armnnUtils::Threads::GetCurrentThreadId());
     }
 
     // Check the event GUID
index 8f138bb..4daf9d5 100644 (file)
@@ -53,7 +53,7 @@ ProfilingGuid VerifyTimelineEntityBinaryPacketData(Optional<ProfilingGuid> guid,
                                                    unsigned int& offset);
 
 ProfilingGuid VerifyTimelineEventBinaryPacket(Optional<uint64_t> timestamp,
-                                              Optional<std::thread::id> threadId,
+                                              Optional<int> threadId,
                                               Optional<ProfilingGuid> eventGuid,
                                               const unsigned char* readableData,
                                               unsigned int& offset);
index 4b45cfe..da30cef 100644 (file)
@@ -6,6 +6,7 @@
 #include "ProfilingMocks.hpp"
 
 #include <BufferManager.hpp>
+#include <Threads.hpp>
 #include <ProfilingService.hpp>
 #include <ProfilingUtils.hpp>
 #include <SendTimelinePacket.hpp>
@@ -322,7 +323,7 @@ BOOST_AUTO_TEST_CASE(SendEventClassAfterTimelineEntityPacketTest)
 
     // Send TimelineEventBinaryPacket
     const uint64_t timestamp = 456789u;
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
     const uint64_t eventProfilingGuid = 123456u;
     sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid);
 
index 96e9bf2..71c6915 100644 (file)
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: MIT
 //
 
+#include <Threads.hpp>
 #include <ProfilingUtils.hpp>
 
 #include <boost/test/unit_test.hpp>
@@ -724,7 +725,7 @@ BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData)
 BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer)
 {
     const uint64_t timestamp = 456789u;
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
     const uint64_t profilingGuid = 123456u;
     unsigned int numberOfBytesWritten = 789u;
     TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
@@ -742,7 +743,7 @@ BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue)
     std::vector<unsigned char> buffer(512, 0);
 
     const uint64_t timestamp = 456789u;
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
     const uint64_t profilingGuid = 123456u;
     unsigned int numberOfBytesWritten = 789u;
     TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
@@ -760,7 +761,7 @@ BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue)
     std::vector<unsigned char> buffer(10, 0);
 
     const uint64_t timestamp = 456789u;
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
     const uint64_t profilingGuid = 123456u;
     unsigned int numberOfBytesWritten = 789u;
     TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
@@ -778,7 +779,7 @@ BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData)
     std::vector<unsigned char> buffer(512, 0);
 
     const uint64_t timestamp = 456789u;
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
     const uint64_t profilingGuid = 123456u;
     unsigned int numberOfBytesWritten = 789u;
     TimelinePacketStatus result = WriteTimelineEventBinary(timestamp,
index 8d0b8a0..08d29d0 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright © 2019 Arm Ltd. All rights reserved.
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -8,6 +8,7 @@
 #include <TimelineDecoder.hpp>
 
 #include <CommandHandlerFunctor.hpp>
+#include <Threads.hpp>
 #include <ProfilingService.hpp>
 #include <PacketBuffer.hpp>
 #include <TimelinePacketWriterFactory.hpp>
@@ -172,7 +173,7 @@ BOOST_AUTO_TEST_CASE(TimelineCaptureTest)
     const uint64_t timestamp = 33333u;
     const uint64_t eventGuid = 44444u;
 
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
 
     // need to do a bit of work here to extract the value from threadId
     unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();;
@@ -285,7 +286,7 @@ BOOST_AUTO_TEST_CASE(TimelineCaptureTestMultipleStringsInBuffer)
     const uint64_t timestamp          = 33333u;
     const uint64_t eventGuid          = 44444u;
 
-    const std::thread::id threadId = std::this_thread::get_id();
+    const int threadId = armnnUtils::Threads::GetCurrentThreadId();
 
     // need to do a bit of work here to extract the value from threadId
     unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();
index 0ee4601..e99bdb5 100644 (file)
@@ -127,7 +127,7 @@ void CheckTimelineDirectory(timelinedecoder::TimelineDirectoryCaptureCommandHand
     uint32_t uint8_t_size  = sizeof(uint8_t);
     uint32_t uint32_t_size = sizeof(uint32_t);
     uint32_t uint64_t_size = sizeof(uint64_t);
-    uint32_t threadId_size = sizeof(std::thread::id);
+    uint32_t threadId_size = sizeof(int);
 
     profiling::BufferManager bufferManager(5);
     profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);