Sen API
Sen Libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
tracer.h
Go to the documentation of this file.
1
// === tracer.h ========================================================================================================
2
// Sen Infrastructure
3
// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4
// See the LICENSE.txt file for more information.
5
// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6
// =====================================================================================================================
7
8
#ifndef SEN_KERNEL_TRACER_H
9
#define SEN_KERNEL_TRACER_H
10
11
// sen
12
#include "
sen/core/base/compiler_macros.h
"
13
#include "
sen/core/base/numbers.h
"
14
#include "
sen/core/base/scope_guard.h
"
15
#include "
sen/core/base/source_location.h
"
16
17
// std
18
#include <functional>
19
#include <memory>
20
#include <string_view>
21
22
namespace
sen::kernel
23
{
24
27
class
Tracer
28
{
29
SEN_NOCOPY_NOMOVE(
Tracer
)
30
31
public
:
32
Tracer
() =
default
;
33
virtual
~Tracer
() =
default
;
34
35
public
:
// for scoped (RAII) zones
58
[[nodiscard]]
auto
makeScopedZone
(
const
SourceLocation
& location);
59
81
[[nodiscard]]
auto
makeScopedZone
(std::string_view name,
const
SourceLocation
& location);
82
83
public
:
// for frame-based tracers
88
virtual
void
frameStart
(std::string_view name) = 0;
89
94
virtual
void
frameEnd
(std::string_view name) = 0;
95
96
public
:
// messages
99
virtual
void
message
(std::string_view name) = 0;
100
105
virtual
void
plot
(std::string_view name,
float64_t
value) = 0;
106
111
virtual
void
plot
(std::string_view name, int64_t value) = 0;
112
113
protected
:
114
virtual
void
zoneStart
(std::string_view name,
const
SourceLocation
& location) = 0;
115
virtual
void
zoneEnd
() = 0;
116
};
117
119
using
TracerFactory
= std::function<std::unique_ptr<Tracer>(std::string_view)>;
120
122
[[nodiscard]]
TracerFactory
getDefaultTracerFactory
();
123
124
// clang-format off
136
#define SEN_TRACE_ZONE_NAMED(tracer, name) static constexpr auto __senSourceLocation ## __LINE__ = SEN_SL(); auto __senScopedZone ## __LINE__ = (tracer).makeScopedZone(name, __senSourceLocation ## __LINE__)
137
149
#define SEN_TRACE_ZONE(tracer) static constexpr auto __senSourceLocation ## __LINE__ = SEN_SL(); auto __senScopedZone ## __LINE__ = (tracer).makeScopedZone(__senSourceLocation ## __LINE__)
150
// clang-format on
151
152
//--------------------------------------------------------------------------------------------------------------
153
// Inline method implementation
154
//--------------------------------------------------------------------------------------------------------------
155
156
inline
auto
Tracer::makeScopedZone
(std::string_view name,
const
SourceLocation
& location)
157
{
158
zoneStart
(std::move(name), location);
159
return
makeScopeGuard
([
this
]() {
zoneEnd
(); });
160
}
161
162
inline
auto
Tracer::makeScopedZone
(
const
SourceLocation
& location) {
return
makeScopedZone
({}, location); }
163
164
}
// namespace sen::kernel
165
166
#endif
// SEN_KERNEL_TRACER_H
sen::kernel::Tracer::frameEnd
virtual void frameEnd(std::string_view name)=0
Marks the end of a (named) frame. Needs to be paired with a corresponding call to frameStart.
sen::kernel::Tracer::frameStart
virtual void frameStart(std::string_view name)=0
Marks the start of a (named) frame. Needs to be paired with a corresponding call to frameEnd.
sen::kernel::Tracer::message
virtual void message(std::string_view name)=0
Sends a message that will be traced.
sen::kernel::Tracer::Tracer
Tracer()=default
sen::kernel::Tracer::makeScopedZone
auto makeScopedZone(const SourceLocation &location)
Create a scoped zone. You can use scoped zones to trace the lifetime of a given block (the typical ex...
Definition
tracer.h:162
sen::kernel::Tracer::~Tracer
virtual ~Tracer()=default
sen::kernel::Tracer::zoneStart
virtual void zoneStart(std::string_view name, const SourceLocation &location)=0
sen::kernel::Tracer::plot
virtual void plot(std::string_view name, float64_t value)=0
Sends a value that will be plotted.
sen::kernel::Tracer::plot
virtual void plot(std::string_view name, int64_t value)=0
Sends a value that will be plotted.
sen::kernel::Tracer::zoneEnd
virtual void zoneEnd()=0
compiler_macros.h
sen::makeScopeGuard
auto makeScopeGuard(F &&f)
Makes scope guard from a callable taking no arguments.
float64_t
double float64_t
Definition
numbers.h:17
sen::SourceLocation
Represents a location in source code.
Definition
source_location.h:47
sen::kernel
Strong type for the unique identifier for a transport timer.
Definition
native_object_impl.h:39
sen::kernel::TracerFactory
std::function< std::unique_ptr< Tracer >(std::string_view)> TracerFactory
A factory function for tracers.
Definition
tracer.h:119
sen::kernel::getDefaultTracerFactory
TracerFactory getDefaultTracerFactory()
A function that returns a no-op tracer.
numbers.h
scope_guard.h
source_location.h
libs
kernel
include
sen
kernel
tracer.h
Generated by
1.17.0