From bbfe603e5ae42317a2b67d713d00882bea341c88 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Mon, 20 Jul 2020 16:57:44 +0100 Subject: IVGCVSW-5166 Pull out the common and server side code into standalone libraries Change-Id: I180f84c493a9b2be4b93b25d312ebdd9e71b1735 Signed-off-by: Jim Flynn --- profiling/common/src/CommonProfilingUtils.cpp | 145 ++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 profiling/common/src/CommonProfilingUtils.cpp (limited to 'profiling/common/src/CommonProfilingUtils.cpp') diff --git a/profiling/common/src/CommonProfilingUtils.cpp b/profiling/common/src/CommonProfilingUtils.cpp new file mode 100644 index 0000000000..fe98e0aaa9 --- /dev/null +++ b/profiling/common/src/CommonProfilingUtils.cpp @@ -0,0 +1,145 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include +#include + +#include + +namespace arm +{ + +namespace pipe +{ +void ReadBytes(const unsigned char* buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]) +{ + ARM_PIPE_ASSERT(buffer); + ARM_PIPE_ASSERT(outValue); + + for (unsigned int i = 0; i < valueSize; i++, offset++) + { + outValue[i] = static_cast(buffer[offset]); + } +} + +uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset) +{ + ARM_PIPE_ASSERT(buffer); + + uint64_t value = 0; + value = static_cast(buffer[offset]); + value |= static_cast(buffer[offset + 1]) << 8; + value |= static_cast(buffer[offset + 2]) << 16; + value |= static_cast(buffer[offset + 3]) << 24; + value |= static_cast(buffer[offset + 4]) << 32; + value |= static_cast(buffer[offset + 5]) << 40; + value |= static_cast(buffer[offset + 6]) << 48; + value |= static_cast(buffer[offset + 7]) << 56; + + return value; +} + +uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset) +{ + ARM_PIPE_ASSERT(buffer); + + uint32_t value = 0; + value = static_cast(buffer[offset]); + value |= static_cast(buffer[offset + 1]) << 8; + value |= static_cast(buffer[offset + 2]) << 16; + value |= static_cast(buffer[offset + 3]) << 24; + return value; +} + +uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset) +{ + ARM_PIPE_ASSERT(buffer); + + uint32_t value = 0; + value = static_cast(buffer[offset]); + value |= static_cast(buffer[offset + 1]) << 8; + return static_cast(value); +} + +uint8_t ReadUint8(const unsigned char* buffer, unsigned int offset) +{ + ARM_PIPE_ASSERT(buffer); + + return buffer[offset]; +} + +void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize) +{ + ARM_PIPE_ASSERT(buffer); + ARM_PIPE_ASSERT(value); + + for (unsigned int i = 0; i < valueSize; i++, offset++) + { + buffer[offset] = *(reinterpret_cast(value) + i); + } +} + +void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value) +{ + ARM_PIPE_ASSERT(buffer); + + buffer[offset] = static_cast(value & 0xFF); + buffer[offset + 1] = static_cast((value >> 8) & 0xFF); + buffer[offset + 2] = static_cast((value >> 16) & 0xFF); + buffer[offset + 3] = static_cast((value >> 24) & 0xFF); + buffer[offset + 4] = static_cast((value >> 32) & 0xFF); + buffer[offset + 5] = static_cast((value >> 40) & 0xFF); + buffer[offset + 6] = static_cast((value >> 48) & 0xFF); + buffer[offset + 7] = static_cast((value >> 56) & 0xFF); +} + +void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value) +{ + ARM_PIPE_ASSERT(buffer); + + buffer[offset] = static_cast(value & 0xFF); + buffer[offset + 1] = static_cast((value >> 8) & 0xFF); + buffer[offset + 2] = static_cast((value >> 16) & 0xFF); + buffer[offset + 3] = static_cast((value >> 24) & 0xFF); +} + +void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value) +{ + ARM_PIPE_ASSERT(buffer); + + buffer[offset] = static_cast(value & 0xFF); + buffer[offset + 1] = static_cast((value >> 8) & 0xFF); +} + +void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value) +{ + ARM_PIPE_ASSERT(buffer); + + buffer[offset] = static_cast(value); +} + +std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth) +{ + std::stringstream outputStream, centrePadding; + int padding = spacingWidth - static_cast(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(); +} + + +} // namespace pipe +} // namespace arm \ No newline at end of file -- cgit v1.2.1