12 #include <boost/core/ignore_unused.hpp> 13 #include <boost/format.hpp> 26 if (categoryName.empty() ||
27 !IsValidSwTraceString<SwTraceNameCharPolicy>(categoryName))
36 boost::str(boost::format(
"Trying to register a category already registered (\"%1%\")")
41 uint16_t deviceUidValue = deviceUid.
has_value() ? deviceUid.
value() : 0;
42 if (deviceUidValue > 0)
48 boost::str(boost::format(
"Trying to connect a category (\"%1%\") to a device that is " 49 "not registered (UID %2%)")
56 uint16_t counterSetUidValue = counterSetUid.
has_value() ? counterSetUid.
value() : 0;
57 if (counterSetUidValue > 0)
63 boost::str(boost::format(
"Trying to connect a category (name: \"%1%\") to a counter set " 64 "that is not registered (UID: %2%)")
66 % counterSetUidValue));
71 CategoryPtr category = std::make_unique<Category>(categoryName, deviceUidValue, counterSetUidValue);
72 BOOST_ASSERT(category);
75 const Category* categoryPtr = category.get();
76 BOOST_ASSERT(categoryPtr);
79 m_Categories.insert(std::move(category));
89 if (deviceName.empty() ||
90 !IsValidSwTraceString<SwTraceCharPolicy>(deviceName))
99 boost::str(boost::format(
"Trying to register a device already registered (\"%1%\")")
108 Category* parentCategoryPtr =
nullptr;
112 const std::string& parentCategoryNameValue = parentCategoryName.
value();
113 if (parentCategoryNameValue.empty())
116 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to an invalid " 117 "parent category (name: \"%2%\")")
119 % parentCategoryNameValue));
123 auto categoryIt = FindCategory(parentCategoryNameValue);
124 if (categoryIt == m_Categories.end())
127 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to a parent category that " 128 "is not registered (name: \"%2%\")")
130 % parentCategoryNameValue));
135 BOOST_ASSERT(parentCategory);
138 if (parentCategory->m_DeviceUid != 0 && parentCategory->m_DeviceUid != deviceUidPeek)
141 boost::str(boost::format(
"Trying to connect a device (UID: %1%) to a parent category that is " 142 "already connected to a different device " 143 "(category \"%2%\" connected to device %3%)")
145 % parentCategoryNameValue
146 % parentCategory->m_DeviceUid));
152 parentCategoryPtr = parentCategory.get();
157 BOOST_ASSERT(deviceUid == deviceUidPeek);
160 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
161 BOOST_ASSERT(device);
164 const Device* devicePtr = device.get();
165 BOOST_ASSERT(devicePtr);
168 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
171 if (parentCategoryPtr)
185 if (counterSetName.empty() ||
186 !IsValidSwTraceString<SwTraceNameCharPolicy>(counterSetName))
195 boost::str(boost::format(
"Trying to register a counter set already registered (\"%1%\")")
201 uint16_t counterSetUidPeek =
GetNextUid(
true);
204 Category* parentCategoryPtr =
nullptr;
208 const std::string& parentCategoryNameValue = parentCategoryName.
value();
209 if (parentCategoryNameValue.empty())
212 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to an invalid " 213 "parent category (name: \"%2%\")")
215 % parentCategoryNameValue));
219 auto it = FindCategory(parentCategoryNameValue);
220 if (it == m_Categories.end())
223 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to a parent category " 224 "that is not registered (name: \"%2%\")")
226 % parentCategoryNameValue));
231 BOOST_ASSERT(parentCategory);
234 if (parentCategory->m_CounterSetUid != 0 && parentCategory->m_CounterSetUid != counterSetUidPeek)
237 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to a parent category " 238 "that is already connected to a different counter set " 239 "(category \"%2%\" connected to counter set %3%)")
241 % parentCategoryNameValue
242 % parentCategory->m_CounterSetUid));
248 parentCategoryPtr = parentCategory.get();
253 BOOST_ASSERT(counterSetUid == counterSetUidPeek);
256 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
257 BOOST_ASSERT(counterSet);
260 const CounterSet* counterSetPtr = counterSet.get();
261 BOOST_ASSERT(counterSetPtr);
264 m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
267 if (parentCategoryPtr)
273 return counterSetPtr;
278 const std::string& parentCategoryName,
279 uint16_t counterClass,
280 uint16_t interpolation,
282 const std::string& name,
283 const std::string& description,
289 boost::ignore_unused(backendId);
292 if (parentCategoryName.empty() ||
293 !IsValidSwTraceString<SwTraceNameCharPolicy>(parentCategoryName))
299 if (counterClass != 0 && counterClass != 1)
305 if (interpolation != 0 && interpolation != 1)
311 if (multiplier == .0f)
318 !IsValidSwTraceString<SwTraceCharPolicy>(name))
324 if (description.empty() ||
325 !IsValidSwTraceString<SwTraceCharPolicy>(description))
332 && !IsValidSwTraceString<SwTraceNameCharPolicy>(units.
value()))
338 auto categoryIt = FindCategory(parentCategoryName);
339 if (categoryIt == m_Categories.end())
342 boost::str(boost::format(
"Trying to connect a counter to a category " 343 "that is not registered (name: \"%1%\")")
344 % parentCategoryName));
349 BOOST_ASSERT(parentCategory);
352 const std::vector<uint16_t>& parentCategoryCounters = parentCategory->m_Counters;
353 for (uint16_t parentCategoryCounterUid : parentCategoryCounters)
356 BOOST_ASSERT(parentCategoryCounter);
358 if (parentCategoryCounter->
m_Name == name)
361 boost::str(boost::format(
"Trying to register a counter to category \"%1%\" with a name that " 362 "is already used within that category (name: \"%2%\")")
369 uint16_t counterSetUidValue = counterSetUid.
has_value() ? counterSetUid.
value() : 0;
370 if (counterSetUidValue > 0)
376 boost::str(boost::format(
"Trying to connect a counter to a counter set that is " 377 "not registered (counter set UID: %1%)")
378 % counterSetUidValue));
383 uint16_t deviceUidValue = deviceUid.
has_value() ? deviceUid.
value() : 0;
384 uint16_t deviceCores = GetNumberOfCores(numberOfCores, deviceUidValue, parentCategory);
388 BOOST_ASSERT(!counterUids.empty());
389 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
392 const std::string unitsValue = units.
has_value() ? units.
value() :
"";
395 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
406 BOOST_ASSERT(counter);
409 const Counter* counterPtr = counter.get();
410 BOOST_ASSERT(counterPtr);
413 for (uint16_t counterUid : counterUids)
416 parentCategory->m_Counters.push_back(counterUid);
419 m_Counters.insert(std::make_pair(counterUid, counter));
427 auto it = FindCategory(categoryName);
428 if (it == m_Categories.end())
433 const Category* category = it->get();
434 BOOST_ASSERT(category);
441 auto it = FindDevice(deviceUid);
442 if (it == m_Devices.end())
447 const Device* device = it->second.get();
448 BOOST_ASSERT(device);
449 BOOST_ASSERT(device->
m_Uid == deviceUid);
456 auto it = FindCounterSet(counterSetUid);
457 if (it == m_CounterSets.end())
462 const CounterSet* counterSet = it->second.get();
463 BOOST_ASSERT(counterSet);
464 BOOST_ASSERT(counterSet->
m_Uid == counterSetUid);
471 auto it = FindCounter(counterUid);
472 if (it == m_Counters.end())
477 const Counter* counter = it->second.get();
478 BOOST_ASSERT(counter);
479 BOOST_ASSERT(counter->
m_Uid <= counterUid);
487 auto it = FindCategory(categoryName);
489 return it != m_Categories.end();
494 auto it = FindDevice(deviceUid);
496 return it != m_Devices.end();
501 auto it = FindDevice(deviceName);
503 return it != m_Devices.end();
508 auto it = FindCounterSet(counterSetUid);
510 return it != m_CounterSets.end();
515 auto it = FindCounterSet(counterSetName);
517 return it != m_CounterSets.end();
522 auto it = FindCounter(counterUid);
524 return it != m_Counters.end();
529 auto it = FindCounter(counterName);
531 return it != m_Counters.end();
537 m_Categories.clear();
539 m_CounterSets.clear();
543 CategoriesIt CounterDirectory::FindCategory(
const std::string& categoryName)
const 545 return std::find_if(m_Categories.begin(), m_Categories.end(), [&categoryName](
const CategoryPtr& category)
547 BOOST_ASSERT(category);
549 return category->m_Name == categoryName;
553 DevicesIt CounterDirectory::FindDevice(uint16_t deviceUid)
const 555 return m_Devices.find(deviceUid);
558 DevicesIt CounterDirectory::FindDevice(
const std::string& deviceName)
const 560 return std::find_if(m_Devices.begin(), m_Devices.end(), [&deviceName](
const auto& pair)
562 BOOST_ASSERT(pair.second);
563 BOOST_ASSERT(pair.second->m_Uid == pair.first);
565 return pair.second->m_Name == deviceName;
569 CounterSetsIt CounterDirectory::FindCounterSet(uint16_t counterSetUid)
const 571 return m_CounterSets.find(counterSetUid);
574 CounterSetsIt CounterDirectory::FindCounterSet(
const std::string& counterSetName)
const 576 return std::find_if(m_CounterSets.begin(), m_CounterSets.end(), [&counterSetName](
const auto& pair)
578 BOOST_ASSERT(pair.second);
579 BOOST_ASSERT(pair.second->m_Uid == pair.first);
581 return pair.second->m_Name == counterSetName;
585 CountersIt CounterDirectory::FindCounter(uint16_t counterUid)
const 587 return m_Counters.find(counterUid);
590 CountersIt CounterDirectory::FindCounter(
const std::string& counterName)
const 592 return std::find_if(m_Counters.begin(), m_Counters.end(), [&counterName](
const auto& pair)
594 BOOST_ASSERT(pair.second);
595 BOOST_ASSERT(pair.second->m_Uid == pair.first);
597 return pair.second->m_Name == counterName;
605 BOOST_ASSERT(parentCategory);
620 return numberOfCores.
value();
628 auto deviceIt = FindDevice(deviceUid);
629 if (deviceIt == m_Devices.end())
632 boost::str(boost::format(
"Trying to connect a counter to a device that is " 633 "not registered (device UID %1%)")
638 const DevicePtr& device = deviceIt->second;
639 BOOST_ASSERT(device);
642 return device->m_Cores;
647 uint16_t parentCategoryDeviceUid = parentCategory->m_DeviceUid;
648 if (parentCategoryDeviceUid > 0)
651 auto deviceIt = FindDevice(parentCategoryDeviceUid);
652 if (deviceIt == m_Devices.end())
655 boost::str(boost::format(
"Trying to get the number of cores from a device that is " 656 "not registered (device UID %1%)")
657 % parentCategoryDeviceUid));
661 const DevicePtr& device = deviceIt->second;
662 BOOST_ASSERT(device);
665 return device->m_Cores;
Counters::const_iterator CountersIt
std::unique_ptr< CounterSet > CounterSetPtr
const CounterSet * GetCounterSet(uint16_t uid) const override
uint16_t GetNextUid(bool peekOnly)
const Device * GetDevice(uint16_t uid) const override
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
bool IsCategoryRegistered(const std::string &categoryName) const
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
bool IsCounterSetRegistered(uint16_t counterSetUid) const
const Counter * GetCounter(uint16_t uid) const 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
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)
bool IsDeviceRegistered(uint16_t deviceUid) const
std::shared_ptr< Counter > CounterPtr
CounterSets::const_iterator CounterSetsIt
std::unique_ptr< Category > CategoryPtr
std::unique_ptr< Device > DevicePtr
Devices::const_iterator DevicesIt
Categories::const_iterator CategoriesIt
const Category * GetCategory(const std::string &name) const override
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
bool IsCounterRegistered(uint16_t counterUid) const
bool has_value() const noexcept