vecmem 1.18.0
Loading...
Searching...
No Matches
instrumenting_memory_resource.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021-2025 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8
9#pragma once
10
11// Local include(s).
12#include "vecmem/memory/details/memory_resource_base.hpp"
13#include "vecmem/memory/memory_resource.hpp"
14#include "vecmem/vecmem_core_export.hpp"
15
16// System include(s).
17#include <cstddef>
18#include <functional>
19#include <memory>
20#include <vector>
21
22namespace vecmem {
23
24// Forward declaration(s).
25namespace details {
26class instrumenting_memory_resource_impl;
27}
28
39
40public:
47 memory_resource& upstream);
51 instrumenting_memory_resource&& parent) noexcept;
54 delete;
55
59
66 const instrumenting_memory_resource&) = delete;
67
72
76 enum class type { ALLOCATION, DEALLOCATION };
77
87 memory_event(type t, std::size_t s, std::size_t a, void* p,
88 std::size_t ns);
89
92
94 std::size_t m_size;
96 std::size_t m_align;
97
99 void* m_ptr;
100
102 std::size_t m_time;
103
104 }; // struct memory_event
105
111 const std::vector<memory_event>& get_events(void) const;
112
123 void add_pre_allocate_hook(std::function<void(std::size_t, std::size_t)> f);
124
138 std::function<void(std::size_t, std::size_t, void*)> f);
139
152 std::function<void(void*, std::size_t, std::size_t)> f);
153
154private:
157
160 void* do_allocate(std::size_t, std::size_t) override;
163 void do_deallocate(void* p, std::size_t, std::size_t) override;
164
166
168 std::unique_ptr<details::instrumenting_memory_resource_impl> m_impl;
169
170}; // class instrumenting_memory_resource
171
172} // namespace vecmem
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
Base class for implementations of the vecmem::memory_resource interface.
Definition memory_resource_base.hpp:25
This memory resource forwards allocation and deallocation requests to the upstream resource while rec...
Definition instrumenting_memory_resource.hpp:38
VECMEM_CORE_EXPORT instrumenting_memory_resource & operator=(instrumenting_memory_resource &&rhs) noexcept
Move assignment operator.
VECMEM_CORE_EXPORT void add_post_allocate_hook(std::function< void(std::size_t, std::size_t, void *)> f)
Add a post-allocation hook.
Definition instrumenting_memory_resource.cpp:40
VECMEM_CORE_EXPORT void do_deallocate(void *p, std::size_t, std::size_t) override
De-allocate a previously allocated memory block.
instrumenting_memory_resource(const instrumenting_memory_resource &)=delete
Disallow copying the memory resource.
VECMEM_CORE_EXPORT void add_pre_deallocate_hook(std::function< void(void *, std::size_t, std::size_t)> f)
Add a pre-deallocation hook.
Definition instrumenting_memory_resource.cpp:46
VECMEM_CORE_EXPORT instrumenting_memory_resource(instrumenting_memory_resource &&parent) noexcept
Move constructor.
VECMEM_CORE_EXPORT const std::vector< memory_event > & get_events(void) const
Return a list of memory allocation and deallocation events in chronological order.
Definition instrumenting_memory_resource.cpp:29
instrumenting_memory_resource & operator=(const instrumenting_memory_resource &)=delete
Disallow copying the memory resource.
VECMEM_CORE_EXPORT void * do_allocate(std::size_t, std::size_t) override
Allocate memory with one of the underlying resources.
VECMEM_CORE_EXPORT void add_pre_allocate_hook(std::function< void(std::size_t, std::size_t)> f)
Add a pre-allocation hook.
Definition instrumenting_memory_resource.cpp:34
VECMEM_CORE_EXPORT ~instrumenting_memory_resource() override
Destructor.
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
Structure describing a memory resource event.
Definition instrumenting_memory_resource.hpp:71
std::size_t m_align
The alignment of the request.
Definition instrumenting_memory_resource.hpp:96
std::size_t m_size
The size of the request.
Definition instrumenting_memory_resource.hpp:94
void * m_ptr
The pointer that was returned or deallocated.
Definition instrumenting_memory_resource.hpp:99
std::size_t m_time
The time taken to perform the request in nanoseconds.
Definition instrumenting_memory_resource.hpp:102
type m_type
The type of event (allocation or deallocation).
Definition instrumenting_memory_resource.hpp:91
type
Classify an event as an alloction or a deallocation.
Definition instrumenting_memory_resource.hpp:76