Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Finn Williams | 8a2b468 | 2020-02-26 10:25:26 +0000 | [diff] [blame] | 6 | #include <TimelineCaptureCommandHandler.hpp> |
| 7 | #include <TimelineDirectoryCaptureCommandHandler.hpp> |
| 8 | #include <TimelineDecoder.hpp> |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 9 | |
| 10 | #include <CommandHandlerFunctor.hpp> |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 11 | #include <Threads.hpp> |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 12 | #include <ProfilingService.hpp> |
| 13 | #include <PacketBuffer.hpp> |
| 14 | #include <TimelinePacketWriterFactory.hpp> |
| 15 | |
| 16 | #include <boost/test/test_tools.hpp> |
| 17 | #include <boost/test/unit_test_suite.hpp> |
| 18 | |
| 19 | BOOST_AUTO_TEST_SUITE(TimelineDecoderTests) |
| 20 | |
| 21 | using namespace armnn; |
Finn Williams | 8a2b468 | 2020-02-26 10:25:26 +0000 | [diff] [blame] | 22 | using namespace timelinedecoder; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 23 | |
| 24 | void SendTimelinePacketToCommandHandler(const unsigned char* packetBuffer, |
| 25 | profiling::CommandHandlerFunctor &CommandHandler) |
| 26 | { |
| 27 | uint32_t uint32_t_size = sizeof(uint32_t); |
| 28 | unsigned int offset = 0; |
| 29 | |
| 30 | uint32_t header[2]; |
| 31 | header[0] = profiling::ReadUint32(packetBuffer, offset); |
| 32 | offset += uint32_t_size; |
| 33 | header[1] = profiling::ReadUint32(packetBuffer, offset); |
| 34 | offset += uint32_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 35 | uint32_t PacketDataLength = header[1] & 0x00FFFFFF; |
| 36 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 37 | auto uniquePacketData = std::make_unique<unsigned char[]>(PacketDataLength); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 38 | std::memcpy(uniquePacketData.get(), packetBuffer + offset, PacketDataLength); |
| 39 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 40 | armnn::profiling::Packet packet(header[0], PacketDataLength, uniquePacketData); |
| 41 | |
| 42 | BOOST_CHECK(std::memcmp(packetBuffer + offset, packet.GetData(), packet.GetLength()) == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 43 | |
| 44 | CommandHandler(packet); |
| 45 | } |
| 46 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 47 | void PushEntity(TimelineDecoder::Model& model, const ITimelineDecoder::Entity entity) |
| 48 | { |
| 49 | model.m_Entities.emplace_back(entity); |
| 50 | } |
| 51 | |
| 52 | void PushEventClass(TimelineDecoder::Model& model, const ITimelineDecoder::EventClass eventClass) |
| 53 | { |
| 54 | model.m_EventClasses.emplace_back(eventClass); |
| 55 | } |
| 56 | |
| 57 | void PushEvent(TimelineDecoder::Model& model, const ITimelineDecoder::Event event) |
| 58 | { |
| 59 | model.m_Events.emplace_back(event); |
| 60 | } |
| 61 | |
| 62 | void PushLabel(TimelineDecoder::Model& model, const ITimelineDecoder::Label label) |
| 63 | { |
| 64 | model.m_Labels.emplace_back(label); |
| 65 | } |
| 66 | |
| 67 | void PushRelationship(TimelineDecoder::Model& model, const ITimelineDecoder::Relationship relationship) |
| 68 | { |
| 69 | model.m_Relationships.emplace_back(relationship); |
| 70 | } |
| 71 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 72 | BOOST_AUTO_TEST_CASE(TimelineDirectoryTest) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 73 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 74 | uint32_t uint8_t_size = sizeof(uint8_t); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 75 | uint32_t uint32_t_size = sizeof(uint32_t); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 76 | uint32_t uint64_t_size = sizeof(uint64_t); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 77 | |
| 78 | profiling::BufferManager bufferManager(5); |
| 79 | profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 80 | |
| 81 | std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket = |
| 82 | timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 83 | |
| 84 | profiling::PacketVersionResolver packetVersionResolver; |
| 85 | |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 86 | TimelineDecoder timelineDecoder; |
| 87 | TimelineCaptureCommandHandler timelineCaptureCommandHandler( |
| 88 | 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder); |
| 89 | |
Finn Williams | 8a2b468 | 2020-02-26 10:25:26 +0000 | [diff] [blame] | 90 | TimelineDirectoryCaptureCommandHandler timelineDirectoryCaptureCommandHandler( |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 91 | 1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue(), |
| 92 | timelineCaptureCommandHandler, true); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 93 | |
| 94 | sendTimelinePacket->SendTimelineMessageDirectoryPackage(); |
| 95 | sendTimelinePacket->Commit(); |
| 96 | |
| 97 | std::vector<profiling::SwTraceMessage> swTraceBufferMessages; |
| 98 | |
| 99 | unsigned int offset = uint32_t_size * 2; |
| 100 | |
| 101 | std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer(); |
| 102 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 103 | uint8_t readStreamVersion = ReadUint8(packetBuffer, offset); |
| 104 | BOOST_CHECK(readStreamVersion == 4); |
| 105 | offset += uint8_t_size; |
| 106 | uint8_t readPointerBytes = ReadUint8(packetBuffer, offset); |
| 107 | BOOST_CHECK(readPointerBytes == uint64_t_size); |
| 108 | offset += uint8_t_size; |
| 109 | uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset); |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 110 | BOOST_CHECK(readThreadIdBytes == armnn::profiling::ThreadIdSize); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 111 | offset += uint8_t_size; |
| 112 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 113 | uint32_t declarationSize = profiling::ReadUint32(packetBuffer, offset); |
| 114 | offset += uint32_t_size; |
| 115 | for(uint32_t i = 0; i < declarationSize; ++i) |
| 116 | { |
Kevin May | c135179 | 2020-07-28 11:29:04 +0100 | [diff] [blame] | 117 | swTraceBufferMessages.push_back(profiling::ReadSwTraceMessage(packetBuffer->GetReadableData(), |
| 118 | offset, |
| 119 | packetBuffer->GetSize())); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | SendTimelinePacketToCommandHandler(packetBuffer->GetReadableData(), timelineDirectoryCaptureCommandHandler); |
| 123 | |
| 124 | for(uint32_t index = 0; index < declarationSize; ++index) |
| 125 | { |
| 126 | profiling::SwTraceMessage& bufferMessage = swTraceBufferMessages[index]; |
| 127 | profiling::SwTraceMessage& handlerMessage = timelineDirectoryCaptureCommandHandler.m_SwTraceMessages[index]; |
| 128 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 129 | BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name); |
| 130 | BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName); |
| 131 | BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 132 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 133 | BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size()); |
| 134 | for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 135 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 136 | BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 139 | BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size()); |
| 140 | for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 141 | { |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 142 | BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | BOOST_AUTO_TEST_CASE(TimelineCaptureTest) |
| 148 | { |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 149 | profiling::BufferManager bufferManager(50); |
| 150 | profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 151 | |
| 152 | std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket = |
| 153 | timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 154 | |
| 155 | profiling::PacketVersionResolver packetVersionResolver; |
| 156 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 157 | TimelineDecoder timelineDecoder; |
| 158 | const TimelineDecoder::Model& model = timelineDecoder.GetModel(); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 159 | |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 160 | |
Finn Williams | 8a2b468 | 2020-02-26 10:25:26 +0000 | [diff] [blame] | 161 | TimelineCaptureCommandHandler timelineCaptureCommandHandler( |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 162 | 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder, |
| 163 | armnn::profiling::ThreadIdSize); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 164 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 165 | using Status = ITimelineDecoder::TimelineStatus; |
| 166 | BOOST_CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success); |
| 167 | BOOST_CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success); |
| 168 | BOOST_CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success); |
| 169 | BOOST_CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success); |
| 170 | BOOST_CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 171 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 172 | const uint64_t entityGuid = 111111u; |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 173 | const uint64_t eventClassGuid = 22222u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 174 | const uint64_t eventClassNameGuid = 22322u; |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 175 | const uint64_t timestamp = 33333u; |
| 176 | const uint64_t eventGuid = 44444u; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 177 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 178 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 179 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 180 | // need to do a bit of work here to extract the value from threadId |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 181 | unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize]();; |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 182 | uint64_t uint64ThreadId; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 183 | |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 184 | profiling::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 185 | |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 186 | if (armnn::profiling::ThreadIdSize == 4) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 187 | { |
| 188 | uint64ThreadId = profiling::ReadUint32(uCharThreadId, 0); |
| 189 | } |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 190 | else if (armnn::profiling::ThreadIdSize == 8) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 191 | { |
| 192 | uint64ThreadId = profiling::ReadUint64(uCharThreadId, 0); |
| 193 | } |
| 194 | delete[] uCharThreadId; |
| 195 | |
| 196 | const uint64_t labelGuid = 66666u; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 197 | std::string labelName = "test_label"; |
| 198 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 199 | const uint64_t relationshipGuid = 77777u; |
| 200 | const uint64_t headGuid = 888888u; |
| 201 | const uint64_t tailGuid = 999999u; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 202 | |
| 203 | for (int i = 0; i < 10; ++i) |
| 204 | { |
| 205 | // Send entity |
| 206 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid); |
| 207 | sendTimelinePacket->Commit(); |
| 208 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 209 | timelineCaptureCommandHandler); |
| 210 | |
| 211 | // Send event class |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 212 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 213 | sendTimelinePacket->Commit(); |
| 214 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 215 | timelineCaptureCommandHandler); |
| 216 | |
| 217 | // Send event |
| 218 | sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid); |
| 219 | sendTimelinePacket->Commit(); |
| 220 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 221 | timelineCaptureCommandHandler); |
| 222 | |
| 223 | // Send label |
| 224 | sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName); |
| 225 | sendTimelinePacket->Commit(); |
| 226 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 227 | timelineCaptureCommandHandler); |
| 228 | |
| 229 | // Send relationship |
| 230 | profiling::ProfilingRelationshipType relationshipType = profiling::ProfilingRelationshipType::DataLink; |
| 231 | sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType, |
| 232 | relationshipGuid, |
| 233 | headGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 234 | tailGuid, |
| 235 | 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 236 | sendTimelinePacket->Commit(); |
| 237 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 238 | timelineCaptureCommandHandler); |
| 239 | } |
| 240 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 241 | for (unsigned long i = 0; i < 10; ++i) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 242 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 243 | BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 244 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 245 | BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 246 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 247 | BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp); |
| 248 | BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId); |
| 249 | BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 250 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 251 | BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid); |
| 252 | BOOST_CHECK(model.m_Labels[i].m_Name == labelName); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 253 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 254 | BOOST_CHECK(model.m_Relationships[i].m_RelationshipType == ITimelineDecoder::RelationshipType::DataLink); |
| 255 | BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid); |
| 256 | BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid); |
| 257 | BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 258 | } |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 261 | BOOST_AUTO_TEST_CASE(TimelineCaptureTestMultipleStringsInBuffer) |
| 262 | { |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 263 | profiling::BufferManager bufferManager(50); |
| 264 | profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 265 | |
| 266 | std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket = |
| 267 | timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 268 | |
| 269 | profiling::PacketVersionResolver packetVersionResolver; |
| 270 | |
| 271 | TimelineDecoder timelineDecoder; |
| 272 | const TimelineDecoder::Model& model = timelineDecoder.GetModel(); |
| 273 | |
| 274 | TimelineCaptureCommandHandler timelineCaptureCommandHandler( |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 275 | 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder, |
| 276 | armnn::profiling::ThreadIdSize); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 277 | |
| 278 | using Status = ITimelineDecoder::TimelineStatus; |
| 279 | BOOST_CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success); |
| 280 | BOOST_CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success); |
| 281 | BOOST_CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success); |
| 282 | BOOST_CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success); |
| 283 | BOOST_CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success); |
| 284 | |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 285 | 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 Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 290 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 291 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 292 | |
| 293 | // need to do a bit of work here to extract the value from threadId |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 294 | unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize](); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 295 | uint64_t uint64ThreadId; |
| 296 | |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 297 | profiling::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 298 | |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 299 | if ( armnn::profiling::ThreadIdSize == 4 ) |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 300 | { |
| 301 | uint64ThreadId = profiling::ReadUint32(uCharThreadId, 0); |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 302 | } |
| 303 | else if ( armnn::profiling::ThreadIdSize == 8 ) |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 304 | { |
| 305 | uint64ThreadId = profiling::ReadUint64(uCharThreadId, 0); |
| 306 | } |
| 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 Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 324 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 325 | // 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 |
| 332 | profiling::ProfilingRelationshipType relationshipType = profiling::ProfilingRelationshipType::DataLink; |
| 333 | sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType, |
| 334 | relationshipGuid, |
| 335 | headGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 336 | tailGuid, |
| 337 | 0); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | sendTimelinePacket->Commit(); |
| 341 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 342 | timelineCaptureCommandHandler); |
| 343 | |
| 344 | for ( unsigned long i = 0; i < 9; ++i ) |
| 345 | { |
| 346 | BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid); |
| 347 | |
| 348 | BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid); |
| 349 | |
| 350 | BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid); |
| 351 | |
| 352 | BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp); |
| 353 | BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId); |
| 354 | BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid); |
| 355 | |
| 356 | BOOST_CHECK(model.m_Relationships[i].m_RelationshipType == ITimelineDecoder::RelationshipType::DataLink); |
| 357 | BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid); |
| 358 | BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid); |
| 359 | BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid); |
| 360 | } |
| 361 | for ( unsigned long i = 0; i < 9; i += 3 ) |
| 362 | { |
| 363 | BOOST_CHECK(model.m_Labels[i].m_Name == labelName); |
| 364 | BOOST_CHECK(model.m_Labels[i+1].m_Name == labelName2); |
| 365 | BOOST_CHECK(model.m_Labels[i+2].m_Name == labelName3); |
| 366 | } |
| 367 | } |
| 368 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 369 | BOOST_AUTO_TEST_SUITE_END() |