Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MemoryInfo.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/* MemoryInfo.h (C) 2000-2015 */
9/* */
10/* Memory usage information collector. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_MEMORYINFO_H
13#define ARCANE_UTILS_MEMORYINFO_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/IMemoryInfo.h"
18#include "arcane/utils/TraceInfo.h"
19
20#include <map>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
35class ARCANE_UTILS_EXPORT MemoryInfo
36: public IMemoryInfo
37{
38 public:
39
40 class MemoryInfoSorter;
41 class TracePrinter;
42
43 public:
44
45 MemoryInfo();
46 virtual ~MemoryInfo();
47
48 public:
49
50 virtual void createOwner(const void* owner, const TraceInfo& trace_info);
51
52 virtual void setOwner(const void* owner, const TraceInfo& new_info);
53
54 virtual void removeOwner(const void* owner);
55
56 public:
57
58 virtual void addInfo(const void* owner, const void* ptr, Int64 size);
59
60 virtual void addInfo(const void* owner, const void* ptr, Int64 size, const void* old_ptr);
61
62 virtual void removeInfo(const void* owner, const void* ptr, bool can_fail);
63
64 virtual void changeOwner(const void* new_owner, const void* ptr);
65
66 virtual void printInfos(std::ostream& ostr);
67
68 virtual void setIteration(Integer iteration)
69 {
70 m_iteration = iteration;
71 }
72 virtual void printAllocatedMemory(std::ostream& ostr, Integer iteration);
73 virtual void setTraceMng(ITraceMng* trace);
74
75 public:
76
77 virtual void beginCollect();
78 virtual void endCollect();
79 virtual bool isCollecting() const;
80
81 public:
82
83 virtual void setKeepStackTrace(bool is_active) { m_is_stack_trace_active = is_active; }
84 virtual bool keepStackTrace() const { return m_is_stack_trace_active; }
85
86 virtual void setStackTraceMinAllocSize(Int64 alloc_size) { m_info_big_alloc = alloc_size; }
87 virtual Int64 stackTraceMinAllocSize() const { return m_info_big_alloc; }
88
89 virtual void visitAllocatedBlocks(IFunctorWithArgumentT<const MemoryInfoChunk&>* functor) const;
90
91 virtual Int64 nbAllocation() const { return m_alloc_id; }
92
93 public:
94
95 void checkMemory(const void* owner, Int64 size);
96
97 private:
98
99 typedef std::map<const void*, MemoryInfoChunk> MemoryInfoMap;
100 typedef std::map<const void*, TraceInfo> MemoryTraceInfoMap;
101
102 MemoryInfoMap m_infos;
103 MemoryTraceInfoMap m_owner_infos;
104
105 Int64 m_alloc_id;
106 Int64 m_max_allocated;
107 Int64 m_current_allocated;
108 Int64 m_biggest_allocated;
109 Int64 m_info_big_alloc;
110 Int64 m_info_biggest_minimal;
111 Int64 m_info_peak_minimal;
112 Integer m_iteration;
113 ITraceMng* m_trace;
114 bool m_display_max_alloc;
115 bool m_in_display;
116 bool m_is_first_collect;
117 bool m_is_stack_trace_active;
118
119 private:
120
121 void _removeOwner(const void* owner);
122 void _addMemory(const void* owner, Int64 size, const String& stack_value);
123 void _removeMemory(const void* owner, Int64 size);
124 TraceInfo* _getTraceInfo(const void* owner);
125 void _printInfos(std::ostream& ostr);
126};
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131extern "C++" ARCANE_UTILS_EXPORT MemoryInfo*
132arcaneGlobalTrueMemoryInfo();
133extern "C++" ARCANE_UTILS_EXPORT void
134arcaneInitCheckMemory();
135extern "C++" ARCANE_UTILS_EXPORT void
136arcaneExitCheckMemory();
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
141} // namespace Arcane
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146#endif
Interface of a functor with an argument but without a return value.
Memory usage information collector.
Definition MemoryInfo.h:37
virtual Int64 stackTraceMinAllocSize() const
Minimum size of allocations whose call stack is traced.
Definition MemoryInfo.h:87
virtual bool keepStackTrace() const
Indicates if call stack saving is enabled.
Definition MemoryInfo.h:84
virtual void createOwner(const void *owner, const TraceInfo &trace_info)
Creates a reference on owner with the trace info trace_info.
virtual void setStackTraceMinAllocSize(Int64 alloc_size)
Sets the minimum size of allocations whose call stack is traced.
Definition MemoryInfo.h:86
virtual void setOwner(const void *owner, const TraceInfo &new_info)
Modifies the info of the reference owner.
virtual void setIteration(Integer iteration)
Sets the current iteration number.
Definition MemoryInfo.h:68
virtual void removeOwner(const void *owner)
Removes the reference on owner.
virtual void setKeepStackTrace(bool is_active)
Indicates whether call stack saving is active.
Definition MemoryInfo.h:83
-- 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.