16base_class(name, pSvcLocator),
45 ATH_MSG_WARNING(
"numConcurrentEvents() == 0. This is a misconfiguration, probably coming from running from pickle. "
46 "Setting local m_eventSlots to a 'large' number until this is fixed to allow the job to proceed.");
60 return StatusCode::SUCCESS;
69 ATH_MSG_INFO(
"Calling hashes2file, saving dump of job's HLT hashing dictionary to disk.");
71 return StatusCode::SUCCESS;
84 std::unique_lock lockUnique(
m_slotMutex[ context.slot() ] );
99 return StatusCode::SUCCESS;
112 std::shared_lock lockShared(
m_slotMutex[ context.slot() ] );
120 << (
type == AuditType::Before ?
"BEGAN" :
"ENDED") <<
" at " << now.microsecondsSinceEpoch());
134 return StatusCode::SUCCESS;
141 if (
type == AuditType::Before) {
145 std::this_thread::get_id(),
147 static_cast<uint32_t
>(context.slot())
153 tbb::concurrent_hash_map<std::thread::id, AlgorithmIdentifier, ThreadHashCompare>::accessor acc;
158 }
else if (
type == AuditType::After) {
164 ATH_MSG_ERROR(
"Only expecting AuditType::Before or AuditType::After");
165 return StatusCode::FAILURE;
169 return StatusCode::SUCCESS;
179 return StatusCode::SUCCESS;
194 std::unique_lock lockUnique(
m_slotMutex[ context.slot() ] );
199 uint64_t eventStopTime = 0;
203 tbb::concurrent_hash_map<AlgorithmIdentifier, TrigTimeStamp, AlgorithmIdentifierHashCompare>::const_accessor stopTimeAcessor;
208 eventStopTime = stopTimeAcessor->second.microsecondsSinceEpoch();
213 uint64_t eventStartTime = 0;
217 tbb::concurrent_hash_map<AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_accessor startAcessor;
222 eventStartTime = startAcessor->second.m_algStartTime.microsecondsSinceEpoch();
227 tbb::concurrent_hash_map< AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_iterator beginIt;
228 tbb::concurrent_hash_map< AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_iterator endIt;
229 tbb::concurrent_hash_map< AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_iterator it;
232 ATH_MSG_DEBUG(
"Monitored event with " << std::distance(beginIt, endIt) <<
" AlgorithmPayload objects.");
234 std::map<size_t, size_t> aiToHandleIndex;
235 for (it = beginIt; it != endIt; ++it) {
238 uint64_t startTime = ap.m_algStartTime.microsecondsSinceEpoch();
241 uint64_t stopTime = eventStopTime;
243 tbb::concurrent_hash_map<AlgorithmIdentifier, TrigTimeStamp, AlgorithmIdentifierHashCompare>::const_accessor stopTimeAcessor;
247 stopTime = stopTimeAcessor->second.microsecondsSinceEpoch();
255 if (startTime > stopTime) {
256 ATH_MSG_VERBOSE(
"Disregard start-time:" << startTime <<
" > stop-time:" << stopTime
266 if (startTime > eventStopTime) {
270 if (stopTime > eventStopTime) {
272 <<
" truncating its ending time stamp from " << stopTime <<
" to " << eventStopTime);
273 stopTime = eventStopTime;
279 if (stopTime < eventStartTime) {
283 if (startTime < eventStartTime) {
285 <<
" truncating its starting time stamp from " << startTime <<
" to " << eventStartTime);
286 startTime = eventStartTime;
291 costOutputHandle->push_back(
tc );
294 const uint32_t threadID =
static_cast<uint32_t
>( std::hash< std::thread::id >()(ap.m_algThreadID) );
295 uint32_t threadEnumerator = 0;
299 const std::unordered_map<uint32_t, uint32_t>::const_iterator mapIt =
m_threadToCounterMap.find(threadID);
304 threadEnumerator = mapIt->second;
312 result &=
tc->setDetail(
"thread", threadEnumerator);
313 result &=
tc->setDetail(
"thash", threadID);
314 result &=
tc->setDetail(
"slot", ap.m_slot);
315 result &=
tc->setDetail(
"roi", ap.m_algROIID);
316 result &=
tc->setDetail(
"start", startTime);
317 result &=
tc->setDetail(
"stop", stopTime);
318 if (!result)
ATH_MSG_WARNING(
"Failed to append one or more details to trigger cost TC");
320 aiToHandleIndex[ai.
m_hash] = costOutputHandle->size() - 1;
323 if (
msg().level() <= MSG::VERBOSE) {
338 return StatusCode::SUCCESS;
349 return StatusCode::SUCCESS;
352 std::unique_lock lockUnique(
m_slotMutex[context.slot()]);
354 tbb::concurrent_hash_map< AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_iterator beginIt;
355 tbb::concurrent_hash_map< AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_iterator endIt;
356 tbb::concurrent_hash_map< AlgorithmIdentifier, AlgorithmPayload, AlgorithmIdentifierHashCompare>::const_iterator it;
360 std::map<uint64_t, std::string, std::greater<uint64_t>> timeToAlgMap;
362 for (it = beginIt; it != endIt; ++it) {
367 if (ai.
m_realSlot != context.slot())
continue;
369 uint64_t startTime = ap.m_algStartTime.microsecondsSinceEpoch();
370 uint64_t stopTime = 0;
372 tbb::concurrent_hash_map<AlgorithmIdentifier, TrigTimeStamp, AlgorithmIdentifierHashCompare>::const_accessor stopTimeAcessor;
377 stopTime = stopTimeAcessor->second.microsecondsSinceEpoch();
382 if (stopTime == 0)
continue;
384 timeToAlgMap[stopTime-startTime] = ai.
m_caller;
388 report =
"Timeout detected with the following algorithms consuming the most time: ";
390 for(
const std::pair<const uint64_t, std::string>& p : timeToAlgMap){
392 report += p.second +
" (" + std::to_string(std::lround(p.first/1e3)) +
" ms)";
394 if (algCounter >= 5){
400 return StatusCode::SUCCESS;
408 ATH_MSG_DEBUG(
"All events are monitored - event will not be discarded");
409 return StatusCode::SUCCESS;
415 std::unique_lock lockUnique(
m_slotMutex[ context.slot() ] );
422 return StatusCode::SUCCESS;
430 return StatusCode::FAILURE;
432 return StatusCode::SUCCESS;
440 if (roi)
return static_cast<int32_t
>(roi->
roiId());
460 return static_cast<size_t>( std::hash< std::thread::id >()(thread) );
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
Maintain a set of objects, one per slot.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
const IRoiDescriptor * roiDescriptor() const
Get cached pointer to View's Region of Interest Descriptor or nullptr if not describing a View.
Describes the API of the Region of Ineterest geometry.
virtual unsigned int roiId() const =0
identifiers
static void hashes2file(const std::string &fileName="hashes2string.txt")
debugging output of internal dictionary
static const std::string hash2string(HLTHash, const std::string &category=s_defaultCategory)
hash function translating identifiers into names (via internal dictionary)
virtual StatusCode processAlg(const EventContext &context, const std::string &caller, const AuditType type) override
Implementation of ITrigCostSvc::processAlg.
Gaudi::Property< bool > m_monitorAllEvents
Gaudi::Property< bool > m_saveHashes
Gaudi::Property< std::string > m_costFinalizeAlgName
std::mutex m_globalMutex
Used to protect all-slot modifications.
TrigCostDataStore< AlgorithmPayload > m_algStartInfo
Thread-safe store of algorithm start payload.
StatusCode checkSlot(const EventContext &context) const
Sanity check that the job is respecting the number of slots which were declared at config time.
TrigCostDataStore< TrigTimeStamp > m_algStopTime
Thread-safe store of algorithm stop times.
Gaudi::Property< bool > m_enableMultiSlot
virtual StatusCode initialize() override
Initialise, create enough storage to store m_eventSlots.
size_t m_eventSlots
Number of concurrent processing slots.
virtual ~TrigCostSvc()
Destructor.
std::unique_ptr< std::shared_mutex[] > m_slotMutex
Used to control and protect whole-table operations.
virtual bool isMonitoredEvent(const EventContext &context, const bool includeMultiSlot=true) const override
std::unique_ptr< std::atomic< bool >[] > m_eventMonitored
Used to cache if the event in a given slot is being monitored.
int32_t getROIID(const EventContext &context)
@breif Internal function to return a RoI from an extended event context context
virtual StatusCode discardEvent(const EventContext &context) override
Discard a cost monitored event.
Gaudi::Property< std::string > m_costSupervisorAlgName
TrigCostSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard ATLAS Service constructor.
Gaudi::Property< size_t > m_masterSlot
virtual StatusCode finalize() override
Finalize, act on m_saveHashes.
virtual StatusCode generateTimeoutReport(const EventContext &context, std::string &report) override
StatusCode monitor(const EventContext &context, const AlgorithmIdentifier &ai, const TrigTimeStamp &now, const AuditType type)
Internal call to save monitoring data for a given AlgorithmIdentifier.
size_t m_threadCounter
Count how many unique thread ID we have seen.
tbb::concurrent_hash_map< std::thread::id, AlgorithmIdentifier, ThreadHashCompare > m_threadToAlgMap
Keeps track of what is running right now in each thread.
virtual StatusCode endEvent(const EventContext &context, SG::WriteHandle< xAOD::TrigCompositeContainer > &costOutputHandle) override
Implementation of ITrigCostSvc::endEvent.
std::unordered_map< uint32_t, uint32_t > m_threadToCounterMap
Map thread's hash ID to a counting numeral.
virtual StatusCode startEvent(const EventContext &context, const bool enableMonitoring=true) override
Implementation of ITrigCostSvc::startEvent.
utility class to measure time duration in AthenaMT The pattern when it is useful: AlgA tags the begin...
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
size_t getNSlots()
Return the number of event slots.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
static AlgorithmIdentifier make(const EventContext &context, const std::string &caller, MsgStream &msg, const int16_t slotOverride=-1)
Construct an AlgorithmIdentifier.
Small structure to hold an algorithm's name and store, plus some details on its EventView.
std::string m_caller
Name of the algorithm.
std::string m_store
Name of the algorithm's store.
TrigConf::HLTHash callerHash(MsgStream &msg) const
size_t m_slotToSaveInto
The slot which is used for the purposes of recording data on this algorithm's execution.
static constexpr int16_t s_noView
Constant value used to express an Algorithm which is not running in a View.
TrigConf::HLTHash storeHash(MsgStream &msg) const
size_t m_realSlot
The actual slot of the algorithm.
size_t m_hash
Hash of algorithm + store + realSlot.
StatusCode isValid() const
int16_t m_viewID
If not within an event view, then the m_iewID = s_noView = -1.
Small structure wrap the various values stored for an algorithm just before it starts to execute.
static bool equal(const std::thread::id &x, const std::thread::id &y)
static size_t hash(const std::thread::id &thread)