CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
profiler
Profiler.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_PROFILER
8
# define LIBCARLA_ENABLE_PROFILER
9
#endif
// LIBCARLA_ENABLE_PROFILER
10
11
#include "
carla/Logging.h
"
12
#include "carla/Version.h"
13
#include "
carla/profiler/Profiler.h
"
14
15
#include <fstream>
16
#include <iomanip>
17
#include <iostream>
18
#include <mutex>
19
20
namespace
carla
{
21
namespace
profiler {
22
namespace
detail
{
23
24
template
<
typename
Arg,
typename
... Args>
25
static
void
write_csv_to_stream
(std::ostream &out, Arg &&arg, Args &&... args) {
26
out << std::boolalpha
27
<< std::left << std::setw(44)
28
<< std::forward<Arg>(arg)
29
<< std::right
30
<< std::fixed << std::setprecision(2);
31
using
expander =
int
[];
32
(void)expander{0, (void(out <<
", "
<< std::setw(10) << std::forward<Args>(args)),0)...};
33
}
34
35
class
StaticProfiler
{
36
public
:
37
38
StaticProfiler
(std::string filename)
39
:
_filename
(
std
::move(filename)) {
40
logging::log(
"PROFILER: writing profiling data to"
,
_filename
);
41
std::string header =
"# LibCarla Profiler "
;
42
header += carla::version();
43
#ifdef NDEBUG
44
header +=
" (release)"
;
45
#else
46
header +=
" (debug)"
;
47
#endif
// NDEBUG
48
write_to_file
(std::ios_base::out, header);
49
write_line
(
"# context"
,
"average"
,
"maximum"
,
"minimum"
,
"units"
,
"times"
);
50
}
51
52
template
<
typename
... Args>
53
void
write_line
(Args &&... args) {
54
write_to_file
(std::ios_base::app|std::ios_base::out, std::forward<Args>(args)...);
55
}
56
57
private
:
58
59
template
<
typename
... Args>
60
void
write_to_file
(std::ios_base::openmode mode, Args &&... args) {
61
if
(!
_filename
.empty()) {
62
static
std::mutex MUTEX;
63
std::scoped_lock<std::mutex> guard(MUTEX);
64
std::ofstream file(
_filename
, mode);
65
write_csv_to_stream
(file, std::forward<Args>(args)...);
66
file << std::endl;
67
}
68
}
69
70
const
std::string
_filename
;
71
};
72
73
ProfilerData::~ProfilerData() {
74
static
StaticProfiler
PROFILER{
"profiler.csv"
};
75
if
(_count > 0u) {
76
if
(_print_fps) {
77
PROFILER
.
write_line
(_name, fps(average()), fps(minimum()), fps(maximum()),
"FPS"
, _count);
78
}
else
{
79
PROFILER.
write_line
(_name, average(), maximum(), minimum(),
"ms"
, _count);
80
}
81
}
else
{
82
log_error(
"profiler"
, _name,
" was never run!"
);
83
}
84
}
85
86
}
// namespace detail
87
}
// namespace profiler
88
}
// namespace carla
Logging.h
Profiler.h
carla::profiler::detail::StaticProfiler
Definition
Profiler.cpp:35
carla::profiler::detail::StaticProfiler::write_to_file
void write_to_file(std::ios_base::openmode mode, Args &&... args)
Definition
Profiler.cpp:60
carla::profiler::detail::StaticProfiler::write_line
void write_line(Args &&... args)
Definition
Profiler.cpp:53
carla::profiler::detail::StaticProfiler::StaticProfiler
StaticProfiler(std::string filename)
Definition
Profiler.cpp:38
carla::profiler::detail::StaticProfiler::_filename
const std::string _filename
Definition
Profiler.cpp:70
carla::profiler::detail
Definition
Profiler.cpp:22
carla::profiler::detail::write_csv_to_stream
static void write_csv_to_stream(std::ostream &out, Arg &&arg, Args &&... args)
Definition
Profiler.cpp:25
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
std
Definition
CarlaRecorderCollision.h:31
Generated by
1.18.0