ATLAS Offline Software
Loading...
Searching...
No Matches
MemoryMonitorSvc.h
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4#ifndef ATHDEVICECOMPS_MEMORYMONITORSVC_H
5#define ATHDEVICECOMPS_MEMORYMONITORSVC_H
6
7// Framework include(s).
9
10// AthDevice include(s).
12
13// System include(s).
14#include <map>
15#include <mutex>
16
17namespace AthDevice {
18
20class MemoryMonitorSvc : public extends<AthService, IMemoryMonitorSvc> {
21
22 public:
23 // Inherit the base class's constructor(s).
24 using extends::extends;
25
28
30 virtual StatusCode finalize() override;
31
33
35
38
40 virtual void memoryAllocated(const std::string& component,
41 const std::string& device,
42 std::size_t bytes) override;
43
45 virtual void memoryDeallocated(const std::string& component,
46 const std::string& device,
47 std::size_t bytes) override;
48
50 virtual void memoryCopied(const std::string& component,
51 vecmem::copy::type::copy_type type,
52 std::size_t bytes) override;
53
55
56 private:
59
63 std::string component;
65 std::string device;
66
68 bool operator<(const MemoryAllocKey& other) const {
69 if (device != other.device) {
70 return device < other.device;
71 } else {
72 return component < other.component;
73 }
74 }
75 };
76
78 std::map<MemoryAllocKey, std::size_t> m_allocations;
82 std::map<MemoryAllocKey, std::size_t> m_deallocations;
85
89 std::string component;
91 vecmem::copy::type::copy_type type;
92
94 bool operator<(const MemoryCopyKey& other) const {
95 if (component != other.component) {
96 return component < other.component;
97 } else {
98 return type < other.type;
99 }
100 }
101 };
102
104 std::map<MemoryCopyKey, std::size_t> m_copies;
106 std::mutex m_copiesMutex;
107
109
110}; // class MemoryMonitorSvc
111
112} // namespace AthDevice
113
114#endif // ATHDEVICECOMPS_MEMORYMONITORSVC_H
Service providing "device memory monitoring".
virtual void memoryDeallocated(const std::string &component, const std::string &device, std::size_t bytes) override
Notify the service that a memory deallocation has been made.
std::map< MemoryCopyKey, std::size_t > m_copies
All the memory copies.
virtual void memoryCopied(const std::string &component, vecmem::copy::type::copy_type type, std::size_t bytes) override
Notify the service that a memory copy has been made.
std::map< MemoryAllocKey, std::size_t > m_deallocations
All the memory deallocations.
virtual StatusCode finalize() override
Finalize the service.
std::mutex m_deallocationsMutex
Mutex for m_deallocations.
std::mutex m_copiesMutex
Mutex for m_copies.
std::mutex m_allocationsMutex
Mutex for m_allocations.
std::map< MemoryAllocKey, std::size_t > m_allocations
All the memory allocations.
virtual void memoryAllocated(const std::string &component, const std::string &device, std::size_t bytes) override
Notify the service that a memory allocation has been made.
Key used in the memory allocation/deallocation monitoring maps.
std::string component
Athena component making the memory (de)allocation.
bool operator<(const MemoryAllocKey &other) const
Comparison operator, to make the type usable as a key in a map.
std::string device
Name/identifier of the device on which the (de)allocation was made.
Key used in the memory copy monitoring map.
vecmem::copy::type::copy_type type
Type of the memory copy.
std::string component
Athena component making the memory copy.
bool operator<(const MemoryCopyKey &other) const
Comparison operator, to make the type usable as a key in a map.