14 #include <boost/format.hpp> 25 if (categoryName.empty() ||
26 !IsValidSwTraceString<SwTraceNameCharPolicy>(categoryName))
35 boost::str(boost::format(
"Trying to register a category already registered (\"%1%\")")
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 !IsValidSwTraceString<SwTraceCharPolicy>(deviceName))
68 boost::str(boost::format(
"Trying to register a device already registered (\"%1%\")")
76 const std::string& parentCategoryNameValue = parentCategoryName.
value();
77 if (parentCategoryNameValue.empty())
80 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to an invalid " 81 "parent category (name: \"%2%\")")
83 % parentCategoryNameValue));
87 auto categoryIt = FindCategory(parentCategoryNameValue);
88 if (categoryIt == m_Categories.end())
91 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to a parent category that " 92 "is not registered (name: \"%2%\")")
94 % parentCategoryNameValue));
102 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
106 const Device* devicePtr = device.get();
110 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
120 if (counterSetName.empty() ||
121 !IsValidSwTraceString<SwTraceNameCharPolicy>(counterSetName))
130 boost::str(boost::format(
"Trying to register a counter set already registered (\"%1%\")")
136 uint16_t counterSetUidPeek =
GetNextUid(
true);
142 const std::string& parentCategoryNameValue = parentCategoryName.
value();
143 if (parentCategoryNameValue.empty())
146 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to an invalid " 147 "parent category (name: \"%2%\")")
149 % parentCategoryNameValue));
153 auto it = FindCategory(parentCategoryNameValue);
154 if (it == m_Categories.end())
157 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to a parent category " 158 "that is not registered (name: \"%2%\")")
160 % parentCategoryNameValue));
169 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
173 const CounterSet* counterSetPtr = counterSet.get();
177 m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
179 return counterSetPtr;
184 const std::string& parentCategoryName,
185 uint16_t counterClass,
186 uint16_t interpolation,
188 const std::string& name,
189 const std::string& description,
198 if (parentCategoryName.empty() ||
199 !IsValidSwTraceString<SwTraceNameCharPolicy>(parentCategoryName))
205 if (counterClass != 0 && counterClass != 1)
211 if (interpolation != 0 && interpolation != 1)
217 if (multiplier == .0f)
224 !IsValidSwTraceString<SwTraceCharPolicy>(name))
230 if (description.empty() ||
231 !IsValidSwTraceString<SwTraceCharPolicy>(description))
238 && !IsValidSwTraceString<SwTraceNameCharPolicy>(units.
value()))
244 auto categoryIt = FindCategory(parentCategoryName);
245 if (categoryIt == m_Categories.end())
248 boost::str(boost::format(
"Trying to connect a counter to a category " 249 "that is not registered (name: \"%1%\")")
250 % parentCategoryName));
258 const std::vector<uint16_t>& parentCategoryCounters = parentCategory->m_Counters;
259 for (uint16_t parentCategoryCounterUid : parentCategoryCounters)
264 if (parentCategoryCounter->
m_Name == name)
267 boost::str(boost::format(
"Trying to register a counter to category \"%1%\" with a name that " 268 "is already used within that category (name: \"%2%\")")
275 uint16_t counterSetUidValue = counterSetUid.
has_value() ? counterSetUid.
value() : 0;
276 if (counterSetUidValue > 0)
282 boost::str(boost::format(
"Trying to connect a counter to a counter set that is " 283 "not registered (counter set UID: %1%)")
284 % counterSetUidValue));
289 uint16_t deviceUidValue = deviceUid.
has_value() ? deviceUid.
value() : 0;
290 uint16_t deviceCores = GetNumberOfCores(numberOfCores, deviceUidValue);
295 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
298 const std::string unitsValue = units.
has_value() ? units.
value() :
"";
301 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
315 const Counter* counterPtr = counter.get();
319 for (uint16_t counterUid : counterUids)
322 parentCategory->m_Counters.push_back(counterUid);
325 m_Counters.insert(std::make_pair(counterUid, counter));
333 auto it = FindCategory(categoryName);
334 if (it == m_Categories.end())
339 const Category* category = it->get();
347 auto it = FindDevice(deviceUid);
348 if (it == m_Devices.end())
353 const Device* device = it->second.get();
362 auto it = FindCounterSet(counterSetUid);
363 if (it == m_CounterSets.end())
368 const CounterSet* counterSet = it->second.get();
377 auto it = FindCounter(counterUid);
378 if (it == m_Counters.end())
383 const Counter* counter = it->second.get();
393 auto it = FindCategory(categoryName);
395 return it != m_Categories.end();
400 auto it = FindDevice(deviceUid);
402 return it != m_Devices.end();
407 auto it = FindDevice(deviceName);
409 return it != m_Devices.end();
414 auto it = FindCounterSet(counterSetUid);
416 return it != m_CounterSets.end();
421 auto it = FindCounterSet(counterSetName);
423 return it != m_CounterSets.end();
428 auto it = FindCounter(counterUid);
430 return it != m_Counters.end();
435 auto it = FindCounter(counterName);
437 return it != m_Counters.end();
443 m_Categories.clear();
445 m_CounterSets.clear();
449 CategoriesIt CounterDirectory::FindCategory(
const std::string& categoryName)
const 451 return std::find_if(m_Categories.begin(), m_Categories.end(), [&categoryName](
const CategoryPtr& category)
455 return category->m_Name == categoryName;
459 DevicesIt CounterDirectory::FindDevice(uint16_t deviceUid)
const 461 return m_Devices.find(deviceUid);
464 DevicesIt CounterDirectory::FindDevice(
const std::string& deviceName)
const 466 return std::find_if(m_Devices.begin(), m_Devices.end(), [&deviceName](
const auto& pair)
471 return pair.second->m_Name == deviceName;
475 CounterSetsIt CounterDirectory::FindCounterSet(uint16_t counterSetUid)
const 477 return m_CounterSets.find(counterSetUid);
480 CounterSetsIt CounterDirectory::FindCounterSet(
const std::string& counterSetName)
const 482 return std::find_if(m_CounterSets.begin(), m_CounterSets.end(), [&counterSetName](
const auto& pair)
487 return pair.second->m_Name == counterSetName;
491 CountersIt CounterDirectory::FindCounter(uint16_t counterUid)
const 493 return m_Counters.find(counterUid);
496 CountersIt CounterDirectory::FindCounter(
const std::string& counterName)
const 498 return std::find_if(m_Counters.begin(), m_Counters.end(), [&counterName](
const auto& pair)
501 ARMNN_ASSERT(pair.first >= pair.second->m_Uid && pair.first <= pair.second->m_MaxCounterUid);
503 return pair.second->m_Name == counterName;
521 return numberOfCores.
value();
529 auto deviceIt = FindDevice(deviceUid);
530 if (deviceIt == m_Devices.end())
533 boost::str(boost::format(
"Trying to connect a counter to a device that is " 534 "not registered (device UID %1%)")
539 const DevicePtr& device = deviceIt->second;
543 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) 2020 ARM Limited.
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