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