blob: f09848f52c9e78e0394397d7411223519a410c22 [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
Jim Flynnbbfe6032020-07-20 16:57:44 +010077 armnn::profiling::BufferManager bufferManager(5);
78 armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Finn Williamse63a0262019-10-22 10:30:49 +010079
Jim Flynnbbfe6032020-07-20 16:57:44 +010080 std::unique_ptr<armnn::profiling::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
Jim Flynnbbfe6032020-07-20 16:57:44 +0100100 std::unique_ptr<armnn::profiling::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);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100109 CHECK(readThreadIdBytes == armnn::profiling::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{
Jim Flynnbbfe6032020-07-20 16:57:44 +0100148 armnn::profiling::BufferManager bufferManager(50);
149 armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Finn Williamse63a0262019-10-22 10:30:49 +0100150
Jim Flynnbbfe6032020-07-20 16:57:44 +0100151 std::unique_ptr<armnn::profiling::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;
157 const arm::pipe::TimelineDecoder::Model& model = timelineDecoder.GetModel();
Finn Williamse63a0262019-10-22 10:30:49 +0100158
Finn Williamse6a2ccd2020-02-27 16:21:41 +0000159
Jim Flynnbbfe6032020-07-20 16:57:44 +0100160 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100161 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder,
162 armnn::profiling::ThreadIdSize);
Finn Williamse63a0262019-10-22 10:30:49 +0100163
Jim Flynnbbfe6032020-07-20 16:57:44 +0100164 using Status = arm::pipe::ITimelineDecoder::TimelineStatus;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100165 CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success);
166 CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success);
167 CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success);
168 CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success);
169 CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success);
Finn Williamse63a0262019-10-22 10:30:49 +0100170
Keith Davis97da5e22020-03-05 16:25:28 +0000171 const uint64_t entityGuid = 111111u;
Finn Williams510f6182020-02-21 11:14:08 +0000172 const uint64_t eventClassGuid = 22222u;
Jim Flynn1892d212020-05-26 21:10:49 +0100173 const uint64_t eventClassNameGuid = 22322u;
Finn Williams510f6182020-02-21 11:14:08 +0000174 const uint64_t timestamp = 33333u;
175 const uint64_t eventGuid = 44444u;
Finn Williamse63a0262019-10-22 10:30:49 +0100176
Jim Flynn1fdeb992020-07-09 07:28:37 +0100177 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Finn Williamse63a0262019-10-22 10:30:49 +0100178
Finn Williams510f6182020-02-21 11:14:08 +0000179 // need to do a bit of work here to extract the value from threadId
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100180 unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();;
Finn Williams510f6182020-02-21 11:14:08 +0000181 uint64_t uint64ThreadId;
Finn Williamse63a0262019-10-22 10:30:49 +0100182
Jim Flynnbbfe6032020-07-20 16:57:44 +0100183 arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize);
Finn Williamse63a0262019-10-22 10:30:49 +0100184
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100185 if (armnn::profiling::ThreadIdSize == 4)
Finn Williams510f6182020-02-21 11:14:08 +0000186 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100187 uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0);
Finn Williams510f6182020-02-21 11:14:08 +0000188 }
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100189 else if (armnn::profiling::ThreadIdSize == 8)
Finn Williams510f6182020-02-21 11:14:08 +0000190 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100191 uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0);
Finn Williams510f6182020-02-21 11:14:08 +0000192 }
193 delete[] uCharThreadId;
194
195 const uint64_t labelGuid = 66666u;
Finn Williamse63a0262019-10-22 10:30:49 +0100196 std::string labelName = "test_label";
197
Finn Williams510f6182020-02-21 11:14:08 +0000198 const uint64_t relationshipGuid = 77777u;
199 const uint64_t headGuid = 888888u;
200 const uint64_t tailGuid = 999999u;
Finn Williamse63a0262019-10-22 10:30:49 +0100201
202 for (int i = 0; i < 10; ++i)
203 {
204 // Send entity
205 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
206 sendTimelinePacket->Commit();
207 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
208 timelineCaptureCommandHandler);
209
210 // Send event class
Jim Flynn1892d212020-05-26 21:10:49 +0100211 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100212 sendTimelinePacket->Commit();
213 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
214 timelineCaptureCommandHandler);
215
216 // Send event
217 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
218 sendTimelinePacket->Commit();
219 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
220 timelineCaptureCommandHandler);
221
222 // Send label
223 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
224 sendTimelinePacket->Commit();
225 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
226 timelineCaptureCommandHandler);
227
228 // Send relationship
Jim Flynnbbfe6032020-07-20 16:57:44 +0100229 armnn::profiling::ProfilingRelationshipType relationshipType =
230 armnn::profiling::ProfilingRelationshipType::DataLink;
Finn Williamse63a0262019-10-22 10:30:49 +0100231 sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
232 relationshipGuid,
233 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100234 tailGuid,
235 0);
Finn Williamse63a0262019-10-22 10:30:49 +0100236 sendTimelinePacket->Commit();
237 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
238 timelineCaptureCommandHandler);
239 }
240
Finn Williams510f6182020-02-21 11:14:08 +0000241 for (unsigned long i = 0; i < 10; ++i)
Finn Williamse63a0262019-10-22 10:30:49 +0100242 {
Sadik Armagan1625efc2021-06-10 18:24:34 +0100243 CHECK(model.m_Entities[i].m_Guid == entityGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100244
Sadik Armagan1625efc2021-06-10 18:24:34 +0100245 CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100246
Sadik Armagan1625efc2021-06-10 18:24:34 +0100247 CHECK(model.m_Events[i].m_TimeStamp == timestamp);
248 CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId);
249 CHECK(model.m_Events[i].m_Guid == eventGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100250
Sadik Armagan1625efc2021-06-10 18:24:34 +0100251 CHECK(model.m_Labels[i].m_Guid == labelGuid);
252 CHECK(model.m_Labels[i].m_Name == labelName);
Finn Williamse63a0262019-10-22 10:30:49 +0100253
Sadik Armagan1625efc2021-06-10 18:24:34 +0100254 CHECK(model.m_Relationships[i].m_RelationshipType ==
Jim Flynnbbfe6032020-07-20 16:57:44 +0100255 arm::pipe::ITimelineDecoder::RelationshipType::DataLink);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100256 CHECK(model.m_Relationships[i].m_Guid == relationshipGuid);
257 CHECK(model.m_Relationships[i].m_HeadGuid == headGuid);
258 CHECK(model.m_Relationships[i].m_TailGuid == tailGuid);
Finn Williamse63a0262019-10-22 10:30:49 +0100259 }
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{
Jim Flynnbbfe6032020-07-20 16:57:44 +0100264 armnn::profiling::BufferManager bufferManager(50);
265 armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
Keith Davis5238aff2020-03-11 12:17:05 +0000266
Jim Flynnbbfe6032020-07-20 16:57:44 +0100267 std::unique_ptr<armnn::profiling::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;
273 const arm::pipe::TimelineDecoder::Model& model = timelineDecoder.GetModel();
Keith Davis5238aff2020-03-11 12:17:05 +0000274
Jim Flynnbbfe6032020-07-20 16:57:44 +0100275 arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler(
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100276 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder,
277 armnn::profiling::ThreadIdSize);
Keith Davis5238aff2020-03-11 12:17:05 +0000278
Jim Flynnbbfe6032020-07-20 16:57:44 +0100279 using Status = arm::pipe::TimelineDecoder::TimelineStatus;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100280 CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success);
281 CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success);
282 CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success);
283 CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success);
284 CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success);
Keith Davis5238aff2020-03-11 12:17:05 +0000285
Jim Flynn1892d212020-05-26 21:10:49 +0100286 const uint64_t entityGuid = 111111u;
287 const uint64_t eventClassGuid = 22222u;
288 const uint64_t eventClassNameGuid = 22322u;
289 const uint64_t timestamp = 33333u;
290 const uint64_t eventGuid = 44444u;
Keith Davis5238aff2020-03-11 12:17:05 +0000291
Jim Flynn1fdeb992020-07-09 07:28:37 +0100292 const int threadId = armnnUtils::Threads::GetCurrentThreadId();
Keith Davis5238aff2020-03-11 12:17:05 +0000293
294 // need to do a bit of work here to extract the value from threadId
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100295 unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();
Keith Davis5238aff2020-03-11 12:17:05 +0000296 uint64_t uint64ThreadId;
297
Jim Flynnbbfe6032020-07-20 16:57:44 +0100298 arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize);
Keith Davis5238aff2020-03-11 12:17:05 +0000299
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100300 if ( armnn::profiling::ThreadIdSize == 4 )
Keith Davis5238aff2020-03-11 12:17:05 +0000301 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100302 uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0);
Colm Donelan5bb3d8a2020-05-12 16:36:46 +0100303 }
304 else if ( armnn::profiling::ThreadIdSize == 8 )
Keith Davis5238aff2020-03-11 12:17:05 +0000305 {
Jim Flynnbbfe6032020-07-20 16:57:44 +0100306 uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0);
Keith Davis5238aff2020-03-11 12:17:05 +0000307 }
308 delete[] uCharThreadId;
309
310 const uint64_t labelGuid = 66666u;
311 std::string labelName = "test_label";
312 std::string labelName2 = "test_label2";
313 std::string labelName3 = "test_label32";
314
315 const uint64_t relationshipGuid = 77777u;
316 const uint64_t headGuid = 888888u;
317 const uint64_t tailGuid = 999999u;
318
319 // Check with multiple messages in the same buffer
320 for ( int i = 0; i < 9; ++i )
321 {
322 // Send entity
323 sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid);
324 // Send event class
Jim Flynn1892d212020-05-26 21:10:49 +0100325 sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000326 // Send event
327 sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid);
328 // Send label
329 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName);
330 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName2);
331 sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName3);
332 // Send relationship
Jim Flynnbbfe6032020-07-20 16:57:44 +0100333 armnn::profiling::ProfilingRelationshipType relationshipType =
334 armnn::profiling::ProfilingRelationshipType::DataLink;
Keith Davis5238aff2020-03-11 12:17:05 +0000335 sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType,
336 relationshipGuid,
337 headGuid,
Finn Williams0a336dc2020-05-11 15:39:58 +0100338 tailGuid,
339 0);
Keith Davis5238aff2020-03-11 12:17:05 +0000340 }
341
342 sendTimelinePacket->Commit();
343 SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(),
344 timelineCaptureCommandHandler);
345
346 for ( unsigned long i = 0; i < 9; ++i )
347 {
Sadik Armagan1625efc2021-06-10 18:24:34 +0100348 CHECK(model.m_Entities[i].m_Guid == entityGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000349
Sadik Armagan1625efc2021-06-10 18:24:34 +0100350 CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000351
Sadik Armagan1625efc2021-06-10 18:24:34 +0100352 CHECK(model.m_Labels[i].m_Guid == labelGuid);
Keith Davis5238aff2020-03-11 12:17:05 +0000353
Sadik Armagan1625efc2021-06-10 18:24:34 +0100354 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
Sadik Armagan1625efc2021-06-10 18:24:34 +0100358 CHECK(model.m_Relationships[i].m_RelationshipType ==
Jim Flynnbbfe6032020-07-20 16:57:44 +0100359 arm::pipe::ITimelineDecoder::RelationshipType::DataLink);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100360 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);
Keith Davis5238aff2020-03-11 12:17:05 +0000363 }
364 for ( unsigned long i = 0; i < 9; i += 3 )
365 {
Sadik Armagan1625efc2021-06-10 18:24:34 +0100366 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);
Keith Davis5238aff2020-03-11 12:17:05 +0000369 }
370}
371
Sadik Armagan1625efc2021-06-10 18:24:34 +0100372}