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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 6 | #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 Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 11 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 12 | #include <BufferManager.hpp> |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 13 | #include <Threads.hpp> |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 14 | #include <ProfilingService.hpp> |
| 15 | #include <PacketBuffer.hpp> |
| 16 | #include <TimelinePacketWriterFactory.hpp> |
| 17 | |
| 18 | #include <boost/test/test_tools.hpp> |
| 19 | #include <boost/test/unit_test_suite.hpp> |
| 20 | |
| 21 | BOOST_AUTO_TEST_SUITE(TimelineDecoderTests) |
| 22 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 23 | void SendTimelinePacketToCommandHandler(const unsigned char* packetBuffer, |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 24 | arm::pipe::CommandHandlerFunctor& CommandHandler) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 25 | { |
| 26 | uint32_t uint32_t_size = sizeof(uint32_t); |
| 27 | unsigned int offset = 0; |
| 28 | |
| 29 | uint32_t header[2]; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 30 | header[0] = arm::pipe::ReadUint32(packetBuffer, offset); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 31 | offset += uint32_t_size; |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 32 | header[1] = arm::pipe::ReadUint32(packetBuffer, offset); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 33 | offset += uint32_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 34 | uint32_t PacketDataLength = header[1] & 0x00FFFFFF; |
| 35 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 36 | auto uniquePacketData = std::make_unique<unsigned char[]>(PacketDataLength); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 37 | std::memcpy(uniquePacketData.get(), packetBuffer + offset, PacketDataLength); |
| 38 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 39 | arm::pipe::Packet packet(header[0], PacketDataLength, uniquePacketData); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 40 | |
| 41 | BOOST_CHECK(std::memcmp(packetBuffer + offset, packet.GetData(), packet.GetLength()) == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 42 | |
| 43 | CommandHandler(packet); |
| 44 | } |
| 45 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 46 | void PushEntity(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Entity entity) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 47 | { |
| 48 | model.m_Entities.emplace_back(entity); |
| 49 | } |
| 50 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 51 | void PushEventClass(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::EventClass eventClass) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 52 | { |
| 53 | model.m_EventClasses.emplace_back(eventClass); |
| 54 | } |
| 55 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 56 | void PushEvent(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Event event) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 57 | { |
| 58 | model.m_Events.emplace_back(event); |
| 59 | } |
| 60 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 61 | void PushLabel(arm::pipe::TimelineDecoder::Model& model, const arm::pipe::ITimelineDecoder::Label label) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 62 | { |
| 63 | model.m_Labels.emplace_back(label); |
| 64 | } |
| 65 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 66 | void PushRelationship(arm::pipe::TimelineDecoder::Model& model, |
| 67 | const arm::pipe::ITimelineDecoder::Relationship relationship) |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 78 | armnn::profiling::BufferManager bufferManager(5); |
| 79 | armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 80 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 81 | std::unique_ptr<armnn::profiling::ISendTimelinePacket> sendTimelinePacket = |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 82 | timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 83 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 84 | arm::pipe::PacketVersionResolver packetVersionResolver; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 85 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 86 | arm::pipe::TimelineDecoder timelineDecoder; |
| 87 | arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler( |
Finn Williams | e6a2ccd | 2020-02-27 16:21:41 +0000 | [diff] [blame] | 88 | 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder); |
| 89 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 90 | arm::pipe::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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 97 | std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 98 | |
| 99 | unsigned int offset = uint32_t_size * 2; |
| 100 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 101 | std::unique_ptr<armnn::profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer(); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 113 | uint32_t declarationSize = arm::pipe::ReadUint32(packetBuffer->GetReadableData(), offset); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 114 | offset += uint32_t_size; |
| 115 | for(uint32_t i = 0; i < declarationSize; ++i) |
| 116 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 117 | swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(), |
Kevin May | c135179 | 2020-07-28 11:29:04 +0100 | [diff] [blame] | 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 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 126 | arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index]; |
| 127 | arm::pipe::SwTraceMessage& handlerMessage = timelineDirectoryCaptureCommandHandler.m_SwTraceMessages[index]; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 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 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 149 | armnn::profiling::BufferManager bufferManager(50); |
| 150 | armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 151 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 152 | std::unique_ptr<armnn::profiling::ISendTimelinePacket> sendTimelinePacket = |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 153 | timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 154 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 155 | arm::pipe::PacketVersionResolver packetVersionResolver; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 156 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 157 | arm::pipe::TimelineDecoder timelineDecoder; |
| 158 | const arm::pipe::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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 161 | arm::pipe::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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 165 | using Status = arm::pipe::ITimelineDecoder::TimelineStatus; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 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 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 184 | arm::pipe::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 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 188 | uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0); |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 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 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 192 | uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0); |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 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 |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 230 | armnn::profiling::ProfilingRelationshipType relationshipType = |
| 231 | armnn::profiling::ProfilingRelationshipType::DataLink; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 232 | sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType, |
| 233 | relationshipGuid, |
| 234 | headGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 235 | tailGuid, |
| 236 | 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 237 | sendTimelinePacket->Commit(); |
| 238 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 239 | timelineCaptureCommandHandler); |
| 240 | } |
| 241 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 242 | for (unsigned long i = 0; i < 10; ++i) |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 243 | { |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 244 | BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 245 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 246 | BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 247 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 248 | BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp); |
| 249 | BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId); |
| 250 | BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 251 | |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 252 | BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid); |
| 253 | BOOST_CHECK(model.m_Labels[i].m_Name == labelName); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 254 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 255 | BOOST_CHECK(model.m_Relationships[i].m_RelationshipType == |
| 256 | arm::pipe::ITimelineDecoder::RelationshipType::DataLink); |
Finn Williams | 510f618 | 2020-02-21 11:14:08 +0000 | [diff] [blame] | 257 | BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid); |
| 258 | BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid); |
| 259 | BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 260 | } |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 263 | BOOST_AUTO_TEST_CASE(TimelineCaptureTestMultipleStringsInBuffer) |
| 264 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 265 | armnn::profiling::BufferManager bufferManager(50); |
| 266 | armnn::profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 267 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 268 | std::unique_ptr<armnn::profiling::ISendTimelinePacket> sendTimelinePacket = |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 269 | timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 270 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 271 | arm::pipe::PacketVersionResolver packetVersionResolver; |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 272 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 273 | arm::pipe::TimelineDecoder timelineDecoder; |
| 274 | const arm::pipe::TimelineDecoder::Model& model = timelineDecoder.GetModel(); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 275 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 276 | arm::pipe::TimelineCaptureCommandHandler timelineCaptureCommandHandler( |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 277 | 1, 1, packetVersionResolver.ResolvePacketVersion(1, 1).GetEncodedValue(), timelineDecoder, |
| 278 | armnn::profiling::ThreadIdSize); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 279 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 280 | using Status = arm::pipe::TimelineDecoder::TimelineStatus; |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 281 | BOOST_CHECK(timelineDecoder.SetEntityCallback(PushEntity) == Status::TimelineStatus_Success); |
| 282 | BOOST_CHECK(timelineDecoder.SetEventClassCallback(PushEventClass) == Status::TimelineStatus_Success); |
| 283 | BOOST_CHECK(timelineDecoder.SetEventCallback(PushEvent) == Status::TimelineStatus_Success); |
| 284 | BOOST_CHECK(timelineDecoder.SetLabelCallback(PushLabel) == Status::TimelineStatus_Success); |
| 285 | BOOST_CHECK(timelineDecoder.SetRelationshipCallback(PushRelationship) == Status::TimelineStatus_Success); |
| 286 | |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 287 | const uint64_t entityGuid = 111111u; |
| 288 | const uint64_t eventClassGuid = 22222u; |
| 289 | const uint64_t eventClassNameGuid = 22322u; |
| 290 | const uint64_t timestamp = 33333u; |
| 291 | const uint64_t eventGuid = 44444u; |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 292 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 293 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 294 | |
| 295 | // 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] | 296 | unsigned char* uCharThreadId = new unsigned char[armnn::profiling::ThreadIdSize](); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 297 | uint64_t uint64ThreadId; |
| 298 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 299 | arm::pipe::WriteBytes(uCharThreadId, 0, &threadId, armnn::profiling::ThreadIdSize); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 300 | |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 301 | if ( armnn::profiling::ThreadIdSize == 4 ) |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 302 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 303 | uint64ThreadId = arm::pipe::ReadUint32(uCharThreadId, 0); |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 304 | } |
| 305 | else if ( armnn::profiling::ThreadIdSize == 8 ) |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 306 | { |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 307 | uint64ThreadId = arm::pipe::ReadUint64(uCharThreadId, 0); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 308 | } |
| 309 | delete[] uCharThreadId; |
| 310 | |
| 311 | const uint64_t labelGuid = 66666u; |
| 312 | std::string labelName = "test_label"; |
| 313 | std::string labelName2 = "test_label2"; |
| 314 | std::string labelName3 = "test_label32"; |
| 315 | |
| 316 | const uint64_t relationshipGuid = 77777u; |
| 317 | const uint64_t headGuid = 888888u; |
| 318 | const uint64_t tailGuid = 999999u; |
| 319 | |
| 320 | // Check with multiple messages in the same buffer |
| 321 | for ( int i = 0; i < 9; ++i ) |
| 322 | { |
| 323 | // Send entity |
| 324 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityGuid); |
| 325 | // Send event class |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 326 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassGuid, eventClassNameGuid); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 327 | // Send event |
| 328 | sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid); |
| 329 | // Send label |
| 330 | sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName); |
| 331 | sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName2); |
| 332 | sendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName3); |
| 333 | // Send relationship |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 334 | armnn::profiling::ProfilingRelationshipType relationshipType = |
| 335 | armnn::profiling::ProfilingRelationshipType::DataLink; |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 336 | sendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType, |
| 337 | relationshipGuid, |
| 338 | headGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 339 | tailGuid, |
| 340 | 0); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | sendTimelinePacket->Commit(); |
| 344 | SendTimelinePacketToCommandHandler(bufferManager.GetReadableBuffer()->GetReadableData(), |
| 345 | timelineCaptureCommandHandler); |
| 346 | |
| 347 | for ( unsigned long i = 0; i < 9; ++i ) |
| 348 | { |
| 349 | BOOST_CHECK(model.m_Entities[i].m_Guid == entityGuid); |
| 350 | |
| 351 | BOOST_CHECK(model.m_EventClasses[i].m_Guid == eventClassGuid); |
| 352 | |
| 353 | BOOST_CHECK(model.m_Labels[i].m_Guid == labelGuid); |
| 354 | |
| 355 | BOOST_CHECK(model.m_Events[i].m_TimeStamp == timestamp); |
| 356 | BOOST_CHECK(model.m_Events[i].m_ThreadId == uint64ThreadId); |
| 357 | BOOST_CHECK(model.m_Events[i].m_Guid == eventGuid); |
| 358 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame^] | 359 | BOOST_CHECK(model.m_Relationships[i].m_RelationshipType == |
| 360 | arm::pipe::ITimelineDecoder::RelationshipType::DataLink); |
Keith Davis | 5238aff | 2020-03-11 12:17:05 +0000 | [diff] [blame] | 361 | BOOST_CHECK(model.m_Relationships[i].m_Guid == relationshipGuid); |
| 362 | BOOST_CHECK(model.m_Relationships[i].m_HeadGuid == headGuid); |
| 363 | BOOST_CHECK(model.m_Relationships[i].m_TailGuid == tailGuid); |
| 364 | } |
| 365 | for ( unsigned long i = 0; i < 9; i += 3 ) |
| 366 | { |
| 367 | BOOST_CHECK(model.m_Labels[i].m_Name == labelName); |
| 368 | BOOST_CHECK(model.m_Labels[i+1].m_Name == labelName2); |
| 369 | BOOST_CHECK(model.m_Labels[i+2].m_Name == labelName3); |
| 370 | } |
| 371 | } |
| 372 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 373 | BOOST_AUTO_TEST_SUITE_END() |