13 #include <common/include/SwTrace.hpp> 15 #include <fmt/format.h> 26 if (categoryName.empty() ||
27 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(categoryName))
40 CategoryPtr category = std::make_unique<Category>(categoryName);
44 const Category* categoryPtr = category.get();
48 m_Categories.insert(std::move(category));
58 if (deviceName.empty() ||
59 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(deviceName))
75 const std::string& parentCategoryNameValue = parentCategoryName.
value();
76 if (parentCategoryNameValue.empty())
79 fmt::format(
"Trying to connect a device (name: \"{}\") to an invalid " 80 "parent category (name: \"{}\")",
82 parentCategoryNameValue));
86 auto categoryIt = FindCategory(parentCategoryNameValue);
87 if (categoryIt == m_Categories.end())
90 fmt::format(
"Trying to connect a device (name: \"{}\") to a parent category that " 91 "is not registered (name: \"{}\")",
93 parentCategoryNameValue));
101 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
105 const Device* devicePtr = device.get();
109 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
119 if (counterSetName.empty() ||
120 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(counterSetName))
129 fmt::format(
"Trying to register a counter set already registered (\"{}\")",
135 uint16_t counterSetUidPeek =
GetNextUid(
true);
141 const std::string& parentCategoryNameValue = parentCategoryName.
value();
142 if (parentCategoryNameValue.empty())
145 fmt::format(
"Trying to connect a counter set (UID: {}) to an invalid " 146 "parent category (name: \"{}\")",
148 parentCategoryNameValue));
152 auto it = FindCategory(parentCategoryNameValue);
153 if (it == m_Categories.end())
156 fmt::format(
"Trying to connect a counter set (UID: {}) to a parent category " 157 "that is not registered (name: \"{}\")",
159 parentCategoryNameValue));
168 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
172 const CounterSet* counterSetPtr = counterSet.get();
176 m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
178 return counterSetPtr;
183 const std::string& parentCategoryName,
184 uint16_t counterClass,
185 uint16_t interpolation,
187 const std::string& name,
188 const std::string& description,
197 if (parentCategoryName.empty() ||
198 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(parentCategoryName))
204 if (counterClass != 0 && counterClass != 1)
210 if (interpolation != 0 && interpolation != 1)
216 if (multiplier == .0f)
223 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(name))
229 if (description.empty() ||
230 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(description))
237 && !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(units.
value()))
243 auto categoryIt = FindCategory(parentCategoryName);
244 if (categoryIt == m_Categories.end())
247 fmt::format(
"Trying to connect a counter to a category that is not registered (name: \"{}\")",
248 parentCategoryName));
256 const std::vector<uint16_t>& parentCategoryCounters = parentCategory->m_Counters;
257 for (uint16_t parentCategoryCounterUid : parentCategoryCounters)
262 if (parentCategoryCounter->
m_Name == name)
265 fmt::format(
"Trying to register a counter to category \"{}\" with a name that " 266 "is already used within that category (name: \"{}\")",
273 uint16_t counterSetUidValue = counterSetUid.
has_value() ? counterSetUid.
value() : 0;
274 if (counterSetUidValue > 0)
280 fmt::format(
"Trying to connect a counter to a counter set that is " 281 "not registered (counter set UID: {})",
282 counterSetUidValue));
287 uint16_t deviceUidValue = deviceUid.
has_value() ? deviceUid.
value() : 0;
288 uint16_t deviceCores = GetNumberOfCores(numberOfCores, deviceUidValue);
293 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
296 const std::string unitsValue = units.
has_value() ? units.
value() :
"";
299 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
313 const Counter* counterPtr = counter.get();
317 for (uint16_t counterUid : counterUids)
320 parentCategory->m_Counters.push_back(counterUid);
323 m_Counters.insert(std::make_pair(counterUid, counter));
331 auto it = FindCategory(categoryName);
332 if (it == m_Categories.end())
337 const Category* category = it->get();
345 auto it = FindDevice(deviceUid);
346 if (it == m_Devices.end())
351 const Device* device = it->second.get();
360 auto it = FindCounterSet(counterSetUid);
361 if (it == m_CounterSets.end())
366 const CounterSet* counterSet = it->second.get();
375 auto it = FindCounter(counterUid);
376 if (it == m_Counters.end())
381 const Counter* counter = it->second.get();
391 auto it = FindCategory(categoryName);
393 return it != m_Categories.end();
398 auto it = FindDevice(deviceUid);
400 return it != m_Devices.end();
405 auto it = FindDevice(deviceName);
407 return it != m_Devices.end();
412 auto it = FindCounterSet(counterSetUid);
414 return it != m_CounterSets.end();
419 auto it = FindCounterSet(counterSetName);
421 return it != m_CounterSets.end();
426 auto it = FindCounter(counterUid);
428 return it != m_Counters.end();
433 auto it = FindCounter(counterName);
435 return it != m_Counters.end();
441 m_Categories.clear();
443 m_CounterSets.clear();
447 CategoriesIt CounterDirectory::FindCategory(
const std::string& categoryName)
const 449 return std::find_if(m_Categories.begin(), m_Categories.end(), [&categoryName](
const CategoryPtr& category)
453 return category->m_Name == categoryName;
457 DevicesIt CounterDirectory::FindDevice(uint16_t deviceUid)
const 459 return m_Devices.find(deviceUid);
462 DevicesIt CounterDirectory::FindDevice(
const std::string& deviceName)
const 464 return std::find_if(m_Devices.begin(), m_Devices.end(), [&deviceName](
const auto& pair)
469 return pair.second->m_Name == deviceName;
473 CounterSetsIt CounterDirectory::FindCounterSet(uint16_t counterSetUid)
const 475 return m_CounterSets.find(counterSetUid);
478 CounterSetsIt CounterDirectory::FindCounterSet(
const std::string& counterSetName)
const 480 return std::find_if(m_CounterSets.begin(), m_CounterSets.end(), [&counterSetName](
const auto& pair)
485 return pair.second->m_Name == counterSetName;
489 CountersIt CounterDirectory::FindCounter(uint16_t counterUid)
const 491 return m_Counters.find(counterUid);
494 CountersIt CounterDirectory::FindCounter(
const std::string& counterName)
const 496 return std::find_if(m_Counters.begin(), m_Counters.end(), [&counterName](
const auto& pair)
499 ARMNN_ASSERT(pair.first >= pair.second->m_Uid && pair.first <= pair.second->m_MaxCounterUid);
501 return pair.second->m_Name == counterName;
519 return numberOfCores.
value();
527 auto deviceIt = FindDevice(deviceUid);
528 if (deviceIt == m_Devices.end())
531 fmt::format(
"Trying to connect a counter to a device that is not registered (device UID {})",
536 const DevicePtr& device = deviceIt->second;
540 return device->m_Cores;
bool IsCategoryRegistered(const std::string &categoryName) const
const Category * RegisterCategory(const std::string &categoryName) override
const Counter * RegisterCounter(const BackendId &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 Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
CounterSets::const_iterator CounterSetsIt
Categories::const_iterator CategoriesIt
std::unique_ptr< Device > DevicePtr
const Device * GetDevice(uint16_t uid) const override
std::unique_ptr< CounterSet > CounterSetPtr
Devices::const_iterator DevicesIt
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
bool IsDeviceRegistered(uint16_t deviceUid) const
uint16_t GetNextUid(bool peekOnly)
std::shared_ptr< Counter > CounterPtr
bool has_value() const noexcept
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)
#define ARMNN_ASSERT(COND)
const Counter * GetCounter(uint16_t uid) const override
const Category * GetCategory(const std::string &name) const override
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
bool IsCounterRegistered(uint16_t counterUid) const
std::unique_ptr< Category > CategoryPtr
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
const CounterSet * GetCounterSet(uint16_t uid) const override
Counters::const_iterator CountersIt
bool IsCounterSetRegistered(uint16_t counterSetUid) const