Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | |
| 9 | #include "GatordMockService.hpp" |
| 10 | #include "MockUtils.hpp" |
| 11 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 12 | #include <common/include/Packet.hpp> |
| 13 | #include <common/include/CommandHandlerFunctor.hpp> |
| 14 | |
Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 15 | #include "SendCounterPacket.hpp" |
| 16 | #include "IPeriodicCounterCapture.hpp" |
| 17 | |
| 18 | #include <vector> |
| 19 | #include <thread> |
| 20 | #include <atomic> |
| 21 | #include <iostream> |
| 22 | #include <functional> |
| 23 | |
| 24 | namespace armnn |
| 25 | { |
| 26 | |
| 27 | namespace gatordmock |
| 28 | { |
| 29 | |
| 30 | struct EventRecord |
| 31 | { |
| 32 | uint16_t m_CounterUid; |
| 33 | uint16_t m_MaxCounterUid; |
| 34 | uint16_t m_DeviceUid; |
| 35 | uint16_t m_CounterSetUid; |
| 36 | uint16_t m_CounterClass; |
| 37 | uint16_t m_CounterInterpolation; |
| 38 | double m_CounterMultiplier; |
| 39 | std::string m_CounterName; |
| 40 | std::string m_CounterDescription; |
| 41 | std::string m_CounterUnits; |
| 42 | |
| 43 | static void printHeader(std::string categoryName) |
| 44 | { |
| 45 | std::string header; |
| 46 | |
| 47 | header.append(gatordmock::CentreAlignFormatting("Counter Name", 20)); |
| 48 | header.append(" | "); |
| 49 | header.append(gatordmock::CentreAlignFormatting("Description", 50)); |
| 50 | header.append(" | "); |
| 51 | header.append(gatordmock::CentreAlignFormatting("Units", 14)); |
| 52 | header.append(" | "); |
| 53 | header.append(gatordmock::CentreAlignFormatting("UID", 6)); |
| 54 | header.append(" | "); |
| 55 | header.append(gatordmock::CentreAlignFormatting("Max UID",10)); |
| 56 | header.append(" | "); |
| 57 | header.append(gatordmock::CentreAlignFormatting("Class", 8)); |
| 58 | header.append(" | "); |
| 59 | header.append(gatordmock::CentreAlignFormatting("Interpolation", 14)); |
| 60 | header.append(" | "); |
| 61 | header.append(gatordmock::CentreAlignFormatting("Multiplier", 20)); |
| 62 | header.append(" | "); |
| 63 | header.append(gatordmock::CentreAlignFormatting("Counter set UID", 16)); |
| 64 | header.append(" | "); |
| 65 | header.append(gatordmock::CentreAlignFormatting("Device UID", 14)); |
| 66 | header.append("\n"); |
| 67 | |
| 68 | std::cout << "\n" << "\n"; |
| 69 | std::cout << gatordmock::CentreAlignFormatting("EVENTS IN CATEGORY: " + categoryName, |
| 70 | static_cast<int>(header.size())); |
| 71 | std::cout << "\n"; |
| 72 | std::cout << std::string(header.size(), '=') << "\n"; |
| 73 | std::cout << header; |
| 74 | } |
| 75 | |
| 76 | void printContents() const |
| 77 | { |
| 78 | std::string body; |
| 79 | |
| 80 | body.append(gatordmock::CentreAlignFormatting(m_CounterName, 20)); |
| 81 | body.append(" | "); |
| 82 | body.append(gatordmock::CentreAlignFormatting(m_CounterDescription, 50)); |
| 83 | body.append(" | "); |
| 84 | body.append(gatordmock::CentreAlignFormatting(m_CounterUnits, 14)); |
| 85 | body.append(" | "); |
| 86 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterUid), 6)); |
| 87 | body.append(" | "); |
| 88 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_MaxCounterUid), 10)); |
| 89 | body.append(" | "); |
| 90 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterClass), 8)); |
| 91 | body.append(" | "); |
| 92 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterInterpolation), 14)); |
| 93 | body.append(" | "); |
| 94 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterMultiplier), 20)); |
| 95 | body.append(" | "); |
| 96 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterSetUid), 16)); |
| 97 | body.append(" | "); |
| 98 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_DeviceUid), 14)); |
| 99 | |
| 100 | body.append("\n"); |
| 101 | |
| 102 | std::cout << std::string(body.size(), '-') << "\n"; |
| 103 | |
| 104 | std::cout << body; |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | struct CategoryRecord |
| 109 | { |
Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 110 | uint16_t m_EventCount; |
| 111 | std::string m_CategoryName; |
| 112 | std::vector<EventRecord> m_EventRecords; |
| 113 | |
| 114 | void print() const |
| 115 | { |
| 116 | std::string body; |
| 117 | std::string header; |
| 118 | |
| 119 | header.append(gatordmock::CentreAlignFormatting("Name", 20)); |
| 120 | header.append(" | "); |
Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 121 | header.append(gatordmock::CentreAlignFormatting("Event Count", 14)); |
| 122 | header.append("\n"); |
| 123 | |
| 124 | body.append(gatordmock::CentreAlignFormatting(m_CategoryName, 20)); |
| 125 | body.append(" | "); |
Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 126 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_EventCount), 14)); |
| 127 | |
| 128 | std::cout << "\n" << "\n"; |
| 129 | std::cout << gatordmock::CentreAlignFormatting("CATEGORY", static_cast<int>(header.size())); |
| 130 | std::cout << "\n"; |
| 131 | std::cout << std::string(header.size(), '=') << "\n"; |
| 132 | |
| 133 | std::cout<< header; |
| 134 | |
| 135 | std::cout << std::string(body.size(), '-') << "\n"; |
| 136 | |
| 137 | std::cout<< body; |
| 138 | |
| 139 | if(m_EventRecords.size() > 0) |
| 140 | { |
| 141 | EventRecord::printHeader(m_CategoryName); |
| 142 | |
| 143 | std::for_each(m_EventRecords.begin(), m_EventRecords.end(), std::mem_fun_ref(&EventRecord::printContents)); |
| 144 | } |
| 145 | } |
| 146 | }; |
| 147 | |
| 148 | struct CounterSetRecord |
| 149 | { |
| 150 | uint16_t m_CounterSetUid; |
| 151 | uint16_t m_CounterSetCount; |
| 152 | std::string m_CounterSetName; |
| 153 | |
| 154 | static void printHeader() |
| 155 | { |
| 156 | std::string header; |
| 157 | |
| 158 | header.append(gatordmock::CentreAlignFormatting("Counter set name", 20)); |
| 159 | header.append(" | "); |
| 160 | header.append(gatordmock::CentreAlignFormatting("UID",13)); |
| 161 | header.append(" | "); |
| 162 | header.append(gatordmock::CentreAlignFormatting("Count",10)); |
| 163 | header.append("\n"); |
| 164 | |
| 165 | std::cout << "\n" << "\n"; |
| 166 | std::cout << gatordmock::CentreAlignFormatting("COUNTER SETS", static_cast<int>(header.size())); |
| 167 | std::cout << "\n"; |
| 168 | std::cout << std::string(header.size(), '=') << "\n"; |
| 169 | |
| 170 | std::cout<< header; |
| 171 | } |
| 172 | |
| 173 | void printContents() const |
| 174 | { |
| 175 | std::string body; |
| 176 | |
| 177 | body.append(gatordmock::CentreAlignFormatting(m_CounterSetName, 20)); |
| 178 | body.append(" | "); |
| 179 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterSetUid), 13)); |
| 180 | body.append(" | "); |
| 181 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_CounterSetCount), 10)); |
| 182 | body.append("\n"); |
| 183 | |
| 184 | std::cout << std::string(body.size(), '-') << "\n"; |
| 185 | |
| 186 | std::cout<< body; |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | struct DeviceRecord |
| 191 | { |
| 192 | uint16_t m_DeviceUid; |
| 193 | uint16_t m_DeviceCores; |
| 194 | std::string m_DeviceName; |
| 195 | |
| 196 | static void printHeader() |
| 197 | { |
| 198 | std::string header; |
| 199 | |
| 200 | header.append(gatordmock::CentreAlignFormatting("Device name", 20)); |
| 201 | header.append(" | "); |
| 202 | header.append(gatordmock::CentreAlignFormatting("UID",13)); |
| 203 | header.append(" | "); |
| 204 | header.append(gatordmock::CentreAlignFormatting("Cores",10)); |
| 205 | header.append("\n"); |
| 206 | |
| 207 | std::cout << "\n" << "\n"; |
| 208 | std::cout << gatordmock::CentreAlignFormatting("DEVICES", static_cast<int>(header.size())); |
| 209 | std::cout << "\n"; |
| 210 | std::cout << std::string(header.size(), '=') << "\n"; |
| 211 | std::cout<< header; |
| 212 | } |
| 213 | |
| 214 | void printContents() const |
| 215 | { |
| 216 | std::string body; |
| 217 | |
| 218 | body.append(gatordmock::CentreAlignFormatting(m_DeviceName, 20)); |
| 219 | body.append(" | "); |
| 220 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_DeviceUid), 13)); |
| 221 | body.append(" | "); |
| 222 | body.append(gatordmock::CentreAlignFormatting(std::to_string(m_DeviceCores), 10)); |
| 223 | body.append("\n"); |
| 224 | |
| 225 | std::cout << std::string(body.size(), '-') << "\n"; |
| 226 | std::cout<< body; |
| 227 | } |
| 228 | }; |
| 229 | |
| 230 | struct CounterDirectory |
| 231 | { |
| 232 | std::vector<CategoryRecord> m_Categories; |
| 233 | std::vector<CounterSetRecord> m_CounterSets; |
| 234 | std::vector<DeviceRecord> m_DeviceRecords; |
| 235 | |
| 236 | void print() const |
| 237 | { |
| 238 | DeviceRecord::printHeader(); |
| 239 | std::for_each(m_DeviceRecords.begin(), m_DeviceRecords.end(), |
| 240 | std::mem_fun_ref(&DeviceRecord::printContents)); |
| 241 | |
| 242 | CounterSetRecord::printHeader(); |
| 243 | std::for_each(m_CounterSets.begin(), m_CounterSets.end(), |
| 244 | std::mem_fun_ref(&CounterSetRecord::printContents)); |
| 245 | |
| 246 | std::for_each(m_Categories.begin(), m_Categories.end(), |
| 247 | std::mem_fun_ref(&CategoryRecord::print)); |
| 248 | std::cout << "\n"; |
| 249 | } |
| 250 | }; |
| 251 | |
| 252 | } // namespace gatordmock |
| 253 | |
| 254 | } // namespace armnn |