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"
30namespace Arcane::Accelerator::Impl
46 const void* ptr = bytes.data();
47 m_infos_map.insert(std::make_pair(ptr,
Info{ bytes.size(), name, stack_trace }));
50 void remove(
void* ptr, [[maybe_unused]]
const String& name, [[maybe_unused]]
const String& stack_trace, [[maybe_unused]]
Int64 timestamp)
52 auto x = m_infos_map.find(ptr);
53 if (x != m_infos_map.end())
57 std::pair<String, String> find(
const void* ptr)
59 auto x = m_infos_map.lower_bound(ptr);
60 if (x != m_infos_map.end())
61 return std::make_pair(x->second.name, x->second.stack);
67 std::map<const void*, Info> m_infos_map;
79notifyMemoryAllocation(Span<const std::byte> bytes,
const String& name,
80 const String& stack_trace,
Int64 timestamp)
83 m_memory_tracer_mng.add(bytes, name, stack_trace, timestamp);
87notifyMemoryFree(
void* ptr,
const String& name,
const String& stack_trace,
Int64 timestamp)
90 m_memory_tracer_mng.remove(ptr, name, stack_trace, timestamp);
96std::pair<String, String> MemoryTracer::
97findMemory(
const void* ptr)
99 return m_memory_tracer_mng.find(ptr);
113void MemoryTracerWrapper::
114traceDeallocate(
const AllocatedMemoryInfo& mem_info,
const MemoryAllocationArgs& args)
119 void* ptr = mem_info.baseAddress();
122 std::ostringstream ostr;
123 if (m_trace_level >= 2)
124 ostr <<
"FREE_MANAGED=" << ptr <<
" size=" << mem_info.capacity() <<
" name=" << args.arrayName();
126 if (m_trace_level >= 3) {
128 if (m_trace_level >= 4) {
129 ostr <<
" stack=" << s;
132 MemoryTracer::notifyMemoryFree(ptr, args.arrayName(), s, 0);
133 if (m_trace_level >= 2) {
135 std::cout << ostr.str();
142void MemoryTracerWrapper::
143traceAllocate(
void* p,
size_t new_size, MemoryAllocationArgs args)
150 std::ostringstream ostr;
151 if (m_trace_level >= 2)
152 ostr <<
"MALLOC_MANAGED=" << p <<
" size=" << new_size <<
" name=" << args.arrayName();
154 if (m_trace_level >= 3) {
156 if (m_trace_level >= 4) {
157 ostr <<
" stack=" << s;
160 Span<const std::byte> bytes(
reinterpret_cast<std::byte*
>(p), new_size);
161 MemoryTracer::notifyMemoryAllocation(bytes, args.arrayName(), s, 0);
162 if (m_trace_level >= 2) {
164 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.