• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <client/src/IProfilingConnectionFactory.hpp>
9 #include <client/src/ProfilingService.hpp>
10 #include <client/src/ProfilingUtils.hpp>
11 #include <client/src/SendCounterPacket.hpp>
12 #include <client/src/SendThread.hpp>
13 
14 #include <armnn/BackendId.hpp>
15 #include <armnn/profiling/ArmNNProfiling.hpp>
16 
17 #include <client/include/Holder.hpp>
18 #include <client/include/IProfilingServiceStatus.hpp>
19 
20 #include <common/include/Assert.hpp>
21 #include <common/include/CommonProfilingUtils.hpp>
22 #include <common/include/IgnoreUnused.hpp>
23 #include <common/include/NumericCast.hpp>
24 #include <common/include/Optional.hpp>
25 #include <common/include/ProfilingException.hpp>
26 #include <common/include/ProfilingGuidGenerator.hpp>
27 
28 #include <atomic>
29 #include <condition_variable>
30 #include <mutex>
31 #include <thread>
32 
33 namespace arm
34 {
35 
36 namespace pipe
37 {
38 
39 class MockProfilingConnection : public IProfilingConnection
40 {
41 public:
MockProfilingConnection()42     MockProfilingConnection()
43         : m_IsOpen(true)
44         , m_WrittenData()
45         , m_Packet()
46     {}
47 
48     enum class PacketType
49     {
50         StreamMetaData,
51         ConnectionAcknowledge,
52         CounterDirectory,
53         ReqCounterDirectory,
54         PeriodicCounterSelection,
55         PerJobCounterSelection,
56         TimelineMessageDirectory,
57         PeriodicCounterCapture,
58         ActivateTimelineReporting,
59         DeactivateTimelineReporting,
60         Unknown
61     };
62 
IsOpen() const63     bool IsOpen() const override
64     {
65         std::lock_guard<std::mutex> lock(m_Mutex);
66 
67         return m_IsOpen;
68     }
69 
Close()70     void Close() override
71     {
72         std::lock_guard<std::mutex> lock(m_Mutex);
73 
74         m_IsOpen = false;
75     }
76 
WritePacket(const unsigned char * buffer,uint32_t length)77     bool WritePacket(const unsigned char* buffer, uint32_t length) override
78     {
79         if (buffer == nullptr || length == 0)
80         {
81             return false;
82         }
83 
84         uint32_t header = ReadUint32(buffer, 0);
85 
86         uint32_t packetFamily = (header >> 26);
87         uint32_t packetId = ((header >> 16) & 1023);
88 
89         PacketType packetType;
90 
91         switch (packetFamily)
92         {
93             case 0:
94                 packetType = packetId < 8 ? PacketType(packetId) : PacketType::Unknown;
95                 break;
96             case 1:
97                 packetType = packetId == 0 ? PacketType::TimelineMessageDirectory : PacketType::Unknown;
98                 break;
99             case 3:
100                 packetType = packetId == 0 ? PacketType::PeriodicCounterCapture : PacketType::Unknown;
101                 break;
102             default:
103                 packetType = PacketType::Unknown;
104         }
105 
106         std::lock_guard<std::mutex> lock(m_Mutex);
107 
108         m_WrittenData.push_back({ packetType, length });
109         return true;
110     }
111 
CheckForPacket(const std::pair<PacketType,uint32_t> packetInfo)112     long CheckForPacket(const std::pair<PacketType, uint32_t> packetInfo)
113     {
114         std::lock_guard<std::mutex> lock(m_Mutex);
115 
116         if(packetInfo.second != 0)
117         {
118             return static_cast<long>(std::count(m_WrittenData.begin(), m_WrittenData.end(), packetInfo));
119         }
120         else
121         {
122             return static_cast<long>(std::count_if(m_WrittenData.begin(), m_WrittenData.end(),
123             [&packetInfo](const std::pair<PacketType, uint32_t> pair) { return packetInfo.first == pair.first; }));
124         }
125     }
126 
WritePacket(arm::pipe::Packet && packet)127     bool WritePacket(arm::pipe::Packet&& packet)
128     {
129         std::lock_guard<std::mutex> lock(m_Mutex);
130 
131         m_Packet = std::move(packet);
132         return true;
133     }
134 
ReadPacket(uint32_t timeout)135     arm::pipe::Packet ReadPacket(uint32_t timeout) override
136     {
137         arm::pipe::IgnoreUnused(timeout);
138 
139         // Simulate a delay in the reading process. The default timeout is way too long.
140         std::this_thread::sleep_for(std::chrono::milliseconds(5));
141         std::lock_guard<std::mutex> lock(m_Mutex);
142         return std::move(m_Packet);
143     }
144 
GetWrittenDataSize()145     unsigned long GetWrittenDataSize()
146     {
147         std::lock_guard<std::mutex> lock(m_Mutex);
148 
149         return static_cast<unsigned long>(m_WrittenData.size());
150     }
151 
Clear()152     void Clear()
153     {
154         std::lock_guard<std::mutex> lock(m_Mutex);
155 
156         m_WrittenData.clear();
157     }
158 
159 private:
160     bool m_IsOpen;
161     std::vector<std::pair<PacketType, uint32_t>> m_WrittenData;
162     arm::pipe::Packet m_Packet;
163     mutable std::mutex m_Mutex;
164 };
165 
166 class MockProfilingConnectionFactory : public IProfilingConnectionFactory
167 {
168 public:
GetProfilingConnection(const ProfilingOptions & options) const169     IProfilingConnectionPtr GetProfilingConnection(const ProfilingOptions& options) const override
170     {
171         arm::pipe::IgnoreUnused(options);
172         return std::make_unique<MockProfilingConnection>();
173     }
174 };
175 
176 class MockPacketBuffer : public IPacketBuffer
177 {
178 public:
MockPacketBuffer(unsigned int maxSize)179     MockPacketBuffer(unsigned int maxSize)
180         : m_MaxSize(maxSize)
181         , m_Size(0)
182         , m_Data(std::make_unique<unsigned char[]>(m_MaxSize))
183     {}
184 
~MockPacketBuffer()185     ~MockPacketBuffer() {}
186 
GetReadableData() const187     const unsigned char* GetReadableData() const override { return m_Data.get(); }
188 
GetSize() const189     unsigned int GetSize() const override { return m_Size; }
190 
MarkRead()191     void MarkRead() override { m_Size = 0; }
192 
Commit(unsigned int size)193     void Commit(unsigned int size) override { m_Size = size; }
194 
Release()195     void Release() override { m_Size = 0; }
196 
GetWritableData()197     unsigned char* GetWritableData() override { return m_Data.get(); }
198 
Destroy()199     void Destroy() override {m_Data.reset(nullptr); m_Size = 0; m_MaxSize =0;}
200 
201 private:
202     unsigned int m_MaxSize;
203     unsigned int m_Size;
204     std::unique_ptr<unsigned char[]> m_Data;
205 };
206 
207 class MockBufferManager : public IBufferManager
208 {
209 public:
MockBufferManager(unsigned int size)210     MockBufferManager(unsigned int size)
211     : m_BufferSize(size),
212       m_Buffer(std::make_unique<MockPacketBuffer>(size)) {}
213 
~MockBufferManager()214     ~MockBufferManager() {}
215 
Reserve(unsigned int requestedSize,unsigned int & reservedSize)216     IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
217     {
218         if (requestedSize > m_BufferSize)
219         {
220             reservedSize = m_BufferSize;
221         }
222         else
223         {
224             reservedSize = requestedSize;
225         }
226 
227         return std::move(m_Buffer);
228     }
229 
Commit(IPacketBufferPtr & packetBuffer,unsigned int size,bool notifyConsumer=true)230     void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override
231     {
232         packetBuffer->Commit(size);
233         m_Buffer = std::move(packetBuffer);
234 
235         if (notifyConsumer)
236         {
237             FlushReadList();
238         }
239     }
240 
GetReadableBuffer()241     IPacketBufferPtr GetReadableBuffer() override
242     {
243         return std::move(m_Buffer);
244     }
245 
Release(IPacketBufferPtr & packetBuffer)246     void Release(IPacketBufferPtr& packetBuffer) override
247     {
248         packetBuffer->Release();
249         m_Buffer = std::move(packetBuffer);
250     }
251 
MarkRead(IPacketBufferPtr & packetBuffer)252     void MarkRead(IPacketBufferPtr& packetBuffer) override
253     {
254         packetBuffer->MarkRead();
255         m_Buffer = std::move(packetBuffer);
256     }
257 
SetConsumer(IConsumer * consumer)258     void SetConsumer(IConsumer* consumer) override
259    {
260         if (consumer != nullptr)
261         {
262             m_Consumer = consumer;
263         }
264    }
265 
FlushReadList()266     void FlushReadList() override
267     {
268         // notify consumer that packet is ready to read
269         if (m_Consumer != nullptr)
270         {
271             m_Consumer->SetReadyToRead();
272         }
273     }
274 
275 private:
276     unsigned int m_BufferSize;
277     IPacketBufferPtr m_Buffer;
278     IConsumer* m_Consumer = nullptr;
279 };
280 
281 class MockStreamCounterBuffer : public IBufferManager
282 {
283 public:
MockStreamCounterBuffer(unsigned int maxBufferSize=4096)284     MockStreamCounterBuffer(unsigned int maxBufferSize = 4096)
285         : m_MaxBufferSize(maxBufferSize)
286         , m_BufferList()
287         , m_CommittedSize(0)
288         , m_ReadableSize(0)
289         , m_ReadSize(0)
290     {}
~MockStreamCounterBuffer()291     ~MockStreamCounterBuffer() {}
292 
Reserve(unsigned int requestedSize,unsigned int & reservedSize)293     IPacketBufferPtr Reserve(unsigned int requestedSize, unsigned int& reservedSize) override
294     {
295         std::lock_guard<std::mutex> lock(m_Mutex);
296 
297         reservedSize = 0;
298         if (requestedSize > m_MaxBufferSize)
299         {
300             throw arm::pipe::InvalidArgumentException("The maximum buffer size that can be requested is [" +
301                                                       std::to_string(m_MaxBufferSize) + "] bytes");
302         }
303         reservedSize = requestedSize;
304         return std::make_unique<MockPacketBuffer>(requestedSize);
305     }
306 
Commit(IPacketBufferPtr & packetBuffer,unsigned int size,bool notifyConsumer=true)307     void Commit(IPacketBufferPtr& packetBuffer, unsigned int size, bool notifyConsumer = true) override
308     {
309         std::lock_guard<std::mutex> lock(m_Mutex);
310 
311         packetBuffer->Commit(size);
312         m_BufferList.push_back(std::move(packetBuffer));
313         m_CommittedSize += size;
314 
315         if (notifyConsumer)
316         {
317             FlushReadList();
318         }
319     }
320 
Release(IPacketBufferPtr & packetBuffer)321     void Release(IPacketBufferPtr& packetBuffer) override
322     {
323         std::lock_guard<std::mutex> lock(m_Mutex);
324 
325         packetBuffer->Release();
326     }
327 
GetReadableBuffer()328     IPacketBufferPtr GetReadableBuffer() override
329     {
330         std::lock_guard<std::mutex> lock(m_Mutex);
331 
332         if (m_BufferList.empty())
333         {
334             return nullptr;
335         }
336         IPacketBufferPtr buffer = std::move(m_BufferList.back());
337         m_BufferList.pop_back();
338         m_ReadableSize += buffer->GetSize();
339         return buffer;
340     }
341 
MarkRead(IPacketBufferPtr & packetBuffer)342     void MarkRead(IPacketBufferPtr& packetBuffer) override
343     {
344         std::lock_guard<std::mutex> lock(m_Mutex);
345 
346         m_ReadSize += packetBuffer->GetSize();
347         packetBuffer->MarkRead();
348     }
349 
SetConsumer(IConsumer * consumer)350     void SetConsumer(IConsumer* consumer) override
351     {
352         if (consumer != nullptr)
353         {
354             m_Consumer = consumer;
355         }
356     }
357 
FlushReadList()358     void FlushReadList() override
359     {
360         // notify consumer that packet is ready to read
361         if (m_Consumer != nullptr)
362         {
363             m_Consumer->SetReadyToRead();
364         }
365     }
366 
GetCommittedSize() const367     unsigned int GetCommittedSize() const { return m_CommittedSize; }
GetReadableSize() const368     unsigned int GetReadableSize()  const { return m_ReadableSize;  }
GetReadSize() const369     unsigned int GetReadSize()      const { return m_ReadSize;      }
370 
371 private:
372     // The maximum buffer size when creating a new buffer
373     unsigned int m_MaxBufferSize;
374 
375     // A list of buffers
376     std::vector<IPacketBufferPtr> m_BufferList;
377 
378     // The mutex to synchronize this mock's methods
379     std::mutex m_Mutex;
380 
381     // The total size of the buffers that has been committed for reading
382     unsigned int m_CommittedSize;
383 
384     // The total size of the buffers that can be read
385     unsigned int m_ReadableSize;
386 
387     // The total size of the buffers that has already been read
388     unsigned int m_ReadSize;
389 
390     // Consumer thread to notify packet is ready to read
391     IConsumer* m_Consumer = nullptr;
392 };
393 
394 class MockSendCounterPacket : public ISendCounterPacket
395 {
396 public:
MockSendCounterPacket(IBufferManager & sendBuffer)397     MockSendCounterPacket(IBufferManager& sendBuffer) : m_BufferManager(sendBuffer) {}
398 
SendStreamMetaDataPacket()399     void SendStreamMetaDataPacket() override
400     {
401         std::string message("SendStreamMetaDataPacket");
402         unsigned int reserved = 0;
403         IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
404         memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
405         m_BufferManager.Commit(buffer, reserved, false);
406     }
407 
SendCounterDirectoryPacket(const ICounterDirectory & counterDirectory)408     void SendCounterDirectoryPacket(const ICounterDirectory& counterDirectory) override
409     {
410         arm::pipe::IgnoreUnused(counterDirectory);
411 
412         std::string message("SendCounterDirectoryPacket");
413         unsigned int reserved = 0;
414         IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
415         memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
416         m_BufferManager.Commit(buffer, reserved);
417     }
418 
SendPeriodicCounterCapturePacket(uint64_t timestamp,const std::vector<CounterValue> & values)419     void SendPeriodicCounterCapturePacket(uint64_t timestamp,
420                                           const std::vector<CounterValue>& values) override
421     {
422         arm::pipe::IgnoreUnused(timestamp, values);
423 
424         std::string message("SendPeriodicCounterCapturePacket");
425         unsigned int reserved = 0;
426         IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
427         memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
428         m_BufferManager.Commit(buffer, reserved);
429     }
430 
SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,const std::vector<uint16_t> & selectedCounterIds)431     void SendPeriodicCounterSelectionPacket(uint32_t capturePeriod,
432                                             const std::vector<uint16_t>& selectedCounterIds) override
433     {
434         arm::pipe::IgnoreUnused(capturePeriod, selectedCounterIds);
435 
436         std::string message("SendPeriodicCounterSelectionPacket");
437         unsigned int reserved = 0;
438         IPacketBufferPtr buffer = m_BufferManager.Reserve(1024, reserved);
439         memcpy(buffer->GetWritableData(), message.c_str(), static_cast<unsigned int>(message.size()) + 1);
440         m_BufferManager.Commit(buffer, reserved);
441     }
442 
443 private:
444     IBufferManager& m_BufferManager;
445 };
446 
447 class MockCounterDirectory : public ICounterDirectory
448 {
449 public:
450     MockCounterDirectory() = default;
451     ~MockCounterDirectory() = default;
452 
453     // Register profiling objects
RegisterCategory(const std::string & categoryName)454     const Category* RegisterCategory(const std::string& categoryName)
455     {
456         // Create the category
457         CategoryPtr category = std::make_unique<Category>(categoryName);
458         ARM_PIPE_ASSERT(category);
459 
460         // Get the raw category pointer
461         const Category* categoryPtr = category.get();
462         ARM_PIPE_ASSERT(categoryPtr);
463 
464         // Register the category
465         m_Categories.insert(std::move(category));
466 
467         return categoryPtr;
468     }
469 
RegisterDevice(const std::string & deviceName,uint16_t cores=0)470     const Device* RegisterDevice(const std::string& deviceName,
471                                  uint16_t cores = 0)
472     {
473         // Get the device UID
474         uint16_t deviceUid = GetNextUid();
475 
476         // Create the device
477         DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
478         ARM_PIPE_ASSERT(device);
479 
480         // Get the raw device pointer
481         const Device* devicePtr = device.get();
482         ARM_PIPE_ASSERT(devicePtr);
483 
484         // Register the device
485         m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
486 
487         return devicePtr;
488     }
489 
RegisterCounterSet(const std::string & counterSetName,uint16_t count=0)490     const CounterSet* RegisterCounterSet(
491             const std::string& counterSetName,
492             uint16_t count = 0)
493     {
494         // Get the counter set UID
495         uint16_t counterSetUid = GetNextUid();
496 
497         // Create the counter set
498         CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
499         ARM_PIPE_ASSERT(counterSet);
500 
501         // Get the raw counter set pointer
502         const CounterSet* counterSetPtr = counterSet.get();
503         ARM_PIPE_ASSERT(counterSetPtr);
504 
505         // Register the counter set
506         m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
507 
508         return counterSetPtr;
509     }
510 
RegisterCounter(const std::string & backendId,const uint16_t uid,const std::string & parentCategoryName,uint16_t counterClass,uint16_t interpolation,double multiplier,const std::string & name,const std::string & description,const arm::pipe::Optional<std::string> & units=arm::pipe::EmptyOptional (),const arm::pipe::Optional<uint16_t> & numberOfCores=arm::pipe::EmptyOptional (),const arm::pipe::Optional<uint16_t> & deviceUid=arm::pipe::EmptyOptional (),const arm::pipe::Optional<uint16_t> & counterSetUid=arm::pipe::EmptyOptional ())511     const Counter* RegisterCounter(const std::string& backendId,
512                                    const uint16_t uid,
513                                    const std::string& parentCategoryName,
514                                    uint16_t counterClass,
515                                    uint16_t interpolation,
516                                    double multiplier,
517                                    const std::string& name,
518                                    const std::string& description,
519                                    const arm::pipe::Optional<std::string>& units = arm::pipe::EmptyOptional(),
520                                    const arm::pipe::Optional<uint16_t>& numberOfCores = arm::pipe::EmptyOptional(),
521                                    const arm::pipe::Optional<uint16_t>& deviceUid = arm::pipe::EmptyOptional(),
522                                    const arm::pipe::Optional<uint16_t>& counterSetUid = arm::pipe::EmptyOptional())
523     {
524         arm::pipe::IgnoreUnused(backendId);
525 
526         // Get the number of cores from the argument only
527         uint16_t deviceCores = numberOfCores.has_value() ? numberOfCores.value() : 0;
528 
529         // Get the device UID
530         uint16_t deviceUidValue = deviceUid.has_value() ? deviceUid.value() : 0;
531 
532         // Get the counter set UID
533         uint16_t counterSetUidValue = counterSetUid.has_value() ? counterSetUid.value() : 0;
534 
535         // Get the counter UIDs and calculate the max counter UID
536         std::vector<uint16_t> counterUids = GetNextCounterUids(uid, deviceCores);
537         ARM_PIPE_ASSERT(!counterUids.empty());
538         uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
539 
540         // Get the counter units
541         const std::string unitsValue = units.has_value() ? units.value() : "";
542 
543         // Create the counter
544         CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
545                                                        counterUids.front(),
546                                                        maxCounterUid,
547                                                        counterClass,
548                                                        interpolation,
549                                                        multiplier,
550                                                        name,
551                                                        description,
552                                                        unitsValue,
553                                                        deviceUidValue,
554                                                        counterSetUidValue);
555         ARM_PIPE_ASSERT(counter);
556 
557         // Get the raw counter pointer
558         const Counter* counterPtr = counter.get();
559         ARM_PIPE_ASSERT(counterPtr);
560 
561         // Process multiple counters if necessary
562         for (uint16_t counterUid : counterUids)
563         {
564             // Connect the counter to the parent category
565             Category* parentCategory = const_cast<Category*>(GetCategory(parentCategoryName));
566             ARM_PIPE_ASSERT(parentCategory);
567             parentCategory->m_Counters.push_back(counterUid);
568 
569             // Register the counter
570             m_Counters.insert(std::make_pair(counterUid, counter));
571         }
572 
573         return counterPtr;
574     }
575 
576     // Getters for counts
GetCategoryCount() const577     uint16_t GetCategoryCount()   const override { return arm::pipe::numeric_cast<uint16_t>(m_Categories.size());  }
GetDeviceCount() const578     uint16_t GetDeviceCount()     const override { return arm::pipe::numeric_cast<uint16_t>(m_Devices.size());     }
GetCounterSetCount() const579     uint16_t GetCounterSetCount() const override { return arm::pipe::numeric_cast<uint16_t>(m_CounterSets.size()); }
GetCounterCount() const580     uint16_t GetCounterCount()    const override { return arm::pipe::numeric_cast<uint16_t>(m_Counters.size());    }
581 
582     // Getters for collections
GetCategories() const583     const Categories&  GetCategories()  const override { return m_Categories;  }
GetDevices() const584     const Devices&     GetDevices()     const override { return m_Devices;     }
GetCounterSets() const585     const CounterSets& GetCounterSets() const override { return m_CounterSets; }
GetCounters() const586     const Counters&    GetCounters()    const override { return m_Counters;    }
587 
588     // Getters for profiling objects
GetCategory(const std::string & name) const589     const Category* GetCategory(const std::string& name) const override
590     {
591         auto it = std::find_if(m_Categories.begin(), m_Categories.end(), [&name](const CategoryPtr& category)
592         {
593             ARM_PIPE_ASSERT(category);
594 
595             return category->m_Name == name;
596         });
597 
598         if (it == m_Categories.end())
599         {
600             return nullptr;
601         }
602 
603         return it->get();
604     }
605 
GetDevice(uint16_t uid) const606     const Device* GetDevice(uint16_t uid) const override
607     {
608         arm::pipe::IgnoreUnused(uid);
609         return nullptr; // Not used by the unit tests
610     }
611 
GetCounterSet(uint16_t uid) const612     const CounterSet* GetCounterSet(uint16_t uid) const override
613     {
614         arm::pipe::IgnoreUnused(uid);
615         return nullptr; // Not used by the unit tests
616     }
617 
GetCounter(uint16_t uid) const618     const Counter* GetCounter(uint16_t uid) const override
619     {
620         arm::pipe::IgnoreUnused(uid);
621         return nullptr; // Not used by the unit tests
622     }
623 
624 private:
625     Categories  m_Categories;
626     Devices     m_Devices;
627     CounterSets m_CounterSets;
628     Counters    m_Counters;
629 };
630 
631 class MockProfilingService : public ProfilingService
632 {
633 public:
MockProfilingService(uint16_t maxGlobalCounterId,IInitialiseProfilingService & initialiser,MockBufferManager & mockBufferManager,bool isProfilingEnabled,const CaptureData & captureData)634     MockProfilingService(uint16_t maxGlobalCounterId,
635                          IInitialiseProfilingService& initialiser,
636                          MockBufferManager& mockBufferManager,
637                          bool isProfilingEnabled,
638                          const CaptureData& captureData) :
639         ProfilingService(maxGlobalCounterId,
640                          initialiser,
641                          arm::pipe::ARMNN_SOFTWARE_INFO,
642                          arm::pipe::ARMNN_SOFTWARE_VERSION,
643                          arm::pipe::ARMNN_HARDWARE_VERSION),
644         m_SendCounterPacket(mockBufferManager,
645                             arm::pipe::ARMNN_SOFTWARE_INFO,
646                             arm::pipe::ARMNN_SOFTWARE_VERSION,
647                             arm::pipe::ARMNN_HARDWARE_VERSION),
648         m_IsProfilingEnabled(isProfilingEnabled),
649         m_CaptureData(captureData)
650     {}
651 
652     /// Return the next random Guid in the sequence
NextGuid()653     ProfilingDynamicGuid NextGuid() override
654     {
655         return m_GuidGenerator.NextGuid();
656     }
657 
658     /// Create a ProfilingStaticGuid based on a hash of the string
GenerateStaticId(const std::string & str)659     ProfilingStaticGuid GenerateStaticId(const std::string& str) override
660     {
661         return m_GuidGenerator.GenerateStaticId(str);
662     }
663 
GetSendTimelinePacket() const664     std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() const override
665     {
666         return nullptr;
667     }
668 
GetCounterMappings() const669     const ICounterMappings& GetCounterMappings() const override
670     {
671         return m_CounterMapping;
672     }
673 
GetSendCounterPacket()674     ISendCounterPacket& GetSendCounterPacket() override
675     {
676         return m_SendCounterPacket;
677     }
678 
IsProfilingEnabled() const679     bool IsProfilingEnabled() const override
680     {
681         return m_IsProfilingEnabled;
682     }
683 
GetCaptureData()684     CaptureData GetCaptureData() override
685     {
686         CaptureData copy(m_CaptureData);
687         return copy;
688     }
689 
RegisterMapping(uint16_t globalCounterId,uint16_t backendCounterId,const std::string & backendId)690     void RegisterMapping(uint16_t globalCounterId,
691                          uint16_t backendCounterId,
692                          const std::string& backendId)
693     {
694         m_CounterMapping.RegisterMapping(globalCounterId, backendCounterId, backendId);
695     }
696 
Reset()697     void Reset()
698     {
699         m_CounterMapping.Reset();
700     }
701 
702 private:
703     ProfilingGuidGenerator m_GuidGenerator;
704     CounterIdMap           m_CounterMapping;
705     SendCounterPacket      m_SendCounterPacket;
706     bool                   m_IsProfilingEnabled;
707     CaptureData            m_CaptureData;
708 };
709 
710 class MockProfilingServiceStatus : public IProfilingServiceStatus
711 {
712 public:
NotifyProfilingServiceActive()713     void NotifyProfilingServiceActive() override {}
WaitForProfilingServiceActivation(unsigned int timeout)714     void WaitForProfilingServiceActivation(unsigned int timeout) override { arm::pipe::IgnoreUnused(timeout); }
715 };
716 
717 } // namespace pipe
718 
719 } // namespace arm
720