ATLAS Offline Software
Loading...
Searching...
No Matches
AthDevice::MemoryMonitorSvc Class Reference

Service providing "device memory monitoring". More...

#include <MemoryMonitorSvc.h>

Inheritance diagram for AthDevice::MemoryMonitorSvc:
Collaboration diagram for AthDevice::MemoryMonitorSvc:

Classes

struct  MemoryAllocKey
 Key used in the memory allocation/deallocation monitoring maps. More...
struct  MemoryCopyKey
 Key used in the memory copy monitoring map. More...

Public Member Functions

Function(s) inherited from @c AthService
virtual StatusCode finalize () override
 Finalize the service.
Function(s) inherited from @c IMemoryMonitorSvc
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.
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.
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.

Private Attributes

Objects collecting the monitoring data
std::map< MemoryAllocKey, std::size_t > m_allocations
 All the memory allocations.
std::mutex m_allocationsMutex
 Mutex for m_allocations.
std::map< MemoryAllocKey, std::size_t > m_deallocations
 All the memory deallocations.
std::mutex m_deallocationsMutex
 Mutex for m_deallocations.
std::map< MemoryCopyKey, std::size_t > m_copies
 All the memory copies.
std::mutex m_copiesMutex
 Mutex for m_copies.

Detailed Description

Service providing "device memory monitoring".

Definition at line 20 of file MemoryMonitorSvc.h.

Member Function Documentation

◆ finalize()

StatusCode AthDevice::MemoryMonitorSvc::finalize ( )
overridevirtual

Finalize the service.

Definition at line 35 of file MemoryMonitorSvc.cxx.

35 {
36
37 // Find the longest component name, to make the output more readable.
38 std::size_t longestComponentName = 0u;
39 auto helper = [&longestComponentName](const auto& map) {
40 for (const auto& [key, bytes] : map) {
41 longestComponentName =
42 std::max(longestComponentName, key.component.size());
43 }
44 };
47
48 // Print the memory allocation monitoring data.
49 ATH_MSG_INFO("Memory allocations:");
50 std::string currentDevice = "";
51 for (const auto& [key, bytes] : m_allocations) {
52 if (key.device != currentDevice) {
53 ATH_MSG_INFO(" - " << key.device);
54 currentDevice = key.device;
55 }
56 ATH_MSG_INFO(" * " << std::setw(longestComponentName) << std::left
57 << key.component << " : " << std::setw(15)
58 << std::right << formatBytes(bytes));
59 }
60
61 // Print the memory deallocation monitoring data.
62 ATH_MSG_INFO("Memory deallocations:");
63 currentDevice = "";
64 for (const auto& [key, bytes] : m_deallocations) {
65 if (key.device != currentDevice) {
66 ATH_MSG_INFO(" - " << key.device);
67 currentDevice = key.device;
68 }
69 ATH_MSG_INFO(" * " << std::setw(longestComponentName) << std::left
70 << key.component << " : " << std::setw(15)
71 << std::right << formatBytes(bytes));
72 }
73
74 // TODO: Print the memory copy monitoring data.
75
76 // Return gracefully.
77 return StatusCode::SUCCESS;
78}
#define ATH_MSG_INFO(x,...)
std::map< MemoryAllocKey, std::size_t > m_deallocations
All the memory deallocations.
std::map< MemoryAllocKey, std::size_t > m_allocations
All the memory allocations.
@ u
Enums for curvilinear frames.
Definition ParamDefs.h:77

◆ memoryAllocated()

void AthDevice::MemoryMonitorSvc::memoryAllocated ( const std::string & component,
const std::string & device,
std::size_t bytes )
overridevirtual

Notify the service that a memory allocation has been made.

Definition at line 80 of file MemoryMonitorSvc.cxx.

82 {
83
84 std::lock_guard lock(m_allocationsMutex);
85 m_allocations[{component, device}] += bytes;
86}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
std::mutex m_allocationsMutex
Mutex for m_allocations.

◆ memoryCopied()

void AthDevice::MemoryMonitorSvc::memoryCopied ( const std::string & component,
vecmem::copy::type::copy_type type,
std::size_t bytes )
overridevirtual

Notify the service that a memory copy has been made.

Definition at line 96 of file MemoryMonitorSvc.cxx.

98 {
99
100 std::lock_guard lock(m_copiesMutex);
101 m_copies[{component, type}] += bytes;
102}
std::map< MemoryCopyKey, std::size_t > m_copies
All the memory copies.
std::mutex m_copiesMutex
Mutex for m_copies.

◆ memoryDeallocated()

void AthDevice::MemoryMonitorSvc::memoryDeallocated ( const std::string & component,
const std::string & device,
std::size_t bytes )
overridevirtual

Notify the service that a memory deallocation has been made.

Definition at line 88 of file MemoryMonitorSvc.cxx.

90 {
91
92 std::lock_guard lock(m_deallocationsMutex);
93 m_deallocations[{component, device}] += bytes;
94}
std::mutex m_deallocationsMutex
Mutex for m_deallocations.

Member Data Documentation

◆ m_allocations

std::map<MemoryAllocKey, std::size_t> AthDevice::MemoryMonitorSvc::m_allocations
private

All the memory allocations.

Definition at line 78 of file MemoryMonitorSvc.h.

◆ m_allocationsMutex

std::mutex AthDevice::MemoryMonitorSvc::m_allocationsMutex
private

Mutex for m_allocations.

Definition at line 80 of file MemoryMonitorSvc.h.

◆ m_copies

std::map<MemoryCopyKey, std::size_t> AthDevice::MemoryMonitorSvc::m_copies
private

All the memory copies.

Definition at line 104 of file MemoryMonitorSvc.h.

◆ m_copiesMutex

std::mutex AthDevice::MemoryMonitorSvc::m_copiesMutex
private

Mutex for m_copies.

Definition at line 106 of file MemoryMonitorSvc.h.

◆ m_deallocations

std::map<MemoryAllocKey, std::size_t> AthDevice::MemoryMonitorSvc::m_deallocations
private

All the memory deallocations.

Definition at line 82 of file MemoryMonitorSvc.h.

◆ m_deallocationsMutex

std::mutex AthDevice::MemoryMonitorSvc::m_deallocationsMutex
private

Mutex for m_deallocations.

Definition at line 84 of file MemoryMonitorSvc.h.


The documentation for this class was generated from the following files: