IVGCVSW-3691 Basic refactoring in view of upcoming work in the profiler
[platform/upstream/armnn.git] / src / profiling / ProfilingUtils.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ProfilingUtils.hpp"
7
8 #include <armnn/Version.hpp>
9
10 #include <boost/assert.hpp>
11
12 #include <fstream>
13
14 namespace armnn
15 {
16
17 namespace profiling
18 {
19
20 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value)
21 {
22     BOOST_ASSERT(buffer);
23
24     buffer[offset]     = static_cast<unsigned char>(value & 0xFF);
25     buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
26     buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
27     buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
28     buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF);
29     buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF);
30     buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF);
31     buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF);
32 }
33
34 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value)
35 {
36     BOOST_ASSERT(buffer);
37
38     buffer[offset]     = static_cast<unsigned char>(value & 0xFF);
39     buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
40     buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
41     buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
42 }
43
44 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
45 {
46     BOOST_ASSERT(buffer);
47
48     buffer[offset]     = static_cast<unsigned char>(value & 0xFF);
49     buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
50 }
51
52 uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset)
53 {
54     BOOST_ASSERT(buffer);
55
56     uint64_t value = 0;
57     value = static_cast<uint64_t>(buffer[offset]);
58     value |= static_cast<uint64_t>(buffer[offset + 1]) << 8;
59     value |= static_cast<uint64_t>(buffer[offset + 2]) << 16;
60     value |= static_cast<uint64_t>(buffer[offset + 3]) << 24;
61     value |= static_cast<uint64_t>(buffer[offset + 4]) << 32;
62     value |= static_cast<uint64_t>(buffer[offset + 5]) << 40;
63     value |= static_cast<uint64_t>(buffer[offset + 6]) << 48;
64     value |= static_cast<uint64_t>(buffer[offset + 7]) << 56;
65
66     return value;
67 }
68
69 uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset)
70 {
71     BOOST_ASSERT(buffer);
72
73     uint32_t value = 0;
74     value  = static_cast<uint32_t>(buffer[offset]);
75     value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
76     value |= static_cast<uint32_t>(buffer[offset + 2]) << 16;
77     value |= static_cast<uint32_t>(buffer[offset + 3]) << 24;
78     return value;
79 }
80
81 uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset)
82 {
83     BOOST_ASSERT(buffer);
84
85     uint32_t value = 0;
86     value  = static_cast<uint32_t>(buffer[offset]);
87     value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
88     return static_cast<uint16_t>(value);
89 }
90
91 std::string GetSoftwareInfo()
92 {
93     return std::string("ArmNN");
94 }
95
96 std::string GetHardwareVersion()
97 {
98     return std::string();
99 }
100
101 std::string GetSoftwareVersion()
102 {
103     std::string armnnVersion(ARMNN_VERSION);
104     std::string result = "Armnn " + armnnVersion.substr(2,2) + "." + armnnVersion.substr(4,2);
105     return result;
106 }
107
108 std::string GetProcessName()
109 {
110     std::ifstream comm("/proc/self/comm");
111     std::string name;
112     getline(comm, name);
113     return name;
114 }
115
116 } // namespace profiling
117
118 } // namespace armnn