diff options
author | Keith Davis <keith.davis@arm.com> | 2019-10-24 17:30:41 +0100 |
---|---|---|
committer | Colm Donelan <colm.donelan@arm.com> | 2019-11-06 08:30:31 +0000 |
commit | 3201eea0565ce2bb0418d1936fec71bdeb14c084 (patch) | |
tree | f73017f6338d707165dbcfd717ddc9793b1858e0 /tests/profiling/gatordmock | |
parent | fe2e2cbbbe5294072b2d58755b8a095f32a97e75 (diff) | |
download | armnn-3201eea0565ce2bb0418d1936fec71bdeb14c084.tar.gz |
IVGCVSW-3444 File Only Profiling Connection
* Add FileOnlyProfilingConnection Decorator
* Fix bug where Conn Ack not automatically sent back
* Modify GatordMock to use the Counter Directory class.
* Promote DirectoryCaptureCommandHandler from GatordMock into ArmNN.
* Remove MockUtils as it's contents were moved or deleted.
* Rewrite GatordMockTests to use Counter Directory class.
* Flush streams in ProfilingConnectionDumpToFileDecorator::Close.
Signed-off-by: Keith Davis <keith.davis@arm.com>
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: I77b2aedece24150dd31691b577f3b5d81b2e226f
Diffstat (limited to 'tests/profiling/gatordmock')
-rw-r--r-- | tests/profiling/gatordmock/DirectoryCaptureCommandHandler.cpp | 341 | ||||
-rw-r--r-- | tests/profiling/gatordmock/DirectoryCaptureCommandHandler.hpp | 75 | ||||
-rw-r--r-- | tests/profiling/gatordmock/GatordMockMain.cpp | 4 | ||||
-rw-r--r-- | tests/profiling/gatordmock/GatordMockService.cpp | 23 | ||||
-rw-r--r-- | tests/profiling/gatordmock/MockUtils.cpp | 57 | ||||
-rw-r--r-- | tests/profiling/gatordmock/MockUtils.hpp | 25 | ||||
-rw-r--r-- | tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp | 17 | ||||
-rw-r--r-- | tests/profiling/gatordmock/tests/GatordMockTests.cpp | 142 |
8 files changed, 93 insertions, 591 deletions
diff --git a/tests/profiling/gatordmock/DirectoryCaptureCommandHandler.cpp b/tests/profiling/gatordmock/DirectoryCaptureCommandHandler.cpp deleted file mode 100644 index eafef0b53c..0000000000 --- a/tests/profiling/gatordmock/DirectoryCaptureCommandHandler.cpp +++ /dev/null @@ -1,341 +0,0 @@ -// -// Copyright © 2019 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include <atomic> -#include "DirectoryCaptureCommandHandler.hpp" - -namespace armnn -{ - -namespace gatordmock -{ - -// Utils -uint32_t uint16_t_size = sizeof(uint16_t); -uint32_t uint32_t_size = sizeof(uint32_t); - -void DirectoryCaptureCommandHandler::ParseData(const armnn::profiling::Packet& packet) -{ - uint16_t categoryRecordCount; - uint16_t counterSetRecordCount; - uint16_t deviceRecordCount; - - uint32_t offset = 0; - - if (packet.GetLength() < 8) - { - std::cout << "Counter directory packet received." << std::endl; - return; - } - - const unsigned char* data = reinterpret_cast<const unsigned char*>(packet.GetData()); - // Body header word 0: - // 0:15 [16] reserved: all zeros - offset += uint16_t_size; - // 16:31 [16] device_records_count: number of entries in the device_records_pointer_table - deviceRecordCount = profiling::ReadUint16(data, offset); - offset += uint16_t_size; - - // Body header word 1: - // 0:31 [32] device_records_pointer_table_offset: offset to the device_records_pointer_table - // The offset is always zero here, as the device record pointer table field is always the first item in the pool - offset += uint32_t_size; - - // Body header word 2: - // 0:15 [16] reserved: all zeros - offset += uint16_t_size; - // 16:31 [16] counter_set_count: number of entries in the counter_set_pointer_table - counterSetRecordCount = profiling::ReadUint16(data, offset); - offset += uint16_t_size; - - // Body header word 3: - // 0:31 [32] counter_set_pointer_table_offset: offset to the counter_set_pointer_table - // counterPointerTableSetOffset = profiling::ReadUint32(data, offset); - offset += uint32_t_size; - - // Body header word 4: - // 0:15 [16] reserved: all zeros - offset += uint16_t_size; - // 16:31 [16] categories_count: number of entries in the categories_pointer_table - categoryRecordCount = profiling::ReadUint16(data, offset); - offset += uint16_t_size; - - // Body header word 5: - // 0:31 [32] categories_pointer_table_offset: offset to the categories_pointer_table - // categoriesPointerTableOffset = profiling::ReadUint32(data, offset); - offset += uint32_t_size; - - std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount); - std::vector<uint32_t> counterSetOffsets(counterSetRecordCount); - std::vector<uint32_t> categoryOffsets(categoryRecordCount); - - for (uint32_t i = 0; i < deviceRecordCount; ++i) - { - deviceRecordOffsets[i] = profiling::ReadUint32(data, offset); - offset += uint32_t_size; - } - - for (uint32_t i = 0; i < counterSetRecordCount; ++i) - { - counterSetOffsets[i] = profiling::ReadUint32(data, offset); - offset += uint32_t_size; - } - - for (uint32_t i = 0; i < categoryRecordCount; ++i) - { - categoryOffsets[i] = profiling::ReadUint32(data, offset); - offset += uint32_t_size; - } - - m_CounterDirectory.m_DeviceRecords = ReadDeviceRecords(data, offset, deviceRecordOffsets); - m_CounterDirectory.m_CounterSets = ReadCounterSetRecords(data, offset, counterSetOffsets); - m_CounterDirectory.m_Categories = ReadCategoryRecords(data, offset, categoryOffsets); - - m_CounterDirectoryCount.operator++(std::memory_order_release); -} - -std::vector<DeviceRecord> DirectoryCaptureCommandHandler::ReadDeviceRecords(const unsigned char* const data, - uint32_t offset, - std::vector<uint32_t> deviceRecordOffsets) -{ - uint32_t deviceRecordCount = static_cast<uint32_t >(deviceRecordOffsets.size()); - std::vector<DeviceRecord> deviceRecords(deviceRecordCount); - - for(uint32_t deviceIndex = 0; deviceIndex < deviceRecordCount; ++deviceIndex) - { - uint32_t deviceRecordOffset = offset + deviceRecordOffsets[deviceIndex]; - // Device record word 0: - // 0:15 [16] cores: the number of individual streams of counters for one or more cores of some device - deviceRecords[deviceIndex].m_DeviceCores = profiling::ReadUint16(data, deviceRecordOffset); - // 16:31 [16] deviceUid: the unique identifier for the device - deviceRecordOffset += uint16_t_size; - deviceRecords[deviceIndex].m_DeviceUid = profiling::ReadUint16(data, deviceRecordOffset); - deviceRecordOffset += uint16_t_size; - - // Device record word 1: - // Offset from the beginning of the device record pool to the name field. - uint32_t nameOffset = profiling::ReadUint32(data, deviceRecordOffset); - - deviceRecordOffset += uint32_t_size; - deviceRecordOffset += uint32_t_size; - deviceRecordOffset += nameOffset; - - deviceRecords[deviceIndex].m_DeviceName = GetStringNameFromBuffer(data, deviceRecordOffset); - } - - return deviceRecords; -} - - -std::vector<CounterSetRecord> - DirectoryCaptureCommandHandler::ReadCounterSetRecords(const unsigned char* const data, - uint32_t offset, - std::vector<uint32_t> counterSetOffsets) -{ - uint32_t counterSetRecordCount = static_cast<uint32_t >(counterSetOffsets.size()); - std::vector<CounterSetRecord> counterSets(counterSetRecordCount); - - for (uint32_t counterSetIndex = 0; counterSetIndex < counterSetRecordCount; ++counterSetIndex) - { - uint32_t counterSetOffset = offset + counterSetOffsets[counterSetIndex]; - - // Counter set record word 0: - // 0:15 [16] count: the number of counters which can be active in this set at any one time - counterSets[counterSetIndex].m_CounterSetCount = profiling::ReadUint16(data, counterSetOffset); - counterSetOffset += uint16_t_size; - - // 16:31 [16] deviceUid: the unique identifier for the counter_set - counterSets[counterSetIndex].m_CounterSetUid = profiling::ReadUint16(data, counterSetOffset); - counterSetOffset += uint16_t_size; - - // Counter set record word 1: - // 0:31 [32] name_offset: offset from the beginning of the counter set pool to the name field - // The offset is always zero here, as the name field is always the first (and only) item in the pool - counterSetOffset += uint32_t_size; - counterSetOffset += uint32_t_size; - - counterSets[counterSetIndex].m_CounterSetName = GetStringNameFromBuffer(data, counterSetOffset); - } - - return counterSets; -} - -std::vector<CategoryRecord> DirectoryCaptureCommandHandler::ReadCategoryRecords(const unsigned char* const data, - uint32_t offset, - std::vector<uint32_t> categoryOffsets) -{ - uint32_t categoryRecordCount = static_cast<uint32_t >(categoryOffsets.size()); - std::vector<CategoryRecord> categories(categoryRecordCount); - - for (uint32_t categoryIndex = 0; categoryIndex < categoryRecordCount; ++categoryIndex) - { - uint32_t categoryRecordOffset = offset + categoryOffsets[categoryIndex]; - - // Category record word 0: - // 0:15 The deviceUid of a counter_set the category is associated with. - // Set to zero if the category is NOT associated with a counter set. - categories[categoryIndex].m_CounterSet = profiling::ReadUint16(data, categoryRecordOffset); - categoryRecordOffset += uint16_t_size; - - // 16:31 The deviceUid of a device element which identifies some hardware device that the category belongs to. - // Set to zero if the category is NOT associated with a device - categories[categoryIndex].m_DeviceUid = profiling::ReadUint16(data, categoryRecordOffset); - categoryRecordOffset += uint16_t_size; - - // Category record word 1: - // 0:15 Reserved, value 0x0000. - categoryRecordOffset += uint16_t_size; - // 16:31 Number of events belonging to this category. - categories[categoryIndex].m_EventCount = profiling::ReadUint16(data, categoryRecordOffset); - categoryRecordOffset += uint16_t_size; - - // Category record word 2 - // 0:31 Offset from the beginning of the category data pool to the event_pointer_table - uint32_t eventPointerTableOffset = profiling::ReadUint32(data, categoryRecordOffset); - categoryRecordOffset += uint32_t_size; - - // Category record word 3 - // 0:31 Offset from the beginning of the category data pool to the name field. - uint32_t nameOffset = profiling::ReadUint32(data, categoryRecordOffset); - categoryRecordOffset += uint32_t_size; - - //Get the events for the category - uint32_t eventCount = categories[categoryIndex].m_EventCount; - - std::vector<uint32_t> eventRecordsOffsets(eventCount); - - eventPointerTableOffset += categoryRecordOffset; - - for (uint32_t eventIndex = 0; eventIndex < eventCount; ++eventIndex) - { - eventRecordsOffsets[eventIndex] = - profiling::ReadUint32(data, eventPointerTableOffset + uint32_t_size * eventIndex); - } - - categories[categoryIndex].m_EventRecords = ReadEventRecords(data, categoryRecordOffset, eventRecordsOffsets); - - categoryRecordOffset += uint32_t_size; - - categories[categoryIndex].m_CategoryName = GetStringNameFromBuffer(data, categoryRecordOffset + nameOffset); - } - - return categories; -} - - -std::vector<EventRecord> DirectoryCaptureCommandHandler::ReadEventRecords(const unsigned char* const data, - uint32_t offset, - std::vector<uint32_t> eventRecordsOffsets) -{ - uint32_t eventCount = static_cast<uint32_t>(eventRecordsOffsets.size()); - - std::vector<EventRecord> eventRecords(eventCount); - for (unsigned long i = 0; i < eventCount; ++i) - { - uint32_t eventRecordOffset = eventRecordsOffsets[i] + offset; - - // Event record word 0: - // 0:15 [16] count_uid: unique ID for the counter. Must be unique across all counters in all categories - eventRecords[i].m_CounterUid = profiling::ReadUint16(data, eventRecordOffset); - eventRecordOffset += uint16_t_size; - // 16:31 [16] max_counter_uid: if the device this event is associated with has more than one core and there - // is one of these counters per core this value will be set to - // (counter_uid + cores (from device_record)) - 1. - // If there is only a single core then this value will be the same as - // the counter_uid value - eventRecords[i].m_MaxCounterUid = profiling::ReadUint16(data, eventRecordOffset); - eventRecordOffset += uint16_t_size; - - // Event record word 1: - // 0:15 [16] counter_set: UID of the counter_set this event is associated with. Set to zero if the event - // is NOT associated with a counter_set - eventRecords[i].m_DeviceUid = profiling::ReadUint16(data, eventRecordOffset); - eventRecordOffset += uint16_t_size; - - // 16:31 [16] device: UID of the device this event is associated with. Set to zero if the event is NOT - // associated with a device - eventRecords[i].m_CounterSetUid = profiling::ReadUint16(data, eventRecordOffset); - eventRecordOffset += uint16_t_size; - - // Event record word 2: - // 0:15 [16] interpolation: type describing how to interpolate each data point in a stream of data points - eventRecords[i].m_CounterClass =profiling::ReadUint16(data, eventRecordOffset); - eventRecordOffset += uint16_t_size; - - // 16:31 [16] class: type describing how to treat each data point in a stream of data points - eventRecords[i].m_CounterInterpolation = profiling::ReadUint16(data, eventRecordOffset); - eventRecordOffset += uint16_t_size; - - // Event record word 3-4: - // 0:63 [64] multiplier: internal data stream is represented as integer values, this allows scaling of - // those values as if they are fixed point numbers. Zero is not a valid value - uint32_t multiplier[2] = { 0u, 0u }; - - multiplier[0] = profiling::ReadUint32(data, eventRecordOffset); - eventRecordOffset += uint32_t_size; - multiplier[1] = profiling::ReadUint32(data, eventRecordOffset); - eventRecordOffset += uint32_t_size; - - std::memcpy(&eventRecords[i].m_CounterMultiplier, &multiplier, sizeof(multiplier)); - - // Event record word 5: - // 0:31 [32] name_eventRecordOffset: eventRecordOffset from the - // beginning of the event record pool to the name field - // The eventRecordOffset is always zero here, as the name field is always the first item in the pool - eventRecordOffset += uint32_t_size; - - // Event record word 6: - // 0:31 [32] description_eventRecordOffset: eventRecordOffset from the - // beginning of the event record pool to the description field - // The size of the name buffer in bytes - uint32_t descriptionOffset = profiling::ReadUint32(data, eventRecordOffset); - eventRecordOffset += uint32_t_size; - - // Event record word 7: - // 0:31 [32] units_eventRecordOffset: (optional) eventRecordOffset from the - // beginning of the event record pool to the units field. - // An eventRecordOffset value of zero indicates this field is not provided - uint32_t unitsOffset = profiling::ReadUint32(data, eventRecordOffset); - eventRecordOffset += uint32_t_size; - eventRecordOffset += uint32_t_size; - - eventRecords[i].m_CounterName = GetStringNameFromBuffer(data, eventRecordOffset); - - eventRecords[i].m_CounterDescription = GetStringNameFromBuffer(data, eventRecordOffset + descriptionOffset); - - eventRecords[i].m_CounterUnits = GetStringNameFromBuffer(data, eventRecordOffset + unitsOffset); - } - - return eventRecords; -} - -void DirectoryCaptureCommandHandler::operator()(const profiling::Packet& packet) -{ - if (!m_QuietOperation)// Are we supposed to print to stdout? - { - std::cout << "Counter directory packet received." << std::endl; - } - - ParseData(packet); - - if (!m_QuietOperation) - { - m_CounterDirectory.print(); - } -} - -CounterDirectory DirectoryCaptureCommandHandler::GetCounterDirectory() const -{ - return m_CounterDirectory; -} - -uint32_t DirectoryCaptureCommandHandler::GetCounterDirectoryCount() const -{ - return m_CounterDirectoryCount.load(std::memory_order_acquire); -} - -} // namespace gatordmock - -} // namespace armnn
\ No newline at end of file diff --git a/tests/profiling/gatordmock/DirectoryCaptureCommandHandler.hpp b/tests/profiling/gatordmock/DirectoryCaptureCommandHandler.hpp deleted file mode 100644 index 4cf96be741..0000000000 --- a/tests/profiling/gatordmock/DirectoryCaptureCommandHandler.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright © 2019 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#pragma once - -#include "CounterDirectory.hpp" -#include "GatordMockService.hpp" -#include "MockUtils.hpp" - - -#include "Packet.hpp" -#include "CommandHandlerFunctor.hpp" -#include "SendCounterPacket.hpp" -#include "IPeriodicCounterCapture.hpp" - - -#include <vector> -#include <thread> -#include <functional> - -namespace armnn -{ - -namespace gatordmock -{ - -class DirectoryCaptureCommandHandler : public profiling::CommandHandlerFunctor -{ - -public: - - DirectoryCaptureCommandHandler(uint32_t familyId, - uint32_t packetId, - uint32_t version, - bool quietOperation = false) - : CommandHandlerFunctor(familyId, packetId, version) - , m_QuietOperation(quietOperation) - , m_CounterDirectoryCount(0) - {} - - void operator()(const armnn::profiling::Packet &packet) override; - - CounterDirectory GetCounterDirectory() const; - uint32_t GetCounterDirectoryCount() const; - -private: - void ParseData(const armnn::profiling::Packet &packet); - - std::vector<CategoryRecord> ReadCategoryRecords(const unsigned char *const data, - uint32_t offset, - std::vector<uint32_t> categoryOffsets); - - std::vector<CounterSetRecord> ReadCounterSetRecords(const unsigned char *const data, - uint32_t offset, - std::vector<uint32_t> eventRecordsOffsets); - - std::vector<DeviceRecord> ReadDeviceRecords(const unsigned char *const data, - uint32_t offset, - std::vector<uint32_t> eventRecordsOffsets); - - std::vector<EventRecord> ReadEventRecords(const unsigned char *const data, - uint32_t offset, - std::vector<uint32_t> eventRecordsOffsets); - - CounterDirectory m_CounterDirectory; - - bool m_QuietOperation; - std::atomic<uint32_t> m_CounterDirectoryCount; -}; - -} // namespace gatordmock - -} // namespace armnn diff --git a/tests/profiling/gatordmock/GatordMockMain.cpp b/tests/profiling/gatordmock/GatordMockMain.cpp index 9dac6d976e..5f15db9002 100644 --- a/tests/profiling/gatordmock/GatordMockMain.cpp +++ b/tests/profiling/gatordmock/GatordMockMain.cpp @@ -35,8 +35,8 @@ int main(int argc, char* argv[]) armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler( 1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue()); - armnn::gatordmock::DirectoryCaptureCommandHandler directoryCaptureCommandHandler( - 0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue()); + armnn::profiling::DirectoryCaptureCommandHandler directoryCaptureCommandHandler( + 0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue(), false); // Register different derived functors registry.RegisterFunctor(&periodicCounterSelectionResponseHandler); diff --git a/tests/profiling/gatordmock/GatordMockService.cpp b/tests/profiling/gatordmock/GatordMockService.cpp index 5e9f8203d1..46f6547b41 100644 --- a/tests/profiling/gatordmock/GatordMockService.cpp +++ b/tests/profiling/gatordmock/GatordMockService.cpp @@ -6,8 +6,8 @@ #include "GatordMockService.hpp" #include <CommandHandlerRegistry.hpp> -#include "../../src/profiling/PacketVersionResolver.hpp" -#include "../../src/profiling/ProfilingUtils.hpp" +#include <PacketVersionResolver.hpp> +#include <ProfilingUtils.hpp> #include <cerrno> #include <fcntl.h> @@ -231,12 +231,12 @@ void GatordMockService::ReceiveLoop(GatordMockService& mockService) { // In this case we ignore timeouts and and keep trying to receive. } - catch (const armnn::InvalidArgumentException &e) + catch (const armnn::InvalidArgumentException& e) { // We couldn't find a functor to handle the packet? std::cerr << "Packet received that could not be processed: " << e.what() << std::endl; } - catch (const armnn::RuntimeException &e) + catch (const armnn::RuntimeException& e) { // A runtime exception occurred which means we must exit the loop. std::cerr << "Receive thread closing: " << e.what() << std::endl; @@ -331,15 +331,14 @@ armnn::profiling::Packet GatordMockService::ReceivePacket() std::cout << "Processing packet ID= " << packetRx.GetPacketId() << " Length=" << packetRx.GetLength() << std::endl; } - // Pass packet into the handler registry - m_PacketsReceivedCount.operator++(std::memory_order::memory_order_release); - m_HandlerRegistry - .GetFunctor(packetRx.GetPacketFamily(), - packetRx.GetPacketId(), - packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketFamily(), - packetRx.GetPacketId()).GetEncodedValue()) - ->operator()(packetRx); + profiling::Version version = + packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketFamily(), packetRx.GetPacketId()); + + profiling::CommandHandlerFunctor* commandHandlerFunctor = + m_HandlerRegistry.GetFunctor(packetRx.GetPacketFamily(), packetRx.GetPacketId(), version.GetEncodedValue()); + BOOST_ASSERT(commandHandlerFunctor); + commandHandlerFunctor->operator()(packetRx); return packetRx; } diff --git a/tests/profiling/gatordmock/MockUtils.cpp b/tests/profiling/gatordmock/MockUtils.cpp deleted file mode 100644 index bdbffc9253..0000000000 --- a/tests/profiling/gatordmock/MockUtils.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright © 2019 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#include "MockUtils.hpp" - -namespace armnn -{ - -namespace gatordmock -{ - -std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth) -{ - std::stringstream outputStream, centrePadding; - int padding = spacingWidth - static_cast<int>(stringToPass.size()); - - for (int i = 0; i < padding / 2; ++i) - { - centrePadding << " "; - } - - outputStream << centrePadding.str() << stringToPass << centrePadding.str(); - - if (padding > 0 && padding %2 != 0) - { - outputStream << " "; - } - - return outputStream.str(); -} - -std::string GetStringNameFromBuffer(const unsigned char* const data, uint32_t offset) -{ - std::string deviceName; - u_char nextChar = profiling::ReadUint8(data, offset); - - while (IsValidChar(nextChar)) - { - deviceName += static_cast<char>(nextChar); - offset ++; - nextChar = profiling::ReadUint8(data, offset); - } - - return deviceName; -} - -bool IsValidChar(unsigned char c) -{ - // Check that the given character has ASCII 7-bit encoding, alpha-numeric, whitespace, and underscore only - return c < 128 && (std::isalnum(c) || c == '_' || c == ' '); -} - -} // gatordmock - -} // armnn diff --git a/tests/profiling/gatordmock/MockUtils.hpp b/tests/profiling/gatordmock/MockUtils.hpp deleted file mode 100644 index 78bd867b0f..0000000000 --- a/tests/profiling/gatordmock/MockUtils.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright © 2017 Arm Ltd. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#pragma once - -#include <EncodeVersion.hpp> -#include <ProfilingUtils.hpp> - -namespace armnn -{ - -namespace gatordmock -{ - -std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth); - -std::string GetStringNameFromBuffer(const unsigned char *const data, uint32_t offset); - -bool IsValidChar(unsigned char c); - -} // gatordmock - -} // armnn diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp index 893351463f..9dd7064c90 100644 --- a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp +++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.cpp @@ -3,7 +3,6 @@ // SPDX-License-Identifier: MIT // -#include "MockUtils.hpp" #include "PeriodicCounterCaptureCommandHandler.hpp" #include <ProfilingUtils.hpp> @@ -94,24 +93,24 @@ void PeriodicCounterCaptureCommandHandler::operator()(const profiling::Packet& p valueString.append(", "); } - body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterCaptureValues.m_Timestamp), 10)); + body.append(profiling::CentreAlignFormatting(std::to_string(m_CounterCaptureValues.m_Timestamp), 10)); body.append(" | "); - body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CurrentPeriodValue), 13)); + body.append(profiling::CentreAlignFormatting(std::to_string(m_CurrentPeriodValue), 13)); body.append(" | "); - body.append(gatordmock::CentreAlignFormatting(uidString, 10)); + body.append(profiling::CentreAlignFormatting(uidString, 10)); body.append(" | "); - body.append(gatordmock::CentreAlignFormatting(valueString, 10)); + body.append(profiling::CentreAlignFormatting(valueString, 10)); body.append("\n"); if (!m_HeaderPrinted) { - header.append(gatordmock::CentreAlignFormatting(" Timestamp", 11)); + header.append(profiling::CentreAlignFormatting(" Timestamp", 11)); header.append(" | "); - header.append(gatordmock::CentreAlignFormatting("Period (us)", 13)); + header.append(profiling::CentreAlignFormatting("Period (us)", 13)); header.append(" | "); - header.append(gatordmock::CentreAlignFormatting("UID's", static_cast<int>(uidString.size()))); + header.append(profiling::CentreAlignFormatting("UID's", static_cast<int>(uidString.size()))); header.append(" | "); - header.append(gatordmock::CentreAlignFormatting("Values", 10)); + header.append(profiling::CentreAlignFormatting("Values", 10)); header.append("\n"); std::cout << header; diff --git a/tests/profiling/gatordmock/tests/GatordMockTests.cpp b/tests/profiling/gatordmock/tests/GatordMockTests.cpp index eb827bec69..1440f90905 100644 --- a/tests/profiling/gatordmock/tests/GatordMockTests.cpp +++ b/tests/profiling/gatordmock/tests/GatordMockTests.cpp @@ -5,9 +5,9 @@ #include "../GatordMockService.hpp" #include "../PeriodicCounterCaptureCommandHandler.hpp" -#include "../DirectoryCaptureCommandHandler.hpp" #include <CommandHandlerRegistry.hpp> +#include <DirectoryCaptureCommandHandler.hpp> #include <ProfilingService.hpp> #include <test/SendCounterPacketTests.hpp> @@ -87,8 +87,7 @@ BOOST_AUTO_TEST_CASE(CounterCaptureHandlingTest) profiling::Packet packet1(headerWord1, dataLength, uniqueData1); profiling::Packet packet2(headerWord1, dataLength, uniqueData2); - gatordmock::PeriodicCounterCaptureCommandHandler commandHandler - (0, 4, headerWord1, true); + gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(0, 4, headerWord1, true); // Simulate two separate packets coming in to calculate period commandHandler(packet1); @@ -108,7 +107,7 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd) // performance data. //These variables are used to wait for the profiling service - u_int32_t timeout = 2000; + u_int32_t timeout = 2000; u_int32_t sleepTime = 50; u_int32_t timeSlept = 0; @@ -118,11 +117,11 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd) profiling::CommandHandlerRegistry registry; // Update with derived functors - gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler - (0, 4, packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), true); + gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler( + 0, 4, packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), true); - gatordmock::DirectoryCaptureCommandHandler directoryCaptureCommandHandler - (0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue(), true); + profiling::DirectoryCaptureCommandHandler directoryCaptureCommandHandler( + 0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue(), true); // Register different derived functors registry.RegisterFunctor(&counterCaptureCommandHandler); @@ -183,10 +182,9 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd) } mockService.LaunchReceivingThread(); - mockService.SendRequestCounterDir(); - + // As part of the default startup of the profiling service a counter directory packet will be sent. timeSlept = 0; - while (directoryCaptureCommandHandler.GetCounterDirectoryCount() == 0) + while (!directoryCaptureCommandHandler.ParsedCounterDirectory()) { if (timeSlept >= timeout) { @@ -196,81 +194,85 @@ BOOST_AUTO_TEST_CASE(GatorDMockEndToEnd) timeSlept += sleepTime; } - const profiling::ICounterDirectory& serviceCounterDirectory = profilingService.GetCounterDirectory(); - gatordmock::CounterDirectory mockCounterDirectory = directoryCaptureCommandHandler.GetCounterDirectory(); + const profiling::ICounterDirectory& serviceCounterDirectory = profilingService.GetCounterDirectory(); + const profiling::ICounterDirectory& receivedCounterDirectory = directoryCaptureCommandHandler.GetCounterDirectory(); - BOOST_ASSERT(serviceCounterDirectory.GetDeviceCount() == mockCounterDirectory.m_DeviceRecords.size()); - BOOST_ASSERT(serviceCounterDirectory.GetCounterSetCount() == mockCounterDirectory.m_CounterSets.size()); - BOOST_ASSERT(serviceCounterDirectory.GetCategoryCount() == mockCounterDirectory.m_Categories.size()); + // Compare thre basics of the counter directory from the service and the one we received over the wire. + BOOST_ASSERT(serviceCounterDirectory.GetDeviceCount() == receivedCounterDirectory.GetDeviceCount()); + BOOST_ASSERT(serviceCounterDirectory.GetCounterSetCount() == receivedCounterDirectory.GetCounterSetCount()); + BOOST_ASSERT(serviceCounterDirectory.GetCategoryCount() == receivedCounterDirectory.GetCategoryCount()); + BOOST_ASSERT(serviceCounterDirectory.GetCounterCount() == receivedCounterDirectory.GetCounterCount()); - const profiling::Devices& serviceDevices = serviceCounterDirectory.GetDevices(); + receivedCounterDirectory.GetDeviceCount(); + serviceCounterDirectory.GetDeviceCount(); - uint32_t deviceIndex = 0; + const profiling::Devices& serviceDevices = serviceCounterDirectory.GetDevices(); for (auto& device : serviceDevices) { - BOOST_ASSERT(device.second->m_Name.size() == - mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceName.size()); - - BOOST_CHECK(device.second->m_Name == mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceName); - BOOST_CHECK(device.second->m_Uid == mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceUid); - BOOST_CHECK(device.second->m_Cores == mockCounterDirectory.m_DeviceRecords[deviceIndex].m_DeviceCores); - deviceIndex++; + // Find the same device in the received counter directory. + auto foundDevice = receivedCounterDirectory.GetDevices().find(device.second->m_Uid); + BOOST_CHECK(foundDevice != receivedCounterDirectory.GetDevices().end()); + BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0); + BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores); } - const profiling::CounterSets & serviceCounterSets = serviceCounterDirectory.GetCounterSets(); - uint32_t counterSetIndex = 0; + const profiling::CounterSets& serviceCounterSets = serviceCounterDirectory.GetCounterSets(); for (auto& counterSet : serviceCounterSets) { - BOOST_ASSERT(counterSet.second->m_Name.size() == - mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetName.size()); - - BOOST_CHECK(counterSet.second->m_Name == mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetName); - BOOST_CHECK(counterSet.second->m_Uid == mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetUid); - BOOST_CHECK(counterSet.second->m_Count == - mockCounterDirectory.m_CounterSets[counterSetIndex].m_CounterSetCount); - counterSetIndex++; + // Find the same counter set in the received counter directory. + auto foundCounterSet = receivedCounterDirectory.GetCounterSets().find(counterSet.second->m_Uid); + BOOST_CHECK(foundCounterSet != receivedCounterDirectory.GetCounterSets().end()); + BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0); + BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count); } const profiling::Categories& serviceCategories = serviceCounterDirectory.GetCategories(); - const std::vector<gatordmock::CategoryRecord> mockCategories = mockCounterDirectory.m_Categories; - - uint32_t categoryIndex = 0; for (auto& category : serviceCategories) { - BOOST_ASSERT(category->m_Name.size() == mockCategories[categoryIndex].m_CategoryName.size()); - - BOOST_CHECK(category->m_Name == mockCategories[categoryIndex].m_CategoryName); - BOOST_CHECK(category->m_CounterSetUid == mockCategories[categoryIndex].m_CounterSet); - BOOST_CHECK(category->m_DeviceUid == mockCategories[categoryIndex].m_DeviceUid); - - const std::vector<gatordmock::EventRecord> events = mockCategories[categoryIndex].m_EventRecords; - uint32_t eventIndex = 0; - for (uint16_t counterUid : category->m_Counters) + for (auto& receivedCategory : receivedCounterDirectory.GetCategories()) { - const profiling::Counter* counter = serviceCounterDirectory.GetCounter(counterUid); - - BOOST_CHECK(counterUid == events[eventIndex].m_CounterUid); - - BOOST_ASSERT(counter->m_Name.size() == events[eventIndex].m_CounterName.size()); - BOOST_ASSERT(counter->m_Units.size() == events[eventIndex].m_CounterUnits.size()); - BOOST_ASSERT(counter->m_Description.size() == events[eventIndex].m_CounterDescription.size()); - - BOOST_CHECK(counter->m_Name == events[eventIndex].m_CounterName); - BOOST_CHECK(counter->m_Units == events[eventIndex].m_CounterUnits); - BOOST_CHECK(counter->m_Description == events[eventIndex].m_CounterDescription); - - BOOST_CHECK(counter->m_CounterSetUid == events[eventIndex].m_CounterSetUid); - BOOST_CHECK(counter->m_DeviceUid == events[eventIndex].m_DeviceUid); - BOOST_CHECK(counter->m_Uid == events[eventIndex].m_CounterUid); - - BOOST_CHECK(counter->m_Multiplier == events[eventIndex].m_CounterMultiplier); - BOOST_CHECK(counter->m_MaxCounterUid == events[eventIndex].m_MaxCounterUid); - BOOST_CHECK(counter->m_Interpolation == events[eventIndex].m_CounterInterpolation); - BOOST_CHECK(counter->m_Class == events[eventIndex].m_CounterClass); - - eventIndex++; + if (receivedCategory->m_Name.compare(category->m_Name) == 0) + { + // We've found the matching category. + BOOST_CHECK(category->m_DeviceUid == receivedCategory->m_DeviceUid); + BOOST_CHECK(category->m_CounterSetUid == receivedCategory->m_CounterSetUid); + // Now look at the interiors of the counters. Start by sorting them. + std::sort(category->m_Counters.begin(), category->m_Counters.end()); + std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end()); + // When comparing uid's here we need to translate them. + std::function<bool(const uint16_t&, const uint16_t&)> comparator = + [&directoryCaptureCommandHandler](const uint16_t& first, const uint16_t& second) { + uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(second); + if (translated == first) + { + return true; + } + return false; + }; + // Then let vector == do the work. + BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(), + receivedCategory->m_Counters.begin(), comparator)); + break; + } } - categoryIndex++; + } + + // Finally check the content of the counters. + const profiling::Counters& receivedCounters = receivedCounterDirectory.GetCounters(); + for (auto& receivedCounter : receivedCounters) + { + // Translate the Uid and find the corresponding counter in the original counter directory. + // Note we can't check m_MaxCounterUid here as it will likely differ between the two counter directories. + uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(receivedCounter.first); + const profiling::Counter* serviceCounter = serviceCounterDirectory.GetCounter(translated); + BOOST_CHECK(serviceCounter->m_DeviceUid == receivedCounter.second->m_DeviceUid); + BOOST_CHECK(serviceCounter->m_Name.compare(receivedCounter.second->m_Name) == 0); + BOOST_CHECK(serviceCounter->m_CounterSetUid == receivedCounter.second->m_CounterSetUid); + BOOST_CHECK(serviceCounter->m_Multiplier == receivedCounter.second->m_Multiplier); + BOOST_CHECK(serviceCounter->m_Interpolation == receivedCounter.second->m_Interpolation); + BOOST_CHECK(serviceCounter->m_Class == receivedCounter.second->m_Class); + BOOST_CHECK(serviceCounter->m_Units.compare(receivedCounter.second->m_Units) == 0); + BOOST_CHECK(serviceCounter->m_Description.compare(receivedCounter.second->m_Description) == 0); } mockService.WaitForReceivingThread(); |