blob: 15c5c7e56d0ff8c2f9a6f19cca2befa38dbb9047 [file] [log] [blame]
Finn Williamse63a0262019-10-22 10:30:49 +01001//
Jim Flynn1fdeb992020-07-09 07:28:37 +01002// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
Finn Williamse63a0262019-10-22 10:30:49 +01003// SPDX-License-Identifier: MIT
4//
5
Jim Flynnbbfe6032020-07-20 16:57:44 +01006#include <common/include/CommandHandlerFunctor.hpp>
7#include <common/include/CommonProfilingUtils.hpp>
8#include <server/include/timelineDecoder/TimelineCaptureCommandHandler.hpp>
9#include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
10#include <server/include/timelineDecoder/TimelineDecoder.hpp>
Finn Williamse63a0262019-10-22 10:30:49 +010011
Jim Flynnbbfe6032020-07-20 16:57:44 +010012#include <BufferManager.hpp>
Rob Hughes9542f902021-07-14 09:48:54 +010013#include <armnnUtils/Threads.hpp>
Finn Williamse63a0262019-10-22 10:30:49 +010014#include <ProfilingService.hpp>
15#include <PacketBuffer.hpp>
16#include <TimelinePacketWriterFactory.hpp>
17
Sadik Armagan1625efc2021-06-10 18:24:34 +010018#include <doctest/doctest.h>
Finn Williamse63a0262019-10-22 10:30:49 +010019
Sadik Armagan1625efc2021-06-10 18:24:34 +010020TEST_SUITE("TimelineDecoderTests")
21{
Finn Williamse63a0262019-10-22 10:30:49 +010022void SendTimelinePacketToCommandHandler(const unsigned char* packetBuffer,
Jim Flynnbbfe6032020-07-20 16:57:44 +010023 arm::pipe::CommandHandlerFunctor& CommandHandler)
Finn Williamse63a0262019-10-22 10:30:49 +010024{
25 uint32_t uint32_t_size = sizeof(uint32_t);
26 unsigned int offset = 0;
27
28 uint32_t header[2];
Jim Flynnbbfe6032020-07-20 16:57:44 +010029 header[0] = arm::pipe::ReadUint32(packetBuffer, offset);
Finn Williamse63a0262019-10-22 10:30:49 +010030 offset += uint32_t_size;
Jim Flynnbbfe6032020-07-20 16:57:44 +010031 header[1] = arm::pipe::ReadUint32(packetBuffer, offset);
Finn Williamse63a0262019-10-22 10:30:49 +010032 offset += uint32_t_size;
Finn Williamse63a0262019-10-22 10:30:49 +010033 uint32_t PacketDataLength = header[1] & 0x00FFFFFF;
34
Matteo Martincigh34a407d2019-11-06 15:30:54 +000035 auto uniquePacketData = std::make_unique<unsigned char[]>(PacketDataLength);
Finn Williamse63a0262019-10-22 10:30:49 +010036 std::memcpy(uniquePacketData.get(), packetBuffer + offset, PacketDataLength);
37
Jim Flynnbbfe6032020-07-20 16:57:44 +010038 arm::pipe::Packet packet(header[0], PacketDataLength, uniquePacketData);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000039
Sadik Armagan1625efc2021-06-10 18:24:34 +010040 CHECK(std::memcmp(packetBuffer + offset, packet.GetData(), packet.GetLength()) == 0);
Finn Williamse63a0262019-10-22 10:30:49 +010041
42 CommandHandler(packet);
43}
44
Jim Flynnbbfe6032020-07-20 16:57:44 +010045void PushEntity(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Entity entity)
Finn Williams510f6182020-02-21 11:14:08 +000046{
47 model.m_Entities.emplace_back(entity);
48}
49
Jim Flynnbbfe6032020-07-20 16:57:44 +010050void PushEventClass(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::EventClass eventClass)
Finn Williams510f6182020-02-21 11:14:08 +000051{
52 model.m_EventClasses.emplace_back(eventClass);
53}
54
Jim Flynnbbfe6032020-07-20 16:57:44 +010055void PushEvent(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Event event)
Finn Williams510f6182020-02-21 11:14:08 +000056{
57 model.m_Events.emplace_back(event);
58}
59
Jim Flynnbbfe6032020-07-20 16:57:44 +010060void PushLabel(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Label label)
Finn Williams510f6182020-02-21 11:14:08 +000061{
62 model.m_Labels.emplace_back(label);
63}
64
Jim Flynnbbfe6032020-07-20 16:57:44 +010065void PushRelationship(arm::pipe::TimelineDecoder::Model& model,
66 const arm::pipe::ITimelineDecoder::Relationship relationship)
Finn Williams510f6182020-02-21 11:14:08 +000067{
68 model.m_Relationships.emplace_back(relationship);
69}
70
Sadik Armagan1625efc2021-06-10 18:24:34 +010071TEST_CASE("TimelineDirectoryTest")
Finn Williamse63a0262019-10-22 10:30:49 +010072{
Matteo Martincigh34a407d2019-11-06 15:30:54 +000073 uint32_t uint8_t_size = sizeof(uint8_t);
Finn Williamse63a0262019-10-22 10:30:49 +010074 uint32_t uint32_t_size = sizeof(uint32_t);
Matteo Martincigh34a407d2019-11-06 15:30:54 +000075 uint32_t uint64_t_size = sizeof(uint64_t);
Finn Williamse63a0262019-10-22 10:30:49 +010076
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000077 arm::pipe::BufferManager bufferManager(5);
78 arm::pipe::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Finn Williamse63a0262019-10-22 10:30:49 +010079
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000080 std::unique_ptr<arm::pipe::ISendTimelinePacket> sendTimelinePacket =
Finn Williamse63a0262019-10-22 10:30:49 +010081 timelinePacketWriterFactory.GetSendTimelinePacket();
82
Jim Flynnbbfe6032020-07-20 16:57:44 +010083 arm::pipe::PacketVersionResolver packetVersionResolver;
Finn Williamse63a0262019-10-22 10:30:49 +010084
Jim Flynnbbfe6032020-07-20 16:57:44 +010085 arm::pipe::TimelineDecoder timelineDecoder;
86 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Finn Williamse6a2ccd2020-02-27 16:21:41 +000087 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder);
88
Jim Flynnbbfe6032020-07-20 16:57:44 +010089 arm::pipe::TimelineDirectoryCaptureCommandHandler timelineDirectoryCaptureCommandHandler(
Finn Williamse6a2ccd2020-02-27 16:21:41 +000090 1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue(),
91 timelineCaptureCommandHandler, true);
Finn Williamse63a0262019-10-22 10:30:49 +010092
93 sendTimelinePacket->SendTimelineMessageDirectoryPackage();
94 sendTimelinePacket->Commit();
95
Jim Flynnbbfe6032020-07-20 16:57:44 +010096 std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
Finn Williamse63a0262019-10-22 10:30:49 +010097
98 unsigned int offset = uint32_t_size * 2;
99
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000100 std::unique_ptr<arm::pipe::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer();
Finn Williamse63a0262019-10-22 10:30:49 +0100101
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000102 uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103 CHECK(readStreamVersion == 4);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000104 offset += uint8_t_size;
105 uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100106 CHECK(readPointerBytes == uint64_t_size);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000107 offset += uint8_t_size;
108 uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000109 CHECK(readThreadIdBytes == arm::pipe::ThreadIdSize);
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000110 offset += uint8_t_size;
111
Jim Flynnbbfe6032020-07-20 16:57:44 +0100112 uint32_t declarationSize = arm::pipe::ReadUint32(packetBuffer->GetReadableData(), offset);
Finn Williamse63a0262019-10-22 10:30:49 +0100113 offset += uint32_t_size;
114 for(uint32_t i = 0; i < declarationSize; ++i)
115 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100116 swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
Kevin Mayc1351792020-07-28 11:29:04 +0100117 offset,
118 packetBuffer->GetSize()));
Finn Williamse63a0262019-10-22 10:30:49 +0100119 }
120
121 SendTimelinePacketToCommandHandler(packetBuffer->GetReadableData(), timelineDirectoryCaptureCommandHandler);
122
123 for(uint32_t index = 0; index < declarationSize; ++index)
124 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100125 arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
126 arm::pipe::SwTraceMessage& handlerMessage = timelineDirectoryCaptureCommandHandler.m_SwTraceMessages[index];
Finn Williamse63a0262019-10-22 10:30:49 +0100127
Sadik Armagan1625efc2021-06-10 18:24:34 +0100128 CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
129 CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
130 CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
Finn Williamse63a0262019-10-22 10:30:49 +0100131
Sadik Armagan1625efc2021-06-10 18:24:34 +0100132 CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000133 for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
Finn Williamse63a0262019-10-22 10:30:49 +0100134 {
Sadik Armagan1625efc2021-06-10 18:24:34 +0100135 CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
Finn Williamse63a0262019-10-22 10:30:49 +0100136 }
137
Sadik Armagan1625efc2021-06-10 18:24:34 +0100138 CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
Matteo Martincigh34a407d2019-11-06 15:30:54 +0000139 for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
Finn Williamse63a0262019-10-22 10:30:49 +0100140 {
Sadik Armagan1625efc2021-06-10 18:24:34 +0100141 CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
Finn Williamse63a0262019-10-22 10:30:49 +0100142 }
143 }
144}
145
Sadik Armagan1625efc2021-06-10 18:24:34 +0100146TEST_CASE("TimelineCaptureTest")
Finn Williamse63a0262019-10-22 10:30:49 +0100147{
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000148 arm::pipe::BufferManager bufferManager(50);
149 arm::pipe::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Finn Williamse63a0262019-10-22 10:30:49 +0100150
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000151 std::unique_ptr<arm::pipe::ISendTimelinePacket> sendTimelinePacket =
Finn Williamse63a0262019-10-22 10:30:49 +0100152 timelinePacketWriterFactory.GetSendTimelinePacket();
153
Jim Flynnbbfe6032020-07-20 16:57:44 +0100154 arm::pipe::PacketVersionResolver packetVersionResolver;
Finn Williamse63a0262019-10-22 10:30:49 +0100155
Jim Flynnbbfe6032020-07-20 16:57:44 +0100156 arm::pipe::TimelineDecoder timelineDecoder;
Finn Williamse6a2ccd2020-02-27 16:21:41 +0000157
Jim Flynnbbfe6032020-07-20 16:57:44 +0100158 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100159 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder,
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000160 arm::pipe::ThreadIdSize);
Finn Williamse63a0262019-10-22 10:30:49 +0100161
Jim Flynnbbfe6032020-07-20 16:57:44 +0100162 using Status = arm::pipe::ITimelineDecoder::TimelineStatus;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100163 CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success);
164 CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success);
165 CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success);
166 CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success);
167 CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success);
Finn Williamse63a0262019-10-22 10:30:49 +0100168
Keith Davis97da5e22020-03-05 16:25:28 +0000169 const uint64_t entityGuid = 111111u;
Finn Williams510f6182020-02-21 11:14:08 +0000170 const uint64_t eventClassGuid = 22222u;
Jim Flynn1892d212020-05-26 21:10:49 +0100171 const uint64_t eventClassNameGuid = 22322u;
Finn Williams510f6182020-02-21 11:14:08 +0000172 const uint64_t timestamp = 33333u;
173 const uint64_t eventGuid = 44444u;
Finn Williamse63a0262019-10-22 10:30:49 +0100174
Jim Flynn1fdeb992020-07-09 07:28:37 +0100175 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Finn Williamse63a0262019-10-22 10:30:49 +0100176
Finn Williams510f6182020-02-21 11:14:08 +0000177 // need to do a bit of work here to extract the value from threadId
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000178 unsigned char* uCharThreadId = new unsigned char[arm::pipe::ThreadIdSize]();;
Finn Williams510f6182020-02-21 11:14:08 +0000179 uint64_t uint64ThreadId;
Finn Williamse63a0262019-10-22 10:30:49 +0100180
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000181 arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, arm::pipe::ThreadIdSize);
Finn Williamse63a0262019-10-22 10:30:49 +0100182
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000183 if (arm::pipe::ThreadIdSize == 4)
Finn Williams510f6182020-02-21 11:14:08 +0000184 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100185 uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0);
Finn Williams510f6182020-02-21 11:14:08 +0000186 }
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000187 else if (arm::pipe::ThreadIdSize == 8)
Finn Williams510f6182020-02-21 11:14:08 +0000188 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100189 uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0);
Finn Williams510f6182020-02-21 11:14:08 +0000190 }
191 delete[] uCharThreadId;
192
193 const uint64_t labelGuid = 66666u;
Finn Williamse63a0262019-10-22 10:30:49 +0100194 std::string labelName = "test_label";
195
Finn Williams510f6182020-02-21 11:14:08 +0000196 const uint64_t relationshipGuid = 77777u;
197 const uint64_t headGuid = 888888u;
198 const uint64_t tailGuid = 999999u;
Finn Williamse63a0262019-10-22 10:30:49 +0100199
200 for (int i = 0; i < 10; ++i)
201 {
202 // Send entity
203 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
204 sendTimelinePacket->Commit();
205 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
206 timelineCaptureCommandHandler);
207
208 // Send event class
Jim Flynn1892d212020-05-26 21:10:49 +0100209 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100210 sendTimelinePacket->Commit();
211 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
212 timelineCaptureCommandHandler);
213
214 // Send event
215 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
216 sendTimelinePacket->Commit();
217 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
218 timelineCaptureCommandHandler);
219
220 // Send label
221 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
222 sendTimelinePacket->Commit();
223 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
224 timelineCaptureCommandHandler);
225
226 // Send relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000227 arm::pipe::ProfilingRelationshipType relationshipType =
228 arm::pipe::ProfilingRelationshipType::DataLink;
Finn Williamse63a0262019-10-22 10:30:49 +0100229 sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
230 relationshipGuid,
231 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100232 tailGuid,
233 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100234 sendTimelinePacket->Commit();
235 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
236 timelineCaptureCommandHandler);
237 }
238
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000239 timelineDecoder.ApplyToModel([&](const arm::pipe::TimelineDecoder::Model& model){
240 for (unsigned long i = 0; i < 10; ++i)
241 {
242 CHECK(model.m_Entities[i].m_Guid == entityGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100243
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000244 CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100245
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000246 CHECK(model.m_Events[i].m_TimeStamp == timestamp);
247 CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId);
248 CHECK(model.m_Events[i].m_Guid == eventGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100249
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000250 CHECK(model.m_Labels[i].m_Guid == labelGuid);
251 CHECK(model.m_Labels[i].m_Name == labelName);
Finn Williamse63a0262019-10-22 10:30:49 +0100252
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000253 CHECK(model.m_Relationships[i].m_RelationshipType ==
254 arm::pipe::ITimelineDecoder::RelationshipType::DataLink);
255 CHECK(model.m_Relationships[i].m_Guid == relationshipGuid);
256 CHECK(model.m_Relationships[i].m_HeadGuid == headGuid);
257 CHECK(model.m_Relationships[i].m_TailGuid == tailGuid);
258 }
259 });
Finn Williamse63a0262019-10-22 10:30:49 +0100260}
261
Sadik Armagan1625efc2021-06-10 18:24:34 +0100262TEST_CASE("TimelineCaptureTestMultipleStringsInBuffer")
Keith Davis5238aff2020-03-11 12:17:05 +0000263{
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000264 arm::pipe::BufferManager bufferManager(50);
265 arm::pipe::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Keith Davis5238aff2020-03-11 12:17:05 +0000266
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000267 std::unique_ptr<arm::pipe::ISendTimelinePacket> sendTimelinePacket =
Keith Davis5238aff2020-03-11 12:17:05 +0000268 timelinePacketWriterFactory.GetSendTimelinePacket();
269
Jim Flynnbbfe6032020-07-20 16:57:44 +0100270 arm::pipe::PacketVersionResolver packetVersionResolver;
Keith Davis5238aff2020-03-11 12:17:05 +0000271
Jim Flynnbbfe6032020-07-20 16:57:44 +0100272 arm::pipe::TimelineDecoder timelineDecoder;
Keith Davis5238aff2020-03-11 12:17:05 +0000273
Jim Flynnbbfe6032020-07-20 16:57:44 +0100274 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100275 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder,
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000276 arm::pipe::ThreadIdSize);
Keith Davis5238aff2020-03-11 12:17:05 +0000277
Jim Flynnbbfe6032020-07-20 16:57:44 +0100278 using Status = arm::pipe::TimelineDecoder::TimelineStatus;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100279 CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success);
280 CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success);
281 CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success);
282 CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success);
283 CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success);
Keith Davis5238aff2020-03-11 12:17:05 +0000284
Jim Flynn1892d212020-05-26 21:10:49 +0100285 const uint64_t entityGuid = 111111u;
286 const uint64_t eventClassGuid = 22222u;
287 const uint64_t eventClassNameGuid = 22322u;
288 const uint64_t timestamp = 33333u;
289 const uint64_t eventGuid = 44444u;
Keith Davis5238aff2020-03-11 12:17:05 +0000290
Jim Flynn1fdeb992020-07-09 07:28:37 +0100291 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Keith Davis5238aff2020-03-11 12:17:05 +0000292
293 // need to do a bit of work here to extract the value from threadId
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000294 unsigned char* uCharThreadId = new unsigned char[arm::pipe::ThreadIdSize]();
Keith Davis5238aff2020-03-11 12:17:05 +0000295 uint64_t uint64ThreadId;
296
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000297 arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, arm::pipe::ThreadIdSize);
Keith Davis5238aff2020-03-11 12:17:05 +0000298
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000299 if ( arm::pipe::ThreadIdSize == 4 )
Keith Davis5238aff2020-03-11 12:17:05 +0000300 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100301 uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0);
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000302 }
303 else if ( arm::pipe::ThreadIdSize == 8 )
Keith Davis5238aff2020-03-11 12:17:05 +0000304 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100305 uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0);
Keith Davis5238aff2020-03-11 12:17:05 +0000306 }
307 delete[] uCharThreadId;
308
309 const uint64_t labelGuid = 66666u;
310 std::string labelName = "test_label";
311 std::string labelName2 = "test_label2";
312 std::string labelName3 = "test_label32";
313
314 const uint64_t relationshipGuid = 77777u;
315 const uint64_t headGuid = 888888u;
316 const uint64_t tailGuid = 999999u;
317
318 // Check with multiple messages in the same buffer
319 for ( int i = 0; i < 9; ++i )
320 {
321 // Send entity
322 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
323 // Send event class
Jim Flynn1892d212020-05-26 21:10:49 +0100324 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000325 // Send event
326 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
327 // Send label
328 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
329 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName2);
330 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName3);
331 // Send relationship
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000332 arm::pipe::ProfilingRelationshipType relationshipType =
333 arm::pipe::ProfilingRelationshipType::DataLink;
Keith Davis5238aff2020-03-11 12:17:05 +0000334 sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
335 relationshipGuid,
336 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100337 tailGuid,
338 0);
Keith Davis5238aff2020-03-11 12:17:05 +0000339 }
340
341 sendTimelinePacket->Commit();
342 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
343 timelineCaptureCommandHandler);
344
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000345 timelineDecoder.ApplyToModel([&](const arm::pipe::TimelineDecoder::Model& model){
346 for ( unsigned long i = 0; i < 9; ++i )
347 {
348 CHECK(model.m_Entities[i].m_Guid == entityGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000349
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000350 CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000351
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000352 CHECK(model.m_Labels[i].m_Guid == labelGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000353
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000354 CHECK(model.m_Events[i].m_TimeStamp == timestamp);
355 CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId);
356 CHECK(model.m_Events[i].m_Guid == eventGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000357
Matthew Bentham6ae43c42022-01-10 13:34:12 +0000358 CHECK(model.m_Relationships[i].m_RelationshipType ==
359 arm::pipe::ITimelineDecoder::RelationshipType::DataLink);
360 CHECK(model.m_Relationships[i].m_Guid == relationshipGuid);
361 CHECK(model.m_Relationships[i].m_HeadGuid == headGuid);
362 CHECK(model.m_Relationships[i].m_TailGuid == tailGuid);
363 }
364 for ( unsigned long i = 0; i < 9; i += 3 )
365 {
366 CHECK(model.m_Labels[i].m_Name == labelName);
367 CHECK(model.m_Labels[i+1].m_Name == labelName2);
368 CHECK(model.m_Labels[i+2].m_Name == labelName3);
369 }
370 });
Keith Davis5238aff2020-03-11 12:17:05 +0000371}
372
Sadik Armagan1625efc2021-06-10 18:24:34 +0100373}