15#include "arccore/common/accelerator/internal/MemoryTracer.h"
17#include "arccore/base/PlatformUtils.h"
19#include "arccore/base/String.h"
21#include "arccore/common/AllocatedMemoryInfo.h"
22#include "arccore/common/IMemoryAllocator.h"
29namespace Arcane::Accelerator::Impl
45 const void* ptr = bytes.data();
46 m_infos_map.insert(std::make_pair(ptr,
Info{ bytes.size(), name, stack_trace }));
49 void remove(
void* ptr, [[maybe_unused]]
const String& name, [[maybe_unused]]
const String& stack_trace, [[maybe_unused]]
Int64 timestamp)
51 auto x = m_infos_map.find(ptr);
52 if (x != m_infos_map.end())
56 std::pair<String, String> find(
const void* ptr)
58 auto x = m_infos_map.lower_bound(ptr);
59 if (x != m_infos_map.end())
60 return std::make_pair(x->second.name, x->second.stack);
66 std::map<const void*, Info> m_infos_map;
78notifyMemoryAllocation(Span<const std::byte> bytes,
const String& name,
79 const String& stack_trace,
Int64 timestamp)
82 m_memory_tracer_mng.add(bytes, name, stack_trace, timestamp);
86notifyMemoryFree(
void* ptr,
const String& name,
const String& stack_trace,
Int64 timestamp)
89 m_memory_tracer_mng.remove(ptr, name, stack_trace, timestamp);
95std::pair<String, String> MemoryTracer::
96findMemory(
const void* ptr)
98 return m_memory_tracer_mng.find(ptr);
112void MemoryTracerWrapper::
113traceDeallocate(
const AllocatedMemoryInfo& mem_info,
const MemoryAllocationArgs& args)
118 void* ptr = mem_info.baseAddress();
121 std::ostringstream ostr;
122 if (m_trace_level >= 2)
123 ostr <<
"FREE_MANAGED=" << ptr <<
" size=" << mem_info.capacity() <<
" name=" << args.arrayName();
125 if (m_trace_level >= 3) {
127 if (m_trace_level >= 4) {
128 ostr <<
" stack=" << s;
131 MemoryTracer::notifyMemoryFree(ptr, args.arrayName(), s, 0);
132 if (m_trace_level >= 2) {
134 std::cout << ostr.str();
141void MemoryTracerWrapper::
142traceAllocate(
void* p,
size_t new_size, MemoryAllocationArgs args)
149 std::ostringstream ostr;
150 if (m_trace_level >= 2)
151 ostr <<
"MALLOC_MANAGED=" << p <<
" size=" << new_size <<
" name=" << args.arrayName();
153 if (m_trace_level >= 3) {
155 if (m_trace_level >= 4) {
156 ostr <<
" stack=" << s;
159 Span<const std::byte> bytes(
reinterpret_cast<std::byte*
>(p), new_size);
160 MemoryTracer::notifyMemoryAllocation(bytes, args.arrayName(), s, 0);
161 if (m_trace_level >= 2) {
163 std::cout << ostr.str();
Types and functions associated with the classes ArrayView and ConstArrayView.
View of an array of elements of type T.
Unicode character string.
std::int64_t Int64
Signed integer type of 64 bits.