Open3D (C++ API)
0.19.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cpp
open3d
core
MemoryManagerStatistic.h
Go to the documentation of this file.
1
// ----------------------------------------------------------------------------
2
// - Open3D: www.open3d.org -
3
// ----------------------------------------------------------------------------
4
// Copyright (c) 2018-2024 www.open3d.org
5
// SPDX-License-Identifier: MIT
6
// ----------------------------------------------------------------------------
7
8
#pragma once
9
10
#include <cstddef>
11
#include <map>
12
#include <mutex>
13
#include <unordered_map>
14
15
#include "
open3d/core/Device.h
"
16
17
namespace
open3d
{
18
namespace
core
{
19
20
class
MemoryManagerStatistic
{
21
public
:
22
enum class
PrintLevel
{
24
All
= 0,
27
Unbalanced
= 1,
29
None
= 2,
30
};
31
32
static
MemoryManagerStatistic
&
GetInstance
();
33
34
MemoryManagerStatistic
(
const
MemoryManagerStatistic
&) =
delete
;
35
MemoryManagerStatistic
&
operator=
(
MemoryManagerStatistic
&) =
delete
;
36
37
~MemoryManagerStatistic
();
38
40
void
SetPrintLevel
(
PrintLevel
level);
41
45
void
SetPrintAtProgramEnd
(
bool
print);
46
48
void
SetPrintAtMallocFree
(
bool
print);
49
51
void
Print
()
const
;
52
55
bool
HasLeaks
()
const
;
56
58
void
CountMalloc
(
void
* ptr,
size_t
byte_size,
const
Device
& device);
59
63
void
CountFree
(
void
* ptr,
const
Device
& device);
64
66
void
Reset
();
67
68
private
:
69
MemoryManagerStatistic
() =
default
;
70
71
struct
MemoryStatistics {
72
bool
IsBalanced()
const
;
73
74
int64_t count_malloc_ = 0;
75
int64_t count_free_ = 0;
76
std::unordered_map<void*, size_t> active_allocations_;
77
};
78
80
PrintLevel
level_ =
PrintLevel::Unbalanced
;
81
84
bool
print_at_program_end_ =
true
;
85
87
bool
print_at_malloc_free_ =
false
;
88
89
std::mutex statistics_mutex_;
90
std::map<Device, MemoryStatistics> statistics_;
91
};
92
93
}
// namespace core
94
}
// namespace open3d
Device.h
open3d::core::Device
Definition
Device.h:18
open3d::core::MemoryManagerStatistic
Definition
MemoryManagerStatistic.h:20
open3d::core::MemoryManagerStatistic::CountFree
void CountFree(void *ptr, const Device &device)
Definition
MemoryManagerStatistic.cpp:143
open3d::core::MemoryManagerStatistic::GetInstance
static MemoryManagerStatistic & GetInstance()
Definition
MemoryManagerStatistic.cpp:19
open3d::core::MemoryManagerStatistic::HasLeaks
bool HasLeaks() const
Definition
MemoryManagerStatistic.cpp:111
open3d::core::MemoryManagerStatistic::~MemoryManagerStatistic
~MemoryManagerStatistic()
Definition
MemoryManagerStatistic.cpp:30
open3d::core::MemoryManagerStatistic::SetPrintAtProgramEnd
void SetPrintAtProgramEnd(bool print)
Definition
MemoryManagerStatistic.cpp:48
open3d::core::MemoryManagerStatistic::Print
void Print() const
Prints statistics for all recorded devices depending on the print level.
Definition
MemoryManagerStatistic.cpp:56
open3d::core::MemoryManagerStatistic::operator=
MemoryManagerStatistic & operator=(MemoryManagerStatistic &)=delete
open3d::core::MemoryManagerStatistic::Reset
void Reset()
Resets the statistics.
Definition
MemoryManagerStatistic.cpp:172
open3d::core::MemoryManagerStatistic::SetPrintLevel
void SetPrintLevel(PrintLevel level)
Sets the level of provided information for printing.
Definition
MemoryManagerStatistic.cpp:46
open3d::core::MemoryManagerStatistic::PrintLevel
PrintLevel
Definition
MemoryManagerStatistic.h:22
open3d::core::MemoryManagerStatistic::PrintLevel::Unbalanced
@ Unbalanced
Definition
MemoryManagerStatistic.h:27
open3d::core::MemoryManagerStatistic::PrintLevel::All
@ All
Statistics for all used devices are printed.
Definition
MemoryManagerStatistic.h:24
open3d::core::MemoryManagerStatistic::SetPrintAtMallocFree
void SetPrintAtMallocFree(bool print)
Enables or disables printing at each malloc and free.
Definition
MemoryManagerStatistic.cpp:52
open3d::core::MemoryManagerStatistic::CountMalloc
void CountMalloc(void *ptr, size_t byte_size, const Device &device)
Adds the given allocation to the statistics.
Definition
MemoryManagerStatistic.cpp:118
open3d::core::MemoryManagerStatistic::MemoryManagerStatistic
MemoryManagerStatistic(const MemoryManagerStatistic &)=delete
open3d::core
Definition
AdvancedIndexing.cpp:15
open3d::core::None
constexpr utility::nullopt_t None
Definition
TensorKey.h:20
open3d
Definition
PinholeCameraIntrinsic.cpp:16
Generated by
1.17.0