blob: 19d79e25e75fb0975866eab3e747088b29c81335 [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
24#include <atomic>
25#include <condition_variable>
26#include <mutex>
27#include <thread>
28
29namespace armnn
30{
31
32namespace profiling
33{
34
35class MockProfilingConnection : public IProfilingConnection
36{
37public:
38 MockProfilingConnection()
39 : m_IsOpen(true)
40 , m_WrittenData()
41 , m_Packet()
42 {}
43
44 enum class PacketType
45 {
46 StreamMetaData,
47 ConnectionAcknowledge,
48 CounterDirectory,
49 ReqCounterDirectory,
50 PeriodicCounterSelection,
51 PerJobCounterSelection,
52 TimelineMessageDirectory,
53 PeriodicCounterCapture,
Keith Davis33ed2212020-03-30 10:43:41 +010054 ActivateTimelineReporting,
55 DeactivateTimelineReporting,
Jim Flynn64063552020-02-14 10:18:08 +000056 Unknown
57 };
58
59 bool IsOpen() const override
60 {
61 std::lock_guard<std::mutex> lock(m_Mutex);
62
63 return m_IsOpen;
64 }
65
66 void Close() override
67 {
68 std::lock_guard<std::mutex> lock(m_Mutex);
69
70 m_IsOpen = false;
71 }
72
73 bool WritePacket(const unsigned char* buffer, uint32_t length) override
74 {
75 if (buffer == nullptr || length == 0)
76 {
77 return false;
78 }
79
80 uint32_t header = ReadUint32(buffer, 0);
81
82 uint32_t packetFamily = (header >> 26);
83 uint32_t packetId = ((header >> 16) & 1023);
84
85 PacketType packetType;
86
87 switch (packetFamily)
88 {
89 case 0:
Keith Davis33ed2212020-03-30 10:43:41 +010090 packetType = packetId < 8 ? PacketType(packetId) : PacketType::Unknown;
Jim Flynn64063552020-02-14 10:18:08 +000091 break;
92 case 1:
93 packetType = packetId == 0 ? PacketType::TimelineMessageDirectory : PacketType::Unknown;
94 break;
95 case 3:
96 packetType = packetId == 0 ? PacketType::PeriodicCounterCapture : PacketType::Unknown;
97 break;
98 default:
99 packetType = PacketType::Unknown;
100 }
101
102 std::lock_guard<std::mutex> lock(m_Mutex);
103
104 m_WrittenData.push_back({ packetType, length });
105 return true;
106 }
107
108 long CheckForPacket(const std::pair<PacketType, uint32_t> packetInfo)
109 {
110 std::lock_guard<std::mutex> lock(m_Mutex);
111
112 if(packetInfo.second != 0)
113 {
Rob Hughesbb46dde2020-05-20 15:27:37 +0100114 return static_cast<long>(std::count(m_WrittenData.begin(), m_WrittenData.end(), packetInfo));
Jim Flynn64063552020-02-14 10:18:08 +0000115 }
116 else
117 {
Rob Hughesbb46dde2020-05-20 15:27:37 +0100118 return static_cast<long>(std::count_if(m_WrittenData.begin(), m_WrittenData.end(),
119 [&packetInfo](const std::pair<PacketType, uint32_t> pair) { return packetInfo.first == pair.first; }));
Jim Flynn64063552020-02-14 10:18:08 +0000120 }
121 }
122
Jim Flynnbbfe6032020-07-20 16:57:44 +0100123 bool WritePacket(arm::pipe::Packet&& packet)
Jim Flynn64063552020-02-14 10:18:08 +0000124 {
125 std::lock_guard<std::mutex> lock(m_Mutex);
126
127 m_Packet = std::move(packet);
128 return true;
129 }
130
Jim Flynnbbfe6032020-07-20 16:57:44 +0100131 arm::pipe::Packet ReadPacket(uint32_t timeout) override
Jim Flynn64063552020-02-14 10:18:08 +0000132 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000133 IgnoreUnused(timeout);
Jim Flynn64063552020-02-14 10:18:08 +0000134
135 // Simulate a delay in the reading process. The default timeout is way too long.
136 std::this_thread::sleep_for(std::chrono::milliseconds(5));
137 std::lock_guard<std::mutex> lock(m_Mutex);
138 return std::move(m_Packet);
139 }
140
141 unsigned long GetWrittenDataSize()
142 {
143 std::lock_guard<std::mutex> lock(m_Mutex);
144
Rob Hughesbb46dde2020-05-20 15:27:37 +0100145 return static_cast<unsigned long>(m_WrittenData.size());
Jim Flynn64063552020-02-14 10:18:08 +0000146 }
147
148 void Clear()
149 {
150 std::lock_guard<std::mutex> lock(m_Mutex);
151
152 m_WrittenData.clear();
153 }
154
155private:
156 bool m_IsOpen;
157 std::vector<std::pair<PacketType, uint32_t>> m_WrittenData;
Jim Flynnbbfe6032020-07-20 16:57:44 +0100158 arm::pipe::Packet m_Packet;
Jim Flynn64063552020-02-14 10:18:08 +0000159 mutable std::mutex m_Mutex;
160};
161
162class MockProfilingConnectionFactory : public IProfilingConnectionFactory
163{
164public:
165 IProfilingConnectionPtr GetProfilingConnection(const ExternalProfilingOptions& options) const override
166 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000167 IgnoreUnused(options);
Jim Flynn64063552020-02-14 10:18:08 +0000168 return std::make_unique<MockProfilingConnection>();
169 }
170};
171
172class MockPacketBuffer : public IPacketBuffer
173{
174public:
175 MockPacketBuffer(unsigned int maxSize)
176 : m_MaxSize(maxSize)
177 , m_Size(0)
178 , m_Data(std::make_unique<unsigned char[]>(m_MaxSize))
179 {}
180
181 ~MockPacketBuffer() {}
182
183 const unsigned char* GetReadableData() const override { return m_Data.get(); }
184
185 unsigned int GetSize() const override { return m_Size; }
186
187 void MarkRead() override { m_Size = 0; }
188
189 void Commit(unsigned int size) override { m_Size = size; }
190
191 void Release() override { m_Size = 0; }
192
193 unsigned char* GetWritableData() override { return m_Data.get(); }
194
Jim Flynn0204f092020-06-22 20:41:43 +0100195 void Destroy() override {m_Data.reset(nullptr); m_Size = 0; m_MaxSize =0;}
196
Jim Flynn64063552020-02-14 10:18:08 +0000197private:
198 unsigned int m_MaxSize;
199 unsigned int m_Size;
200 std::unique_ptr<unsigned char[]> m_Data;
201};
202
203class MockBufferManager : public IBufferManager
204{
205public:
206 MockBufferManager(unsigned int size)
207 : m_BufferSize(size),
208 m_Buffer(std::make_unique<MockPacketBuffer>(size)) {}
209
210 ~MockBufferManager() {}
211
212 IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
213 {
214 if (requestedSize > m_BufferSize)
215 {
216 reservedSize = m_BufferSize;
217 }
218 else
219 {
220 reservedSize = requestedSize;
221 }
222
223 return std::move(m_Buffer);
224 }
225
226 void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override
227 {
228 packetBuffer->Commit(size);
229 m_Buffer = std::move(packetBuffer);
230
231 if (notifyConsumer)
232 {
233 FlushReadList();
234 }
235 }
236
237 IPacketBufferPtr GetReadableBuffer() override
238 {
239 return std::move(m_Buffer);
240 }
241
242 void Release(IPacketBufferPtr& packetBuffer) override
243 {
244 packetBuffer->Release();
245 m_Buffer = std::move(packetBuffer);
246 }
247
248 void MarkRead(IPacketBufferPtr& packetBuffer) override
249 {
250 packetBuffer->MarkRead();
251 m_Buffer = std::move(packetBuffer);
252 }
253
254 void SetConsumer(IConsumer* consumer) override
255 {
256 if (consumer != nullptr)
257 {
258 m_Consumer = consumer;
259 }
260 }
261
262 void FlushReadList() override
263 {
264 // notify consumer that packet is ready to read
265 if (m_Consumer != nullptr)
266 {
267 m_Consumer->SetReadyToRead();
268 }
269 }
270
271private:
272 unsigned int m_BufferSize;
273 IPacketBufferPtr m_Buffer;
274 IConsumer* m_Consumer = nullptr;
275};
276
277class MockStreamCounterBuffer : public IBufferManager
278{
279public:
280 MockStreamCounterBuffer(unsigned int maxBufferSize = 4096)
281 : m_MaxBufferSize(maxBufferSize)
282 , m_BufferList()
283 , m_CommittedSize(0)
284 , m_ReadableSize(0)
285 , m_ReadSize(0)
286 {}
287 ~MockStreamCounterBuffer() {}
288
289 IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
290 {
291 std::lock_guard<std::mutex> lock(m_Mutex);
292
293 reservedSize = 0;
294 if (requestedSize > m_MaxBufferSize)
295 {
296 throw armnn::InvalidArgumentException("The maximum buffer size that can be requested is [" +
297 std::to_string(m_MaxBufferSize) + "] bytes");
298 }
299 reservedSize = requestedSize;
300 return std::make_unique<MockPacketBuffer>(requestedSize);
301 }
302
303 void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override
304 {
305 std::lock_guard<std::mutex> lock(m_Mutex);
306
307 packetBuffer->Commit(size);
308 m_BufferList.push_back(std::move(packetBuffer));
309 m_CommittedSize += size;
310
311 if (notifyConsumer)
312 {
313 FlushReadList();
314 }
315 }
316
317 void Release(IPacketBufferPtr& packetBuffer) override
318 {
319 std::lock_guard<std::mutex> lock(m_Mutex);
320
321 packetBuffer->Release();
322 }
323
324 IPacketBufferPtr GetReadableBuffer() override
325 {
326 std::lock_guard<std::mutex> lock(m_Mutex);
327
328 if (m_BufferList.empty())
329 {
330 return nullptr;
331 }
332 IPacketBufferPtr buffer = std::move(m_BufferList.back());
333 m_BufferList.pop_back();
334 m_ReadableSize += buffer->GetSize();
335 return buffer;
336 }
337
338 void MarkRead(IPacketBufferPtr& packetBuffer) override
339 {
340 std::lock_guard<std::mutex> lock(m_Mutex);
341
342 m_ReadSize += packetBuffer->GetSize();
343 packetBuffer->MarkRead();
344 }
345
346 void SetConsumer(IConsumer* consumer) override
347 {
348 if (consumer != nullptr)
349 {
350 m_Consumer = consumer;
351 }
352 }
353
354 void FlushReadList() override
355 {
356 // notify consumer that packet is ready to read
357 if (m_Consumer != nullptr)
358 {
359 m_Consumer->SetReadyToRead();
360 }
361 }
362
363 unsigned int GetCommittedSize() const { return m_CommittedSize; }
364 unsigned int GetReadableSize() const { return m_ReadableSize; }
365 unsigned int GetReadSize() const { return m_ReadSize; }
366
367private:
368 // The maximum buffer size when creating a new buffer
369 unsigned int m_MaxBufferSize;
370
371 // A list of buffers
372 std::vector<IPacketBufferPtr> m_BufferList;
373
374 // The mutex to synchronize this mock's methods
375 std::mutex m_Mutex;
376
377 // The total size of the buffers that has been committed for reading
378 unsigned int m_CommittedSize;
379
380 // The total size of the buffers that can be read
381 unsigned int m_ReadableSize;
382
383 // The total size of the buffers that has already been read
384 unsigned int m_ReadSize;
385
386 // Consumer thread to notify packet is ready to read
387 IConsumer* m_Consumer = nullptr;
388};
389
390class MockSendCounterPacket : public ISendCounterPacket
391{
392public:
393 MockSendCounterPacket(IBufferManager& sendBuffer) : m_BufferManager(sendBuffer) {}
394
395 void SendStreamMetaDataPacket() override
396 {
397 std::string message("SendStreamMetaDataPacket");
398 unsigned int reserved = 0;
399 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
400 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
401 m_BufferManager.Commit(buffer, reserved, false);
402 }
403
404 void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory) override
405 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000406 IgnoreUnused(counterDirectory);
Jim Flynn64063552020-02-14 10:18:08 +0000407
408 std::string message("SendCounterDirectoryPacket");
409 unsigned int reserved = 0;
410 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
411 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
412 m_BufferManager.Commit(buffer, reserved);
413 }
414
415 void SendPeriodicCounterCapturePacket(uint64_t timestamp,
416 const std::vector<CounterValue>& values) override
417 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000418 IgnoreUnused(timestamp, values);
Jim Flynn64063552020-02-14 10:18:08 +0000419
420 std::string message("SendPeriodicCounterCapturePacket");
421 unsigned int reserved = 0;
422 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
423 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
424 m_BufferManager.Commit(buffer, reserved);
425 }
426
427 void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
428 const std::vector<uint16_t>& selectedCounterIds) override
429 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000430 IgnoreUnused(capturePeriod, selectedCounterIds);
Jim Flynn64063552020-02-14 10:18:08 +0000431
432 std::string message("SendPeriodicCounterSelectionPacket");
433 unsigned int reserved = 0;
434 IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
435 memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
436 m_BufferManager.Commit(buffer, reserved);
437 }
438
439private:
440 IBufferManager& m_BufferManager;
441};
442
443class MockCounterDirectory : public ICounterDirectory
444{
445public:
446 MockCounterDirectory() = default;
447 ~MockCounterDirectory() = default;
448
449 // Register profiling objects
Sadik Armagan4c998992020-02-25 12:44:44 +0000450 const Category* RegisterCategory(const std::string& categoryName)
Jim Flynn64063552020-02-14 10:18:08 +0000451 {
Jim Flynn64063552020-02-14 10:18:08 +0000452 // Create the category
Sadik Armagan4c998992020-02-25 12:44:44 +0000453 CategoryPtr category = std::make_unique<Category>(categoryName);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100454 ARMNN_ASSERT(category);
Jim Flynn64063552020-02-14 10:18:08 +0000455
456 // Get the raw category pointer
457 const Category* categoryPtr = category.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100458 ARMNN_ASSERT(categoryPtr);
Jim Flynn64063552020-02-14 10:18:08 +0000459
460 // Register the category
461 m_Categories.insert(std::move(category));
462
463 return categoryPtr;
464 }
465
466 const Device* RegisterDevice(const std::string& deviceName,
Sadik Armagan4c998992020-02-25 12:44:44 +0000467 uint16_t cores = 0)
Jim Flynn64063552020-02-14 10:18:08 +0000468 {
469 // Get the device UID
470 uint16_t deviceUid = GetNextUid();
471
472 // Create the device
473 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100474 ARMNN_ASSERT(device);
Jim Flynn64063552020-02-14 10:18:08 +0000475
476 // Get the raw device pointer
477 const Device* devicePtr = device.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100478 ARMNN_ASSERT(devicePtr);
Jim Flynn64063552020-02-14 10:18:08 +0000479
480 // Register the device
481 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
482
Jim Flynn64063552020-02-14 10:18:08 +0000483 return devicePtr;
484 }
485
486 const CounterSet* RegisterCounterSet(
487 const std::string& counterSetName,
Sadik Armagan4c998992020-02-25 12:44:44 +0000488 uint16_t count = 0)
Jim Flynn64063552020-02-14 10:18:08 +0000489 {
490 // Get the counter set UID
491 uint16_t counterSetUid = GetNextUid();
492
493 // Create the counter set
494 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100495 ARMNN_ASSERT(counterSet);
Jim Flynn64063552020-02-14 10:18:08 +0000496
497 // Get the raw counter set pointer
498 const CounterSet* counterSetPtr = counterSet.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100499 ARMNN_ASSERT(counterSetPtr);
Jim Flynn64063552020-02-14 10:18:08 +0000500
501 // Register the counter set
502 m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
503
Jim Flynn64063552020-02-14 10:18:08 +0000504 return counterSetPtr;
505 }
506
507 const Counter* RegisterCounter(const BackendId& backendId,
508 const uint16_t uid,
509 const std::string& parentCategoryName,
510 uint16_t counterClass,
511 uint16_t interpolation,
512 double multiplier,
513 const std::string& name,
514 const std::string& description,
515 const armnn::Optional<std::string>& units = armnn::EmptyOptional(),
516 const armnn::Optional<uint16_t>& numberOfCores = armnn::EmptyOptional(),
517 const armnn::Optional<uint16_t>& deviceUid = armnn::EmptyOptional(),
518 const armnn::Optional<uint16_t>& counterSetUid = armnn::EmptyOptional())
519 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000520 IgnoreUnused(backendId);
Jim Flynn64063552020-02-14 10:18:08 +0000521
522 // Get the number of cores from the argument only
523 uint16_t deviceCores = numberOfCores.has_value() ? numberOfCores.value() : 0;
524
525 // Get the device UID
526 uint16_t deviceUidValue = deviceUid.has_value() ? deviceUid.value() : 0;
527
528 // Get the counter set UID
529 uint16_t counterSetUidValue = counterSetUid.has_value() ? counterSetUid.value() : 0;
530
531 // Get the counter UIDs and calculate the max counter UID
532 std::vector<uint16_t> counterUids = GetNextCounterUids(uid, deviceCores);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100533 ARMNN_ASSERT(!counterUids.empty());
Jim Flynn64063552020-02-14 10:18:08 +0000534 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
535
536 // Get the counter units
537 const std::string unitsValue = units.has_value() ? units.value() : "";
538
539 // Create the counter
540 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
541 counterUids.front(),
542 maxCounterUid,
543 counterClass,
544 interpolation,
545 multiplier,
546 name,
547 description,
548 unitsValue,
549 deviceUidValue,
550 counterSetUidValue);
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100551 ARMNN_ASSERT(counter);
Jim Flynn64063552020-02-14 10:18:08 +0000552
553 // Get the raw counter pointer
554 const Counter* counterPtr = counter.get();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100555 ARMNN_ASSERT(counterPtr);
Jim Flynn64063552020-02-14 10:18:08 +0000556
557 // Process multiple counters if necessary
558 for (uint16_t counterUid : counterUids)
559 {
560 // Connect the counter to the parent category
561 Category* parentCategory = const_cast<Category*>(GetCategory(parentCategoryName));
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100562 ARMNN_ASSERT(parentCategory);
Jim Flynn64063552020-02-14 10:18:08 +0000563 parentCategory->m_Counters.push_back(counterUid);
564
565 // Register the counter
566 m_Counters.insert(std::make_pair(counterUid, counter));
567 }
568
569 return counterPtr;
570 }
571
572 // Getters for counts
Matthew Sloyan371b70e2020-09-11 10:14:57 +0100573 uint16_t GetCategoryCount() const override { return armnn::numeric_cast<uint16_t>(m_Categories.size()); }
574 uint16_t GetDeviceCount() const override { return armnn::numeric_cast<uint16_t>(m_Devices.size()); }
575 uint16_t GetCounterSetCount() const override { return armnn::numeric_cast<uint16_t>(m_CounterSets.size()); }
576 uint16_t GetCounterCount() const override { return armnn::numeric_cast<uint16_t>(m_Counters.size()); }
Jim Flynn64063552020-02-14 10:18:08 +0000577
578 // Getters for collections
579 const Categories& GetCategories() const override { return m_Categories; }
580 const Devices& GetDevices() const override { return m_Devices; }
581 const CounterSets& GetCounterSets() const override { return m_CounterSets; }
582 const Counters& GetCounters() const override { return m_Counters; }
583
584 // Getters for profiling objects
585 const Category* GetCategory(const std::string& name) const override
586 {
587 auto it = std::find_if(m_Categories.begin(), m_Categories.end(), [&name](const CategoryPtr& category)
588 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100589 ARMNN_ASSERT(category);
Jim Flynn64063552020-02-14 10:18:08 +0000590
591 return category->m_Name == name;
592 });
593
594 if (it == m_Categories.end())
595 {
596 return nullptr;
597 }
598
599 return it->get();
600 }
601
602 const Device* GetDevice(uint16_t uid) const override
603 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000604 IgnoreUnused(uid);
Jim Flynn64063552020-02-14 10:18:08 +0000605 return nullptr; // Not used by the unit tests
606 }
607
608 const CounterSet* GetCounterSet(uint16_t uid) const override
609 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000610 IgnoreUnused(uid);
Jim Flynn64063552020-02-14 10:18:08 +0000611 return nullptr; // Not used by the unit tests
612 }
613
614 const Counter* GetCounter(uint16_t uid) const override
615 {
Jan Eilers8eb25602020-03-09 12:13:48 +0000616 IgnoreUnused(uid);
Jim Flynn64063552020-02-14 10:18:08 +0000617 return nullptr; // Not used by the unit tests
618 }
619
620private:
621 Categories m_Categories;
622 Devices m_Devices;
623 CounterSets m_CounterSets;
624 Counters m_Counters;
625};
626
Sadik Armagan3184c902020-03-18 10:57:30 +0000627class MockProfilingService : public ProfilingService
Sadik Armagancab588a2020-02-17 11:33:31 +0000628{
629public:
630 MockProfilingService(MockBufferManager& mockBufferManager,
631 bool isProfilingEnabled,
632 const CaptureData& captureData) :
633 m_SendCounterPacket(mockBufferManager),
634 m_IsProfilingEnabled(isProfilingEnabled),
Keith Davis33ed2212020-03-30 10:43:41 +0100635 m_CaptureData(captureData)
636 {}
Sadik Armagancab588a2020-02-17 11:33:31 +0000637
638 /// Return the next random Guid in the sequence
639 ProfilingDynamicGuid NextGuid() override
640 {
641 return m_GuidGenerator.NextGuid();
642 }
643
644 /// Create a ProfilingStaticGuid based on a hash of the string
645 ProfilingStaticGuid GenerateStaticId(const std::string& str) override
646 {
647 return m_GuidGenerator.GenerateStaticId(str);
648 }
649
650 std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() const override
651 {
652 return nullptr;
653 }
654
655 const ICounterMappings& GetCounterMappings() const override
656 {
657 return m_CounterMapping;
658 }
659
660 ISendCounterPacket& GetSendCounterPacket() override
661 {
662 return m_SendCounterPacket;
663 }
664
665 bool IsProfilingEnabled() const override
666 {
667 return m_IsProfilingEnabled;
668 }
669
670 CaptureData GetCaptureData() override
671 {
672 CaptureData copy(m_CaptureData);
673 return copy;
674 }
675
676 void RegisterMapping(uint16_t globalCounterId,
677 uint16_t backendCounterId,
Sadik Armagan3184c902020-03-18 10:57:30 +0000678 const armnn::BackendId& backendId)
Sadik Armagancab588a2020-02-17 11:33:31 +0000679 {
680 m_CounterMapping.RegisterMapping(globalCounterId, backendCounterId, backendId);
681 }
682
Sadik Armagan3184c902020-03-18 10:57:30 +0000683 void Reset()
Sadik Armagancab588a2020-02-17 11:33:31 +0000684 {
685 m_CounterMapping.Reset();
686 }
687
688private:
689 ProfilingGuidGenerator m_GuidGenerator;
Keith Davis33ed2212020-03-30 10:43:41 +0100690 CounterIdMap m_CounterMapping;
691 SendCounterPacket m_SendCounterPacket;
692 bool m_IsProfilingEnabled;
693 CaptureData m_CaptureData;
Sadik Armagancab588a2020-02-17 11:33:31 +0000694};
695
Jim Flynn6398a982020-05-27 17:05:21 +0100696class MockProfilingServiceStatus : public IProfilingServiceStatus
697{
698public:
699 void NotifyProfilingServiceActive() override {}
700 void WaitForProfilingServiceActivation(unsigned int timeout) override { IgnoreUnused(timeout); }
701};
702
Jim Flynn64063552020-02-14 10:18:08 +0000703} // namespace profiling
704
705} // namespace armnn