CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
profiler
LifetimeProfiled.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#ifndef LIBCARLA_ENABLE_LIFETIME_PROFILER
8
# define LIBCARLA_ENABLE_LIFETIME_PROFILER
9
#endif
// LIBCARLA_ENABLE_LIFETIME_PROFILER
10
11
#include "
carla/Debug.h
"
12
#include "
carla/Logging.h
"
13
#include "
carla/profiler/LifetimeProfiled.h
"
14
15
#include <mutex>
16
#include <unordered_map>
17
18
namespace
carla
{
19
namespace
profiler
{
20
21
template
<
typename
... Args>
22
static
inline
void
log
(Args && ... args) {
23
logging::write_to_stream(std::cerr,
"LIFETIME:"
, std::forward<Args>(args) ...,
'\n'
);
24
}
25
26
class
LifetimeProfiler
{
27
public
:
28
29
~LifetimeProfiler
() {
30
std::scoped_lock<std::mutex> lock(
_mutex
);
31
if
(!
_objects
.empty()) {
32
log
(
"WARNING! the following objects were not destructed."
);
33
for
(
const
auto
&item :
_objects
) {
34
log
(item.second,
"still alive."
);
35
}
36
DEBUG_ERROR
;
37
}
38
}
39
40
void
Register
(
void
*
object
, std::string display_name) {
41
#if LIBCARLA_LOG_LEVEL <= LIBCARLA_LOG_LEVEL_DEBUG
42
log
(
'+'
, display_name);
43
#endif
44
std::scoped_lock<std::mutex> lock(
_mutex
);
45
_objects
.emplace(
object
, std::move(display_name));
46
}
47
48
void
Deregister
(
void
*
object
) {
49
std::scoped_lock<std::mutex> lock(
_mutex
);
50
auto
it =
_objects
.find(
object
);
51
DEBUG_ASSERT
(it !=
_objects
.end());
52
#if LIBCARLA_LOG_LEVEL <= LIBCARLA_LOG_LEVEL_DEBUG
53
log
(
'-'
, it->second);
54
#endif
55
_objects
.erase(it);
56
}
57
58
private
:
59
60
std::mutex
_mutex
;
61
62
std::unordered_map<void *, std::string>
_objects
;
63
};
64
65
static
LifetimeProfiler
PROFILER
;
66
67
LifetimeProfiled::LifetimeProfiled
(std::string display_name) {
68
PROFILER
.
Register
(
this
, std::move(display_name));
69
}
70
71
LifetimeProfiled::~LifetimeProfiled() {
72
PROFILER
.
Deregister
(
this
);
73
}
74
75
}
// namespace profiler
76
}
// namespace carla
Debug.h
DEBUG_ASSERT
#define DEBUG_ASSERT(predicate)
Definition
Debug.h:66
DEBUG_ERROR
#define DEBUG_ERROR
Definition
Debug.h:68
LifetimeProfiled.h
Logging.h
carla::profiler::LifetimeProfiled::LifetimeProfiled
LifetimeProfiled()=default
Definition
LifetimeProfiled.cpp:67
carla::profiler::LifetimeProfiler
Definition
LifetimeProfiled.cpp:26
carla::profiler::LifetimeProfiler::_objects
std::unordered_map< void *, std::string > _objects
Definition
LifetimeProfiled.cpp:62
carla::profiler::LifetimeProfiler::~LifetimeProfiler
~LifetimeProfiler()
Definition
LifetimeProfiled.cpp:29
carla::profiler::LifetimeProfiler::Deregister
void Deregister(void *object)
Definition
LifetimeProfiled.cpp:48
carla::profiler::LifetimeProfiler::Register
void Register(void *object, std::string display_name)
Definition
LifetimeProfiled.cpp:40
carla::profiler::LifetimeProfiler::_mutex
std::mutex _mutex
Definition
LifetimeProfiled.cpp:60
carla::profiler
Definition
LifetimeProfiled.cpp:19
carla::profiler::log
static void log(Args &&... args)
Definition
LifetimeProfiled.cpp:22
carla::profiler::PROFILER
static LifetimeProfiler PROFILER
Definition
LifetimeProfiled.cpp:65
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0