blob: a34c84930227f5ef253d7aa10381ef147f1883f3 [file] [log] [blame]
Jim Flynn64063552020-02-14 10:18:08 +00001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Jim Flynn64063552020-02-14 10:18:08 +00003// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Sadik Armagancab588a2020-02-17 11:33:31 +00008#include <Holder.hpp>
Jim Flynn64063552020-02-14 10:18:08 +00009#include <IProfilingConnectionFactory.hpp>
Jim Flynn6398a982020-05-27 17:05:21 +010010#include <IProfilingServiceStatus.hpp>
Sadik Armagan3184c902020-03-18 10:57:30 +000011#include <ProfilingService.hpp>
Jim Flynn64063552020-02-14 10:18:08 +000012#include <ProfilingGuidGenerator.hpp>
13#include <ProfilingUtils.hpp>
14#include <SendCounterPacket.hpp>
15#include <SendThread.hpp>
16
17#include <armnn/Exceptions.hpp>
18#include <armnn/Optional.hpp>
19#include <armnn/Conversion.hpp>
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010020#include <armnn/utility/Assert.hpp>
Jan Eilers8eb25602020-03-09 12:13:48 +000021#include <armnn/utility/IgnoreUnused.hpp>
Matthew Sloyan371b70e2020-09-11 10:14:57 +010022#include <armnn/utility/NumericCast.hpp>
Jim Flynn64063552020-02-14 10:18:08 +000023
Nikhil Raj7dcc6972021-04-30 15:44:24 +010024#include <common/include/ProfilingGuid.hpp>
25
Jim Flynn64063552020-02-14 10:18:08 +000026#include <atomic>
27#include <condition_variable>
28#include <mutex>
29#include <thread>
30
31namespace armnn
32{
33
34namespace profiling
35{
36
37class MockProfilingConnection : public IProfilingConnection
38{
39public:
40 MockProfilingConnection()
41 : m_IsOpen(true)
42 , m_WrittenData()
43 , m_Packet()
44 {}
45
46 enum class PacketType
47 {
48 StreamMetaData,
49 ConnectionAcknowledge,
50 CounterDirectory,
51 ReqCounterDirectory,
52 PeriodicCounterSelection,
53 PerJobCounterSelection,
54 TimelineMessageDirectory,
55 PeriodicCounterCapture,
Keith Davis33ed2212020-03-30 10:43:41 +010056 ActivateTimelineReporting,
57 DeactivateTimelineReporting,
Jim Flynn64063552020-02-14 10:18:08 +000058 Unknown
59 };
60
61 bool IsOpen() const override
62 {
63 std::lock_guard<std::mutex> lock(m_Mutex);
64
65 return m_IsOpen;
66 }
67
68 void Close() override
69 {
70 std::lock_guard<std::mutex> lock(m_Mutex);
71
72 m_IsOpen = false;
73 }
74
75 bool WritePacket(const unsigned char* buffer, uint32_t length) override
76 {
77 if (buffer == nullptr || length == 0)
78 {
79 return false;
80 }
81
82 uint32_t header = ReadUint32(buffer, 0);
83
84 uint32_t packetFamily = (header >> 26);
85 uint32_t packetId = ((header >> 16) & 1023);
86
87 PacketType packetType;
88
89 switch (packetFamily)
90 {
91 case 0:
Keith Davis33ed2212020-03-30 10:43:41 +010092 packetType = packetId < 8 ? PacketType(packetId) : PacketType::Unknown;
Jim Flynn64063552020-02-14 10:18:08 +000093 break;
94 case 1:
95 packetType = packetId == 0 ? PacketType::TimelineMessageDirectory : PacketType::Unknown;
96 break;
97 case 3:
98 packetType = packetId == 0 ? PacketType::PeriodicCounterCapture : PacketType::Unknown;
99 break;
100 default:
101 packetType = PacketType::Unknown;
102 }
103
104 std::lock_guard<std::mutex> lock(m_Mutex);
105
106 m_WrittenData.push_back({ packetType, length });
107 return true;
108 }
109
110 long CheckForPacket(const std::pair<PacketType, uint32_t> packetInfo)
111 {
112 std::lock_guard<std::mutex> lock(m_Mutex);
113
114 if(packetInfo.second != 0)
115 {
Rob Hughesbb46dde2020-05-20 15:27:37 +0100116 return static_cast<long>(std::count(m_WrittenData.begin(), m_WrittenData.end(), packetInfo));
Jim Flynn64063552020-02-14 10:18:08 +0000117 }
118 else
119 {
Rob Hughesbb46dde2020-05-20 15:27:37 +0100120 return static_cast<long>(std::count_if(m_WrittenData.begin(), m_WrittenData.end(),
121 [&packetInfo](const std::pair<PacketType, uint32_t> pair) { return packetInfo.first == pair.first; }));
Jim Flynn64063552020-02-14 10:18:08 +0000122 }
123 }
124
Jim Flynnbbfe6032020-07-20 16:57:44 +0100125 bool WritePacket(arm::pipe::Packet&& packet)
Jim Flynn64063552020-02-14 10:18:08 +0000126 {
127 std::lock_guard<std::mutex> lock(m_Mutex);
128
129 m_Packet = std::move(packet);
130 return true;
131 }
132
Jim Flynnbbfe6032020-07-20 16:57:44 +0100133 arm::pipe::Packet ReadPacket(uint32_t timeout) override
Jim Flynn64063552020-02-14 10:18:08 +0000134 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000135 IgnoreUnused(timeout);
Jim Flynn64063552020-02-14 10:18:08 +0000136
137 // Simulate a delay in the reading process. The default timeout is way too long.
138 std::this_thread::sleep_for(std::chrono::milliseconds(5));
139 std::lock_guard<std::mutex> lock(m_Mutex);
140 return std::move(m_Packet);
141 }
142
143 unsigned long GetWrittenDataSize()
144 {
145 std::lock_guard<std::mutex> lock(m_Mutex);
146
Rob Hughesbb46dde2020-05-20 15:27:37 +0100147 return static_cast<unsigned long>(m_WrittenData.size());
Jim Flynn64063552020-02-14 10:18:08 +0000148 }
149
150 void Clear()
151 {
152 std::lock_guard<std::mutex> lock(m_Mutex);
153
154 m_WrittenData.clear();
155 }
156
157private:
158 bool m_IsOpen;
159 std::vector<std::pair<PacketType, uint32_t>> m_WrittenData;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100160 arm::pipe::Packet m_Packet;
Jim Flynn64063552020-02-14 10:18:08 +0000161 mutable std::mutex m_Mutex;
162};
163
164class MockProfilingConnectionFactory : public IProfilingConnectionFactory
165{
166public:
167 IProfilingConnectionPtr GetProfilingConnection(const ExternalProfilingOptions& options) const override
168 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000169 IgnoreUnused(options);
Jim Flynn64063552020-02-14 10:18:08 +0000170 return std::make_unique<MockProfilingConnection>();
171 }
172};
173
174class MockPacketBuffer : public IPacketBuffer
175{
176public:
177 MockPacketBuffer(unsigned int maxSize)
178 : m_MaxSize(maxSize)
179 , m_Size(0)
180 , m_Data(std::make_unique<unsigned char[]>(m_MaxSize))
181 {}
182
183 ~MockPacketBuffer() {}
184
185 const unsigned char* GetReadableData() const override { return m_Data.get(); }
186
187 unsigned int GetSize() const override { return m_Size; }
188
189 void MarkRead() override { m_Size = 0; }
190
191 void Commit(unsigned int size) override { m_Size = size; }
192
193 void Release() override { m_Size = 0; }
194
195 unsigned char* GetWritableData() override { return m_Data.get(); }
196
Jim Flynn0204f092020-06-22 20:41:43 +0100197 void Destroy() override {m_Data.reset(nullptr); m_Size = 0; m_MaxSize =0;}
198
Jim Flynn64063552020-02-14 10:18:08 +0000199private:
200 unsigned int m_MaxSize;
201 unsigned int m_Size;
202 std::unique_ptr<unsigned char[]> m_Data;
203};
204
205class MockBufferManager : public IBufferManager
206{
207public:
208 MockBufferManager(unsigned int size)
209 : m_BufferSize(size),
210 m_Buffer(std::make_unique<MockPacketBuffer>(size)) {}
211
212 ~MockBufferManager() {}
213
214 IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
215 {
216 if (requestedSize > m_BufferSize)
217 {
218 reservedSize = m_BufferSize;
219 }
220 else
221 {
222 reservedSize = requestedSize;
223 }
224
225 return std::move(m_Buffer);
226 }
227
228 void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override
229 {
230 packetBuffer->Commit(size);
231 m_Buffer = std::move(packetBuffer);
232
233 if (notifyConsumer)
234 {
235 FlushReadList();
236 }
237 }
238
239 IPacketBufferPtr GetReadableBuffer() override
240 {
241 return std::move(m_Buffer);
242 }
243
244 void Release(IPacketBufferPtr& packetBuffer) override
245 {
246 packetBuffer->Release();
247 m_Buffer = std::move(packetBuffer);
248 }
249
250 void MarkRead(IPacketBufferPtr& packetBuffer) override
251 {
252 packetBuffer->MarkRead();
253 m_Buffer = std::move(packetBuffer);
254 }
255
256 void SetConsumer(IConsumer* consumer) override
257 {
258 if (consumer != nullptr)
259 {
260 m_Consumer = consumer;
261 }
262 }
263
264 void FlushReadList() override
265 {
266 // notify consumer that packet is ready to read
267 if (m_Consumer != nullptr)
268 {
269 m_Consumer->SetReadyToRead();
270 }
271 }
272
273private:
274 unsigned int m_BufferSize;
275 IPacketBufferPtr m_Buffer;
276 IConsumer* m_Consumer = nullptr;
277};
278
279class MockStreamCounterBuffer : public IBufferManager
280{
281public:
282 MockStreamCounterBuffer(unsigned int maxBufferSize = 4096)
283 : m_MaxBufferSize(maxBufferSize)
284 , m_BufferList()
285 , m_CommittedSize(0)
286 , m_ReadableSize(0)
287 , m_ReadSize(0)
288 {}
289 ~MockStreamCounterBuffer() {}
290
291 IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
292 {
293 std::lock_guard<std::mutex> lock(m_Mutex);
294
295 reservedSize = 0;
296 if (requestedSize > m_MaxBufferSize)
297 {
298 throw armnn::InvalidArgumentException("The maximum buffer size that can be requested is [" +
299 std::to_string(m_MaxBufferSize) + "] bytes");
300 }
301 reservedSize = requestedSize;
302 return std::make_unique<MockPacketBuffer>(requestedSize);
303 }
304
305 void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override
306 {
307 std::lock_guard<std::mutex> lock(m_Mutex);
308
309 packetBuffer->Commit(size);
310 m_BufferList.push_back(std::move(packetBuffer));
311 m_CommittedSize += size;
312
313 if (notifyConsumer)
314 {
315 FlushReadList();
316 }
317 }
318
319 void Release(IPacketBufferPtr& packetBuffer) override
320 {
321 std::lock_guard<std::mutex> lock(m_Mutex);
322
323 packetBuffer->Release();
324 }
325
326 IPacketBufferPtr GetReadableBuffer() override
327 {
328 std::lock_guard<std::mutex> lock(m_Mutex);
329
330 if (m_BufferList.empty())
331 {
332 return nullptr;
333 }
334 IPacketBufferPtr buffer = std::move(m_BufferList.back());
335 m_BufferList.pop_back();
336 m_ReadableSize += buffer->GetSize();
337 return buffer;
338 }
339
340 void MarkRead(IPacketBufferPtr& packetBuffer) override
341 {
342 std::lock_guard<std::mutex> lock(m_Mutex);
343
344 m_ReadSize += packetBuffer->GetSize();
345 packetBuffer->MarkRead();
346 }
347
348 void SetConsumer(IConsumer* consumer) override
349 {
350 if (consumer != nullptr)
351 {
352 m_Consumer = consumer;
353 }
354 }
355
356 void FlushReadList() override
357 {
358 // notify consumer that packet is ready to read
359 if (m_Consumer != nullptr)
360 {
361 m_Consumer->SetReadyToRead();
362 }
363 }
364
365 unsigned int GetCommittedSize() const { return m_CommittedSize; }
366 unsigned int GetReadableSize() const { return m_ReadableSize; }
367 unsigned int GetReadSize() const { return m_ReadSize; }
368
369private:
370 // The maximum buffer size when creating a new buffer
371 unsigned int m_MaxBufferSize;
372
373 // A list of buffers
374 std::vector<IPacketBufferPtr> m_BufferList;
375
376 // The mutex to synchronize this mock's methods
377 std::mutex m_Mutex;
378
379 // The total size of the buffers that has been committed for reading
380 unsigned int m_CommittedSize;
381
382 // The total size of the buffers that can be read
383 unsigned int m_ReadableSize;
384
385 // The total size of the buffers that has already been read
386 unsigned int m_ReadSize;
387
388 // Consumer thread to notify packet is ready to read
389 IConsumer* m_Consumer = nullptr;
390};
391
392class MockSendCounterPacket : public ISendCounterPacket
393{
394public:
395 MockSendCounterPacket(IBufferManager& sendBuffer) : m_BufferManager(sendBuffer) {}
396
397 void SendStreamMetaDataPacket() override
398 {
399 std::string message("SendStreamMetaDataPacket");
400 unsigned int reserved = 0;
401 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
402 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
403 m_BufferManager.Commit(buffer, reserved, false);
404 }
405
406 void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory) override
407 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000408 IgnoreUnused(counterDirectory);
Jim Flynn64063552020-02-14 10:18:08 +0000409
410 std::string message("SendCounterDirectoryPacket");
411 unsigned int reserved = 0;
412 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
413 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
414 m_BufferManager.Commit(buffer, reserved);
415 }
416
417 void SendPeriodicCounterCapturePacket(uint64_t timestamp,
418 const std::vector<CounterValue>& values) override
419 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000420 IgnoreUnused(timestamp, values);
Jim Flynn64063552020-02-14 10:18:08 +0000421
422 std::string message("SendPeriodicCounterCapturePacket");
423 unsigned int reserved = 0;
424 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
425 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
426 m_BufferManager.Commit(buffer, reserved);
427 }
428
429 void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
430 const std::vector<uint16_t>& selectedCounterIds) override
431 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000432 IgnoreUnused(capturePeriod, selectedCounterIds);
Jim Flynn64063552020-02-14 10:18:08 +0000433
434 std::string message("SendPeriodicCounterSelectionPacket");
435 unsigned int reserved = 0;
436 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
437 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
438 m_BufferManager.Commit(buffer, reserved);
439 }
440
441private:
442 IBufferManager& m_BufferManager;
443};
444
445class MockCounterDirectory : public ICounterDirectory
446{
447public:
448 MockCounterDirectory() = default;
449 ~MockCounterDirectory() = default;
450
451 // Register profiling objects
Sadik Armagan4c998992020-02-25 12:44:44 +0000452 const Category* RegisterCategory(const std::string& categoryName)
Jim Flynn64063552020-02-14 10:18:08 +0000453 {
Jim Flynn64063552020-02-14 10:18:08 +0000454 // Create the category
Sadik Armagan4c998992020-02-25 12:44:44 +0000455 CategoryPtr category = std::make_unique<Category>(categoryName);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100456 ARMNN_ASSERT(category);
Jim Flynn64063552020-02-14 10:18:08 +0000457
458 // Get the raw category pointer
459 const Category* categoryPtr = category.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100460 ARMNN_ASSERT(categoryPtr);
Jim Flynn64063552020-02-14 10:18:08 +0000461
462 // Register the category
463 m_Categories.insert(std::move(category));
464
465 return categoryPtr;
466 }
467
468 const Device* RegisterDevice(const std::string& deviceName,
Sadik Armagan4c998992020-02-25 12:44:44 +0000469 uint16_t cores = 0)
Jim Flynn64063552020-02-14 10:18:08 +0000470 {
471 // Get the device UID
472 uint16_t deviceUid = GetNextUid();
473
474 // Create the device
475 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100476 ARMNN_ASSERT(device);
Jim Flynn64063552020-02-14 10:18:08 +0000477
478 // Get the raw device pointer
479 const Device* devicePtr = device.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100480 ARMNN_ASSERT(devicePtr);
Jim Flynn64063552020-02-14 10:18:08 +0000481
482 // Register the device
483 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
484
Jim Flynn64063552020-02-14 10:18:08 +0000485 return devicePtr;
486 }
487
488 const CounterSet* RegisterCounterSet(
489 const std::string& counterSetName,
Sadik Armagan4c998992020-02-25 12:44:44 +0000490 uint16_t count = 0)
Jim Flynn64063552020-02-14 10:18:08 +0000491 {
492 // Get the counter set UID
493 uint16_t counterSetUid = GetNextUid();
494
495 // Create the counter set
496 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100497 ARMNN_ASSERT(counterSet);
Jim Flynn64063552020-02-14 10:18:08 +0000498
499 // Get the raw counter set pointer
500 const CounterSet* counterSetPtr = counterSet.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100501 ARMNN_ASSERT(counterSetPtr);
Jim Flynn64063552020-02-14 10:18:08 +0000502
503 // Register the counter set
504 m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
505
Jim Flynn64063552020-02-14 10:18:08 +0000506 return counterSetPtr;
507 }
508
509 const Counter* RegisterCounter(const BackendId& backendId,
510 const uint16_t uid,
511 const std::string& parentCategoryName,
512 uint16_t counterClass,
513 uint16_t interpolation,
514 double multiplier,
515 const std::string& name,
516 const std::string& description,
517 const armnn::Optional<std::string>& units = armnn::EmptyOptional(),
518 const armnn::Optional<uint16_t>& numberOfCores = armnn::EmptyOptional(),
519 const armnn::Optional<uint16_t>& deviceUid = armnn::EmptyOptional(),
520 const armnn::Optional<uint16_t>& counterSetUid = armnn::EmptyOptional())
521 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000522 IgnoreUnused(backendId);
Jim Flynn64063552020-02-14 10:18:08 +0000523
524 // Get the number of cores from the argument only
525 uint16_t deviceCores = numberOfCores.has_value() ? numberOfCores.value() : 0;
526
527 // Get the device UID
528 uint16_t deviceUidValue = deviceUid.has_value() ? deviceUid.value() : 0;
529
530 // Get the counter set UID
531 uint16_t counterSetUidValue = counterSetUid.has_value() ? counterSetUid.value() : 0;
532
533 // Get the counter UIDs and calculate the max counter UID
534 std::vector<uint16_t> counterUids = GetNextCounterUids(uid, deviceCores);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100535 ARMNN_ASSERT(!counterUids.empty());
Jim Flynn64063552020-02-14 10:18:08 +0000536 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
537
538 // Get the counter units
539 const std::string unitsValue = units.has_value() ? units.value() : "";
540
541 // Create the counter
542 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
543 counterUids.front(),
544 maxCounterUid,
545 counterClass,
546 interpolation,
547 multiplier,
548 name,
549 description,
550 unitsValue,
551 deviceUidValue,
552 counterSetUidValue);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100553 ARMNN_ASSERT(counter);
Jim Flynn64063552020-02-14 10:18:08 +0000554
555 // Get the raw counter pointer
556 const Counter* counterPtr = counter.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100557 ARMNN_ASSERT(counterPtr);
Jim Flynn64063552020-02-14 10:18:08 +0000558
559 // Process multiple counters if necessary
560 for (uint16_t counterUid : counterUids)
561 {
562 // Connect the counter to the parent category
563 Category* parentCategory = const_cast<Category*>(GetCategory(parentCategoryName));
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100564 ARMNN_ASSERT(parentCategory);
Jim Flynn64063552020-02-14 10:18:08 +0000565 parentCategory->m_Counters.push_back(counterUid);
566
567 // Register the counter
568 m_Counters.insert(std::make_pair(counterUid, counter));
569 }
570
571 return counterPtr;
572 }
573
574 // Getters for counts
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100575 uint16_t GetCategoryCount() const override { return armnn::numeric_cast<uint16_t>(m_Categories.size()); }
576 uint16_t GetDeviceCount() const override { return armnn::numeric_cast<uint16_t>(m_Devices.size()); }
577 uint16_t GetCounterSetCount() const override { return armnn::numeric_cast<uint16_t>(m_CounterSets.size()); }
578 uint16_t GetCounterCount() const override { return armnn::numeric_cast<uint16_t>(m_Counters.size()); }
Jim Flynn64063552020-02-14 10:18:08 +0000579
580 // Getters for collections
581 const Categories& GetCategories() const override { return m_Categories; }
582 const Devices& GetDevices() const override { return m_Devices; }
583 const CounterSets& GetCounterSets() const override { return m_CounterSets; }
584 const Counters& GetCounters() const override { return m_Counters; }
585
586 // Getters for profiling objects
587 const Category* GetCategory(const std::string& name) const override
588 {
589 auto it = std::find_if(m_Categories.begin(), m_Categories.end(), [&name](const CategoryPtr& category)
590 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100591 ARMNN_ASSERT(category);
Jim Flynn64063552020-02-14 10:18:08 +0000592
593 return category->m_Name == name;
594 });
595
596 if (it == m_Categories.end())
597 {
598 return nullptr;
599 }
600
601 return it->get();
602 }
603
604 const Device* GetDevice(uint16_t uid) const override
605 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000606 IgnoreUnused(uid);
Jim Flynn64063552020-02-14 10:18:08 +0000607 return nullptr; // Not used by the unit tests
608 }
609
610 const CounterSet* GetCounterSet(uint16_t uid) const override
611 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000612 IgnoreUnused(uid);
Jim Flynn64063552020-02-14 10:18:08 +0000613 return nullptr; // Not used by the unit tests
614 }
615
616 const Counter* GetCounter(uint16_t uid) const override
617 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000618 IgnoreUnused(uid);
Jim Flynn64063552020-02-14 10:18:08 +0000619 return nullptr; // Not used by the unit tests
620 }
621
622private:
623 Categories m_Categories;
624 Devices m_Devices;
625 CounterSets m_CounterSets;
626 Counters m_Counters;
627};
628
Sadik Armagan3184c902020-03-18 10:57:30 +0000629class MockProfilingService : public ProfilingService
Sadik Armagancab588a2020-02-17 11:33:31 +0000630{
631public:
632 MockProfilingService(MockBufferManager& mockBufferManager,
633 bool isProfilingEnabled,
634 const CaptureData& captureData) :
635 m_SendCounterPacket(mockBufferManager),
636 m_IsProfilingEnabled(isProfilingEnabled),
Keith Davis33ed2212020-03-30 10:43:41 +0100637 m_CaptureData(captureData)
638 {}
Sadik Armagancab588a2020-02-17 11:33:31 +0000639
640 /// Return the next random Guid in the sequence
641 ProfilingDynamicGuid NextGuid() override
642 {
643 return m_GuidGenerator.NextGuid();
644 }
645
646 /// Create a ProfilingStaticGuid based on a hash of the string
647 ProfilingStaticGuid GenerateStaticId(const std::string& str) override
648 {
649 return m_GuidGenerator.GenerateStaticId(str);
650 }
651
652 std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() const override
653 {
654 return nullptr;
655 }
656
657 const ICounterMappings& GetCounterMappings() const override
658 {
659 return m_CounterMapping;
660 }
661
662 ISendCounterPacket& GetSendCounterPacket() override
663 {
664 return m_SendCounterPacket;
665 }
666
667 bool IsProfilingEnabled() const override
668 {
669 return m_IsProfilingEnabled;
670 }
671
672 CaptureData GetCaptureData() override
673 {
674 CaptureData copy(m_CaptureData);
675 return copy;
676 }
677
678 void RegisterMapping(uint16_t globalCounterId,
679 uint16_t backendCounterId,
Sadik Armagan3184c902020-03-18 10:57:30 +0000680 const armnn::BackendId& backendId)
Sadik Armagancab588a2020-02-17 11:33:31 +0000681 {
682 m_CounterMapping.RegisterMapping(globalCounterId, backendCounterId, backendId);
683 }
684
Sadik Armagan3184c902020-03-18 10:57:30 +0000685 void Reset()
Sadik Armagancab588a2020-02-17 11:33:31 +0000686 {
687 m_CounterMapping.Reset();
688 }
689
690private:
691 ProfilingGuidGenerator m_GuidGenerator;
Keith Davis33ed2212020-03-30 10:43:41 +0100692 CounterIdMap m_CounterMapping;
693 SendCounterPacket m_SendCounterPacket;
694 bool m_IsProfilingEnabled;
695 CaptureData m_CaptureData;
Sadik Armagancab588a2020-02-17 11:33:31 +0000696};
697
Jim Flynn6398a982020-05-27 17:05:21 +0100698class MockProfilingServiceStatus : public IProfilingServiceStatus
699{
700public:
701 void NotifyProfilingServiceActive() override {}
702 void WaitForProfilingServiceActivation(unsigned int timeout) override { IgnoreUnused(timeout); }
703};
704
Jim Flynn64063552020-02-14 10:18:08 +0000705} // namespace profiling
706
707} // namespace armnn