Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
IMemoryInfo.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* IMemoryInfo.h (C) 2000-2018 */
9/* */
10/* Interface for a memory usage information collector. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_IMEMORYINFO_H
13#define ARCANE_UTILS_IMEMORYINFO_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/utils/IFunctorWithArgument.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29/*!
30 * \brief Information about an allocated chunk.
31 */
32class MemoryInfoChunk
33{
34 public:
35
36 MemoryInfoChunk()
37 : m_owner(0)
38 , m_size(0)
39 , m_alloc_id(0)
40 , m_iteration(0)
41 {}
42 MemoryInfoChunk(const void* aowner, Int64 asize, Int64 alloc_id, Integer aiteration)
43 : m_owner(aowner)
44 , m_size(asize)
45 , m_alloc_id(alloc_id)
46 , m_iteration(aiteration)
47 {}
48
49 public:
50
51 const void* owner() const { return m_owner; }
52 Int64 size() const { return m_size; }
53 Int64 allocId() const { return m_alloc_id; }
54 Integer iteration() const { return m_iteration; }
55 const String& stackTrace() const { return m_stack_trace; }
56
57 public:
58
59 void setOwner(const void* o) { m_owner = o; }
60 void setStackTrace(const String& st) { m_stack_trace = st; }
61
62 private:
63
64 const void* m_owner;
65 Int64 m_size;
66 Int64 m_alloc_id;
67 Integer m_iteration;
68 String m_stack_trace;
69};
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74/*!
75 * \internal
76 * \brief Interface for a memory usage information collector.
77 */
78class IMemoryInfo
79{
80 protected:
81
82 IMemoryInfo() {}
83
84 public:
85
86 //! Releases resources
87 virtual ~IMemoryInfo() {}
88
89 public:
90
91 //! Creates a reference on \a owner with the trace info \a trace_info
92 virtual void createOwner(const void* owner, const TraceInfo& trace_info) = 0;
93
94 //! Modifies the info of the reference \a owner
95 virtual void setOwner(const void* owner, const TraceInfo& new_info) = 0;
96
97 //! Removes the reference on \a owner
98 virtual void removeOwner(const void* owner) = 0;
99
100 public:
101
102 virtual void addInfo(const void* owner, const void* ptr, Int64 size) = 0;
103
104 virtual void addInfo(const void* owner, const void* ptr, Int64 size, const void* old_ptr) = 0;
105
106 virtual void changeOwner(const void* new_owner, const void* ptr) = 0;
107
108 virtual void removeInfo(const void* owner, const void* ptr, bool can_fail = false) = 0;
109
110 virtual void printInfos(std::ostream& ostr) = 0;
111
112 public:
113
114 virtual void beginCollect() = 0;
115 virtual void endCollect() = 0;
116 virtual bool isCollecting() const = 0;
117
118 public:
119
120 //! Sets the current iteration number.
121 virtual void setIteration(Integer iteration) = 0;
122
123 virtual void printAllocatedMemory(std::ostream& ostr, Integer iteration) = 0;
124
125 //! Sets the ITraceMng for messages.
126 virtual void setTraceMng(ITraceMng* msg) = 0;
127
128 /*!
129 * \brief Indicates whether call stack saving is active.
130 *
131 * If \a is_active is true, it activates tracing the call stack of allocations.
132 * Tracing is conditional on the value of stackTraceMinAllocSize().
133 */
134 virtual void setKeepStackTrace(bool is_active) = 0;
135
136 //! Indicates if call stack saving is enabled.
137 virtual bool keepStackTrace() const = 0;
138
139 /*!
140 * \brief Sets the minimum size of allocations whose call stack is traced.
141 *
142 * For all allocations above \a alloc_size,
143 * the call stack is preserved in order to identify memory leaks. The memory and CPU cost of preserving
144 * a call stack is significant, and it is therefore not recommended to set a value too low (below 1000) for \a alloc_size.
145 * Call stack preservation is disabled if \a keepStackTrace() equals \a false.
146 */
147 virtual void setStackTraceMinAllocSize(Int64 alloc_size) = 0;
148
149 //! Minimum size of allocations whose call stack is traced.
150 virtual Int64 stackTraceMinAllocSize() const = 0;
151
152 //! Visitor over all allocated blocks
154
155 virtual Int64 nbAllocation() const = 0;
156};
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161extern "C++" ARCANE_UTILS_EXPORT IMemoryInfo*
162arcaneGlobalMemoryInfo();
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167} // namespace Arcane
168
169/*---------------------------------------------------------------------------*/
170/*---------------------------------------------------------------------------*/
171
172#endif
Interface of a functor with an argument but without a return value.
virtual void setIteration(Integer iteration)=0
Sets the current iteration number.
virtual void setStackTraceMinAllocSize(Int64 alloc_size)=0
Sets the minimum size of allocations whose call stack is traced.
virtual void removeOwner(const void *owner)=0
Removes the reference on owner.
virtual void createOwner(const void *owner, const TraceInfo &trace_info)=0
Creates a reference on owner with the trace info trace_info.
virtual void setTraceMng(ITraceMng *msg)=0
Sets the ITraceMng for messages.
virtual void visitAllocatedBlocks(IFunctorWithArgumentT< const MemoryInfoChunk & > *functor) const =0
Visitor over all allocated blocks.
virtual void setOwner(const void *owner, const TraceInfo &new_info)=0
Modifies the info of the reference owner.
virtual ~IMemoryInfo()
Releases resources.
Definition IMemoryInfo.h:87
virtual Int64 stackTraceMinAllocSize() const =0
Minimum size of allocations whose call stack is traced.
virtual void setKeepStackTrace(bool is_active)=0
Indicates whether call stack saving is active.
virtual bool keepStackTrace() const =0
Indicates if call stack saving is enabled.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.