13 #include <boost/format.hpp> 24 if (categoryName.empty() ||
25 !IsValidSwTraceString<SwTraceNameCharPolicy>(categoryName))
34 boost::str(boost::format(
"Trying to register a category already registered (\"%1%\")")
39 CategoryPtr category = std::make_unique<Category>(categoryName);
40 BOOST_ASSERT(category);
43 const Category* categoryPtr = category.get();
44 BOOST_ASSERT(categoryPtr);
47 m_Categories.insert(std::move(category));
57 if (deviceName.empty() ||
58 !IsValidSwTraceString<SwTraceCharPolicy>(deviceName))
67 boost::str(boost::format(
"Trying to register a device already registered (\"%1%\")")
75 const std::string& parentCategoryNameValue = parentCategoryName.
value();
76 if (parentCategoryNameValue.empty())
79 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to an invalid " 80 "parent category (name: \"%2%\")")
82 % parentCategoryNameValue));
86 auto categoryIt = FindCategory(parentCategoryNameValue);
87 if (categoryIt == m_Categories.end())
90 boost::str(boost::format(
"Trying to connect a device (name: \"%1%\") to a parent category that " 91 "is not registered (name: \"%2%\")")
93 % parentCategoryNameValue));
101 DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, cores);
102 BOOST_ASSERT(device);
105 const Device* devicePtr = device.get();
106 BOOST_ASSERT(devicePtr);
109 m_Devices.insert(std::make_pair(deviceUid, std::move(device)));
119 if (counterSetName.empty() ||
120 !IsValidSwTraceString<SwTraceNameCharPolicy>(counterSetName))
129 boost::str(boost::format(
"Trying to register a counter set already registered (\"%1%\")")
135 uint16_t counterSetUidPeek =
GetNextUid(
true);
141 const std::string& parentCategoryNameValue = parentCategoryName.
value();
142 if (parentCategoryNameValue.empty())
145 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to an invalid " 146 "parent category (name: \"%2%\")")
148 % parentCategoryNameValue));
152 auto it = FindCategory(parentCategoryNameValue);
153 if (it == m_Categories.end())
156 boost::str(boost::format(
"Trying to connect a counter set (UID: %1%) to a parent category " 157 "that is not registered (name: \"%2%\")")
159 % parentCategoryNameValue));
165 BOOST_ASSERT(counterSetUid == counterSetUidPeek);
168 CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, count);
169 BOOST_ASSERT(counterSet);
172 const CounterSet* counterSetPtr = counterSet.get();
173 BOOST_ASSERT(counterSetPtr);
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 !IsValidSwTraceString<SwTraceNameCharPolicy>(parentCategoryName))
204 if (counterClass != 0 && counterClass != 1)
210 if (interpolation != 0 && interpolation != 1)
216 if (multiplier == .0f)
223 !IsValidSwTraceString<SwTraceCharPolicy>(name))
229 if (description.empty() ||
230 !IsValidSwTraceString<SwTraceCharPolicy>(description))
237 && !IsValidSwTraceString<SwTraceNameCharPolicy>(units.
value()))
243 auto categoryIt = FindCategory(parentCategoryName);
244 if (categoryIt == m_Categories.end())
247 boost::str(boost::format(
"Trying to connect a counter to a category " 248 "that is not registered (name: \"%1%\")")
249 % parentCategoryName));
254 BOOST_ASSERT(parentCategory);
257 const std::vector<uint16_t>& parentCategoryCounters = parentCategory->m_Counters;
258 for (uint16_t parentCategoryCounterUid : parentCategoryCounters)
261 BOOST_ASSERT(parentCategoryCounter);
263 if (parentCategoryCounter->
m_Name == name)
266 boost::str(boost::format(
"Trying to register a counter to category \"%1%\" with a name that " 267 "is already used within that category (name: \"%2%\")")
274 uint16_t counterSetUidValue = counterSetUid.
has_value() ? counterSetUid.
value() : 0;
275 if (counterSetUidValue > 0)
281 boost::str(boost::format(
"Trying to connect a counter to a counter set that is " 282 "not registered (counter set UID: %1%)")
283 % counterSetUidValue));
288 uint16_t deviceUidValue = deviceUid.
has_value() ? deviceUid.
value() : 0;
289 uint16_t deviceCores = GetNumberOfCores(numberOfCores, deviceUidValue);
293 BOOST_ASSERT(!counterUids.empty());
294 uint16_t maxCounterUid = deviceCores <= 1 ? counterUids.front() : counterUids.back();
297 const std::string unitsValue = units.
has_value() ? units.
value() :
"";
300 CounterPtr counter = std::make_shared<Counter>(armnn::profiling::BACKEND_ID,
311 BOOST_ASSERT(counter);
314 const Counter* counterPtr = counter.get();
315 BOOST_ASSERT(counterPtr);
318 for (uint16_t counterUid : counterUids)
321 parentCategory->m_Counters.push_back(counterUid);
324 m_Counters.insert(std::make_pair(counterUid, counter));
332 auto it = FindCategory(categoryName);
333 if (it == m_Categories.end())
338 const Category* category = it->get();
339 BOOST_ASSERT(category);
346 auto it = FindDevice(deviceUid);
347 if (it == m_Devices.end())
352 const Device* device = it->second.get();
353 BOOST_ASSERT(device);
354 BOOST_ASSERT(device->
m_Uid == deviceUid);
361 auto it = FindCounterSet(counterSetUid);
362 if (it == m_CounterSets.end())
367 const CounterSet* counterSet = it->second.get();
368 BOOST_ASSERT(counterSet);
369 BOOST_ASSERT(counterSet->
m_Uid == counterSetUid);
376 auto it = FindCounter(counterUid);
377 if (it == m_Counters.end())
382 const Counter* counter = it->second.get();
383 BOOST_ASSERT(counter);
384 BOOST_ASSERT(counter->
m_Uid <= counterUid);
392 auto it = FindCategory(categoryName);
394 return it != m_Categories.end();
399 auto it = FindDevice(deviceUid);
401 return it != m_Devices.end();
406 auto it = FindDevice(deviceName);
408 return it != m_Devices.end();
413 auto it = FindCounterSet(counterSetUid);
415 return it != m_CounterSets.end();
420 auto it = FindCounterSet(counterSetName);
422 return it != m_CounterSets.end();
427 auto it = FindCounter(counterUid);
429 return it != m_Counters.end();
434 auto it = FindCounter(counterName);
436 return it != m_Counters.end();
442 m_Categories.clear();
444 m_CounterSets.clear();
448 CategoriesIt CounterDirectory::FindCategory(
const std::string& categoryName)
const 450 return std::find_if(m_Categories.begin(), m_Categories.end(), [&categoryName](
const CategoryPtr& category)
452 BOOST_ASSERT(category);
454 return category->m_Name == categoryName;
458 DevicesIt CounterDirectory::FindDevice(uint16_t deviceUid)
const 460 return m_Devices.find(deviceUid);
463 DevicesIt CounterDirectory::FindDevice(
const std::string& deviceName)
const 465 return std::find_if(m_Devices.begin(), m_Devices.end(), [&deviceName](
const auto& pair)
467 BOOST_ASSERT(pair.second);
468 BOOST_ASSERT(pair.second->m_Uid == pair.first);
470 return pair.second->m_Name == deviceName;
474 CounterSetsIt CounterDirectory::FindCounterSet(uint16_t counterSetUid)
const 476 return m_CounterSets.find(counterSetUid);
479 CounterSetsIt CounterDirectory::FindCounterSet(
const std::string& counterSetName)
const 481 return std::find_if(m_CounterSets.begin(), m_CounterSets.end(), [&counterSetName](
const auto& pair)
483 BOOST_ASSERT(pair.second);
484 BOOST_ASSERT(pair.second->m_Uid == pair.first);
486 return pair.second->m_Name == counterSetName;
490 CountersIt CounterDirectory::FindCounter(uint16_t counterUid)
const 492 return m_Counters.find(counterUid);
495 CountersIt CounterDirectory::FindCounter(
const std::string& counterName)
const 497 return std::find_if(m_Counters.begin(), m_Counters.end(), [&counterName](
const auto& pair)
499 BOOST_ASSERT(pair.second);
500 BOOST_ASSERT(pair.second->m_Uid == pair.first);
502 return pair.second->m_Name == counterName;
520 return numberOfCores.
value();
528 auto deviceIt = FindDevice(deviceUid);
529 if (deviceIt == m_Devices.end())
532 boost::str(boost::format(
"Trying to connect a counter to a device that is " 533 "not registered (device UID %1%)")
538 const DevicePtr& device = deviceIt->second;
539 BOOST_ASSERT(device);
542 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)
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