13 #include <common/include/SwTrace.hpp> 15 #include <boost/format.hpp> 26 if (categoryName.empty() ||
27 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(categoryName))
36 boost::str(boost::format(
"Trying to register a category already registered (\"%1%\")")
41 CategoryPtr category = std::make_unique<Category>(categoryName);
45 const Category* categoryPtr = category.get();
49 m_Categories.insert(std::move(category));
59 if (deviceName.empty() ||
60 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(deviceName))
69 boost::str(boost::format(
"Trying to register a device already registered (\"%1%\")")
77 const std::string& parentCategoryNameValue = parentCategoryName.
value();
78 if (parentCategoryNameValue.empty())
81 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to an invalid " 82 "parent category (name: \"%2%\")")
84 % parentCategoryNameValue));
88 auto categoryIt = FindCategory(parentCategoryNameValue);
89 if (categoryIt == m_Categories.end())
92 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to a parent category that " 93 "is not registered (name: \"%2%\")")
95 % parentCategoryNameValue));
103 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
107 const Device* devicePtr = device.get();
111 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
121 if (counterSetName.empty() ||
122 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(counterSetName))
131 boost::str(boost::format(
"Trying to register a counter set already registered (\"%1%\")")
137 uint16_t counterSetUidPeek =
GetNextUid(
true);
143 const std::string& parentCategoryNameValue = parentCategoryName.
value();
144 if (parentCategoryNameValue.empty())
147 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to an invalid " 148 "parent category (name: \"%2%\")")
150 % parentCategoryNameValue));
154 auto it = FindCategory(parentCategoryNameValue);
155 if (it == m_Categories.end())
158 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to a parent category " 159 "that is not registered (name: \"%2%\")")
161 % parentCategoryNameValue));
170 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
174 const CounterSet* counterSetPtr = counterSet.get();
178 m_CounterSets.insert(std::make_pair(counterSetUid, std::move(counterSet)));
180 return counterSetPtr;
185 const std::string& parentCategoryName,
186 uint16_t counterClass,
187 uint16_t interpolation,
189 const std::string& name,
190 const std::string& description,
199 if (parentCategoryName.empty() ||
200 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(parentCategoryName))
206 if (counterClass != 0 && counterClass != 1)
212 if (interpolation != 0 && interpolation != 1)
218 if (multiplier == .0f)
225 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(name))
231 if (description.empty() ||
232 !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceCharPolicy>(description))
239 && !arm::pipe::IsValidSwTraceString<arm::pipe::SwTraceNameCharPolicy>(units.
value()))
245 auto categoryIt = FindCategory(parentCategoryName);
246 if (categoryIt == m_Categories.end())
249 boost::str(boost::format(
"Trying to connect a counter to a category " 250 "that is not registered (name: \"%1%\")")
251 % parentCategoryName));
259 const std::vector<uint16_t>& parentCategoryCounters = parentCategory->m_Counters;
260 for (uint16_t parentCategoryCounterUid : parentCategoryCounters)
265 if (parentCategoryCounter->
m_Name == name)
268 boost::str(boost::format(
"Trying to register a counter to category \"%1%\" with a name that " 269 "is already used within that category (name: \"%2%\")")
276 uint16_t counterSetUidValue = counterSetUid.
has_value() ? counterSetUid.
value() : 0;
277 if (counterSetUidValue > 0)
283 boost::str(boost::format(
"Trying to connect a counter to a counter set that is " 284 "not registered (counter set UID: %1%)")
285 % counterSetUidValue));
290 uint16_t deviceUidValue = deviceUid.
has_value() ? deviceUid.
value() : 0;
291 uint16_t deviceCores = GetNumberOfCores(numberOfCores, deviceUidValue);
296 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
299 const std::string unitsValue = units.
has_value() ? units.
value() :
"";
302 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
316 const Counter* counterPtr = counter.get();
320 for (uint16_t counterUid : counterUids)
323 parentCategory->m_Counters.push_back(counterUid);
326 m_Counters.insert(std::make_pair(counterUid, counter));
334 auto it = FindCategory(categoryName);
335 if (it == m_Categories.end())
340 const Category* category = it->get();
348 auto it = FindDevice(deviceUid);
349 if (it == m_Devices.end())
354 const Device* device = it->second.get();
363 auto it = FindCounterSet(counterSetUid);
364 if (it == m_CounterSets.end())
369 const CounterSet* counterSet = it->second.get();
378 auto it = FindCounter(counterUid);
379 if (it == m_Counters.end())
384 const Counter* counter = it->second.get();
394 auto it = FindCategory(categoryName);
396 return it != m_Categories.end();
401 auto it = FindDevice(deviceUid);
403 return it != m_Devices.end();
408 auto it = FindDevice(deviceName);
410 return it != m_Devices.end();
415 auto it = FindCounterSet(counterSetUid);
417 return it != m_CounterSets.end();
422 auto it = FindCounterSet(counterSetName);
424 return it != m_CounterSets.end();
429 auto it = FindCounter(counterUid);
431 return it != m_Counters.end();
436 auto it = FindCounter(counterName);
438 return it != m_Counters.end();
444 m_Categories.clear();
446 m_CounterSets.clear();
450 CategoriesIt CounterDirectory::FindCategory(
const std::string& categoryName)
const 452 return std::find_if(m_Categories.begin(), m_Categories.end(), [&categoryName](
const CategoryPtr& category)
456 return category->m_Name == categoryName;
460 DevicesIt CounterDirectory::FindDevice(uint16_t deviceUid)
const 462 return m_Devices.find(deviceUid);
465 DevicesIt CounterDirectory::FindDevice(
const std::string& deviceName)
const 467 return std::find_if(m_Devices.begin(), m_Devices.end(), [&deviceName](
const auto& pair)
472 return pair.second->m_Name == deviceName;
476 CounterSetsIt CounterDirectory::FindCounterSet(uint16_t counterSetUid)
const 478 return m_CounterSets.find(counterSetUid);
481 CounterSetsIt CounterDirectory::FindCounterSet(
const std::string& counterSetName)
const 483 return std::find_if(m_CounterSets.begin(), m_CounterSets.end(), [&counterSetName](
const auto& pair)
488 return pair.second->m_Name == counterSetName;
492 CountersIt CounterDirectory::FindCounter(uint16_t counterUid)
const 494 return m_Counters.find(counterUid);
497 CountersIt CounterDirectory::FindCounter(
const std::string& counterName)
const 499 return std::find_if(m_Counters.begin(), m_Counters.end(), [&counterName](
const auto& pair)
502 ARMNN_ASSERT(pair.first >= pair.second->m_Uid && pair.first <= pair.second->m_MaxCounterUid);
504 return pair.second->m_Name == counterName;
522 return numberOfCores.
value();
530 auto deviceIt = FindDevice(deviceUid);
531 if (deviceIt == m_Devices.end())
534 boost::str(boost::format(
"Trying to connect a counter to a device that is " 535 "not registered (device UID %1%)")
540 const DevicePtr& device = deviceIt->second;
544 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