VLC 4.0.0-dev
vlc_tracer.h
Go to the documentation of this file.
1/*****************************************************************************
2 * vlc_tracer.h: tracing interface
3 * This library provides basic functions for threads to interact with user
4 * interface, such as trace output.
5 *****************************************************************************
6 * Copyright (C) 2021 VLC authors and VideoLAN
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
22
23#ifndef VLC_TRACES_H
24#define VLC_TRACES_H
25
26#include <stdarg.h>
27
28#include <vlc_common.h>
29#include <vlc_threads.h>
30
31/**
32 * \defgroup traces Tracing
33 * \ingroup os
34 * \brief Message traces
35 *
36 * Functions for modules to emit traces.
37 *
38 * @{
39 * \file
40 * Tracing functions
41 */
42
43/**
44 * Trace message values
45 */
51};
53typedef union
55 int64_t integer;
57 const char *string;
59
60/**
61 * Trace message
62 */
65 const char *key; /**< Key to identify the value */
66 vlc_tracer_value_t value; /**< Trace value */
67 enum vlc_tracer_value type; /**< Type of the value */
68};
69
70struct vlc_tracer;
71
72/**
73 * Trace logging callback signature.
74 *
75 * va-args can only be \ref vlc_tracer_entry and the va-args list
76 * should be ended by a \ref vlc_tracer_entry with a NULL key.
77 * \param data data pointer as provided to vlc_tracer_Trace().
78 */
79typedef void (*vlc_trace_cb) (void *data, vlc_tick_t ts, va_list entries);
84 void (*destroy)(void *data);
85};
86
87/**
88 * Emit traces
89 *
90 * va-args are a list of key / value parameters.
91 * Key must be a not NULL string.
92 * Value has to be defined with one of the type defined
93 * in the \ref vlc_tracer_entry union.
94 * \param tracer tracer emitting the traces
95 * \param ts timestamp of the current trace
96 */
97VLC_API void vlc_tracer_TraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts, ...);
98
99#define vlc_tracer_Trace(tracer, ...) \
100 vlc_tracer_TraceWithTs(tracer, vlc_tick_now(), __VA_ARGS__)
101
102/**
103 * \defgroup tracer Tracer
104 * \brief Tracing back-end.
105 *
106 * @{
107 */
108
109static inline struct vlc_tracer_entry vlc_tracer_entry_FromTick(const char *key, vlc_tick_t value)
111 vlc_tracer_value_t tracer_value;
112 tracer_value.tick = value;
113 struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_TICK };
114 return trace;
115}
116
117static inline struct vlc_tracer_entry vlc_tracer_entry_FromString(const char *key, const char *value)
119 vlc_tracer_value_t tracer_value;
120 tracer_value.string = value;
121 struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_STRING };
122 return trace;
123}
124
125#ifndef __cplusplus
126#define VLC_TRACE_END \
127 vlc_tracer_entry_FromString(NULL, NULL)
128
129#define VLC_TRACE(key, value) \
130 _Generic((value), \
131 vlc_tick_t: vlc_tracer_entry_FromTick, \
132 char *: vlc_tracer_entry_FromString, \
133 const char *: vlc_tracer_entry_FromString) (key, value)
134#else
135#define VLC_TRACE_END \
136 vlc_tracer_entry_FromString(nullptr, nullptr)
137
138static inline struct vlc_tracer_entry VLC_TRACE(const char *key, vlc_tick_t value)
139{
141}
142
143static inline struct vlc_tracer_entry VLC_TRACE(const char *key, char *value)
144{
146}
147
148static inline struct vlc_tracer_entry VLC_TRACE(const char *key, const char *value)
149{
151}
152#endif
153
154/*
155 * Helper trace functions
156 */
157
158static inline void vlc_tracer_TraceStreamPTS(struct vlc_tracer *tracer, const char *type,
159 const char *id, const char* stream,
160 vlc_tick_t pts)
161{
162 vlc_tracer_Trace(tracer, VLC_TRACE("type", type), VLC_TRACE("id", id),
163 VLC_TRACE("stream", stream), VLC_TRACE("pts", pts),
165}
166
167static inline void vlc_tracer_TraceStreamDTS(struct vlc_tracer *tracer, const char *type,
168 const char *id, const char* stream,
169 vlc_tick_t pts, vlc_tick_t dts)
170{
171 vlc_tracer_Trace(tracer, VLC_TRACE("type", type), VLC_TRACE("id", id),
172 VLC_TRACE("stream", stream), VLC_TRACE("pts", pts),
173 VLC_TRACE("dts", dts), VLC_TRACE_END);
174}
175
176static inline void vlc_tracer_TraceRender(struct vlc_tracer *tracer, const char *type,
177 const char *id, vlc_tick_t now, vlc_tick_t pts)
178{
179 if (now != VLC_TICK_MAX && now != VLC_TICK_INVALID)
180 {
182 VLC_TRACE("id", id), VLC_TRACE("pts", pts),
183 VLC_TRACE("render_ts", now), VLC_TRACE_END);
184 vlc_tracer_TraceWithTs(tracer, now, VLC_TRACE("type", type),
185 VLC_TRACE("id", id), VLC_TRACE("render_pts", pts),
187
188 }
189 else
190 vlc_tracer_Trace(tracer, VLC_TRACE("type", type), VLC_TRACE("id", id),
191 VLC_TRACE("pts", pts), VLC_TRACE_END);
192}
193
194static inline void vlc_tracer_TraceEvent(struct vlc_tracer *tracer, const char *type,
195 const char *id, const char *event)
196{
197 vlc_tracer_Trace(tracer, VLC_TRACE("type", type), VLC_TRACE("id", id),
198 VLC_TRACE("event", event), VLC_TRACE_END);
199}
200
201static inline void vlc_tracer_TracePCR( struct vlc_tracer *tracer, const char *type,
202 const char *id, vlc_tick_t pcr)
203{
204 vlc_tracer_Trace(tracer, VLC_TRACE("type", type), VLC_TRACE("id", id),
205 VLC_TRACE("pcr", pcr), VLC_TRACE_END);
206}
207
208/**
209 * @}
210 */
211/**
212 * @}
213 */
214#endif
#define VLC_API
Definition: fourcc_gen.c:31
vlc_tick_t vlc_tick_now(void)
Precision monotonic clock.
Definition: thread.c:227
static void vlc_tracer_TraceStreamPTS(struct vlc_tracer *tracer, const char *type, const char *id, const char *stream, vlc_tick_t pts)
Definition: vlc_tracer.h:159
static struct vlc_tracer_entry vlc_tracer_entry_FromTick(const char *key, vlc_tick_t value)
Definition: vlc_tracer.h:110
#define VLC_TRACE(key, value)
Definition: vlc_tracer.h:130
static void vlc_tracer_TracePCR(struct vlc_tracer *tracer, const char *type, const char *id, vlc_tick_t pcr)
Definition: vlc_tracer.h:202
static void vlc_tracer_TraceStreamDTS(struct vlc_tracer *tracer, const char *type, const char *id, const char *stream, vlc_tick_t pts, vlc_tick_t dts)
Definition: vlc_tracer.h:168
static void vlc_tracer_TraceRender(struct vlc_tracer *tracer, const char *type, const char *id, vlc_tick_t now, vlc_tick_t pts)
Definition: vlc_tracer.h:177
#define VLC_TRACE_END
Definition: vlc_tracer.h:127
static void vlc_tracer_TraceEvent(struct vlc_tracer *tracer, const char *type, const char *id, const char *event)
Definition: vlc_tracer.h:195
static struct vlc_tracer_entry vlc_tracer_entry_FromString(const char *key, const char *value)
Definition: vlc_tracer.h:118
void vlc_tracer_TraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts,...)
Emit traces.
Definition: tracer.c:49
void(* vlc_trace_cb)(void *data, vlc_tick_t ts, va_list entries)
Trace logging callback signature.
Definition: vlc_tracer.h:80
vlc_tracer_value
Trace message values.
Definition: vlc_tracer.h:48
#define vlc_tracer_Trace(tracer,...)
Definition: vlc_tracer.h:100
@ VLC_TRACER_STRING
Definition: vlc_tracer.h:51
@ VLC_TRACER_INT
Definition: vlc_tracer.h:49
@ VLC_TRACER_TICK
Definition: vlc_tracer.h:50
Trace message.
Definition: vlc_tracer.h:65
vlc_tracer_value_t value
Trace value.
Definition: vlc_tracer.h:67
const char * key
Key to identify the value.
Definition: vlc_tracer.h:66
enum vlc_tracer_value type
Type of the value.
Definition: vlc_tracer.h:68
Definition: vlc_tracer.h:83
void(* destroy)(void *data)
Definition: vlc_tracer.h:85
vlc_trace_cb trace
Definition: vlc_tracer.h:84
Definition: tracer.c:36
Definition: vlc_tracer.h:55
const char * string
Definition: vlc_tracer.h:58
int64_t integer
Definition: vlc_tracer.h:56
vlc_tick_t tick
Definition: vlc_tracer.h:57
This file is a collection of common definitions and types.
#define VLC_TICK_INVALID
Definition: vlc_config.h:44
Thread primitive declarations.
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_tick.h:45
#define VLC_TICK_MAX
Definition: vlc_tick.h:48