VLC 4.0.0-dev
Loading...
Searching...
No Matches
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 tracer Tracer module and API
33 * \ingroup os
34 *
35 * Functions for modules to emit traces.
36 *
37 * @{
38 * \file
39 * Tracing functions
40 *
41 * \defgroup tracer_module Tracer Module implementation
42 * \ingroup tracer
43 *
44 * @{
45 */
46
47/**
48 * Trace message values
49 */
57typedef union
59 int64_t integer;
60 double double_;
61 const char *string;
63
64/**
65 * Trace message
66 */
69 const char *key; /**< Key to identify the value */
70 vlc_tracer_value_t value; /**< Trace value */
71 enum vlc_tracer_value type; /**< Type of the value */
72};
73
74struct vlc_tracer;
75
76/**
77 * Trace record containing the key-values from the trace.
78 */
81 /**
82 * Defines the list of key-value in the trace. The entries must link
83 * towards an array terminated by a VLC_TRACE_END entry, which remains
84 * valid as long as the trace itself should remain valid.
85 **/
86 const struct vlc_tracer_entry *entries;
87};
88
89
90/**
91 * Tracer operations returned by the module probe function
92 */
95 /**
96 * Called when tracing data
97 *
98 * \param sys data pointer set by vlc_tracer_open_cb()
99 * \param ts timestamp of the trace (based on vlc_tick_now())
100 * \param entries can only be \ref vlc_tracer_entry and the va-args list
101 * should be ended by a \ref vlc_tracer_entry with a NULL key.
102 */
103 void (*trace)(void *sys, vlc_tick_t ts, const struct vlc_tracer_trace *trace);
105 /**
106 * Called to clean module specific resources
107 *
108 * \param sys data pointer set by vlc_tracer_open_cb()
109 */
110 void (*destroy)(void *sys);
112
113/**
114 * Module probe/open function signature
115 *
116 * \param obj a valid object
117 * \param[out] sysp to module specific data
118 * \return the operations implemented by the module or NULL in case of error
119 * */
120typedef struct vlc_tracer_operations *(*vlc_tracer_open_cb)(vlc_object_t *obj,
121 void **restrict sysp);
122
123/**
124 * @}
125 *
126 * \defgroup tracer_api Tracer API
127 * \ingroup tracer
128 *
129 * @{
130 */
131
132/**
133 * Create a tracer object
134 *
135 * \note This function is for advanced debugging/testing.
136 * Use vlc_object_get_tracer() to get the existing tracer.
137 *
138 * \param parent parent object used to create the tracer
139 * \param name module to load or NULL for the default one
140 * \return a valid tracer or NULL in case of error
141 */
143 const char *name);
144
145/**
146 * Destroy a tracer object
147 */
148VLC_API void vlc_tracer_Destroy(struct vlc_tracer *tracer);
149
150/**
151 * Emit traces
152 *
153 * \param tracer tracer emitting the traces
154 * \param ts timestamp of the current trace
155 * \param trace the trace to register with its list of key / value parameters.
156 * Key must be a not NULL string. Value has to be defined with
157 * one of the type defined in the \ref vlc_tracer_entry union.
158 */
159
161 const struct vlc_tracer_trace *trace);
162#define vlc_tracer_TraceWithTs(tracer, ts, ...) \
163 (vlc_tracer_TraceWithTs)(tracer, ts, &(const struct vlc_tracer_trace) { \
164 .entries = (const struct vlc_tracer_entry[]) { \
165 __VA_ARGS__ \
166 } \
167 })
168
169#define vlc_tracer_Trace(tracer, ...) \
170 vlc_tracer_TraceWithTs(tracer, vlc_tick_now(), __VA_ARGS__)
171
172static inline struct vlc_tracer_entry vlc_tracer_entry_FromInt(const char *key, int64_t value)
174 vlc_tracer_value_t tracer_value;
175 tracer_value.integer = value;
176 struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_INT };
177 return trace;
178}
179
180static inline struct vlc_tracer_entry vlc_tracer_entry_FromDouble(const char *key, double value)
182 vlc_tracer_value_t tracer_value = {
183 .double_ = value,
184 };
185 struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_DOUBLE };
186 return trace;
187}
188
189static inline struct vlc_tracer_entry vlc_tracer_entry_FromString(const char *key, const char *value)
191 vlc_tracer_value_t tracer_value;
192 tracer_value.string = value;
193 struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_STRING };
194 return trace;
195}
196
197#ifndef __cplusplus
198#define VLC_TRACE_END \
199 vlc_tracer_entry_FromString(NULL, NULL)
200
201#define VLC_TRACE(key, value) \
202 _Generic((value), \
203 int64_t: vlc_tracer_entry_FromInt, \
204 double: vlc_tracer_entry_FromDouble, \
205 char *: vlc_tracer_entry_FromString, \
206 const char *: vlc_tracer_entry_FromString) (key, value)
207#else
208#define VLC_TRACE_END \
209 vlc_tracer_entry_FromString(nullptr, nullptr)
210
211static inline struct vlc_tracer_entry VLC_TRACE(const char *key, int64_t value)
212{
214}
215
216static inline struct vlc_tracer_entry VLC_TRACE(const char *key, char *value)
217{
219}
220
221static inline struct vlc_tracer_entry VLC_TRACE(const char *key, const char *value)
222{
224}
225#endif
226
227#define VLC_TRACE_TICK_NS(key, tick) VLC_TRACE((key), NS_FROM_VLC_TICK((tick)))
229/**
230 * @}
231 *
232 * \defgroup tracer_helper Tracer helper functions
233 * \ingroup tracer
234 *
235 * @{
236 */
237
238static inline void vlc_tracer_TraceStreamPTS(struct vlc_tracer *tracer, const char *type,
239 const char *id, const char* stream,
240 vlc_tick_t pts)
241{
242 vlc_tracer_Trace(tracer, VLC_TRACE("type", type),
243 VLC_TRACE("id", id),
244 VLC_TRACE("stream", stream),
245 VLC_TRACE_TICK_NS("pts", pts),
247}
248
249static inline void vlc_tracer_TraceStreamDTS(struct vlc_tracer *tracer, const char *type,
250 const char *id, const char* stream,
251 vlc_tick_t pts, vlc_tick_t dts)
252{
253 vlc_tracer_Trace(tracer, VLC_TRACE("type", type),
254 VLC_TRACE("id", id),
255 VLC_TRACE("stream", stream),
256 VLC_TRACE_TICK_NS("pts", pts),
257 VLC_TRACE_TICK_NS("dts", dts),
259}
260
261static inline void vlc_tracer_TraceEvent(struct vlc_tracer *tracer, const char *type,
262 const char *id, const char *event)
263{
264 vlc_tracer_Trace(tracer, VLC_TRACE("type", type),
265 VLC_TRACE("id", id),
266 VLC_TRACE("event", event),
268}
269
270static inline void vlc_tracer_TracePCR( struct vlc_tracer *tracer, const char *type,
271 const char *id, vlc_tick_t pcr)
272{
273 vlc_tracer_Trace(tracer, VLC_TRACE("type", type),
274 VLC_TRACE("id", id),
275 VLC_TRACE_TICK_NS("pcr", pcr),
277}
278
279/**
280 * @}
281 */
282/**
283 * @}
284 */
285#endif
#define VLC_API
Definition fourcc_gen.c:31
#define VLC_TRACE(key, value)
Definition vlc_tracer.h:202
#define VLC_TRACE_TICK_NS(key, tick)
Definition vlc_tracer.h:228
struct vlc_tracer * vlc_tracer_Create(vlc_object_t *parent, const char *name)
Create a tracer object.
Definition tracer.c:71
void vlc_tracer_Destroy(struct vlc_tracer *tracer)
Destroy a tracer object.
Definition tracer.c:88
static struct vlc_tracer_entry vlc_tracer_entry_FromDouble(const char *key, double value)
Definition vlc_tracer.h:181
#define VLC_TRACE_END
Definition vlc_tracer.h:199
#define vlc_tracer_TraceWithTs(tracer, ts,...)
Definition vlc_tracer.h:163
static struct vlc_tracer_entry vlc_tracer_entry_FromInt(const char *key, int64_t value)
Definition vlc_tracer.h:173
static struct vlc_tracer_entry vlc_tracer_entry_FromString(const char *key, const char *value)
Definition vlc_tracer.h:190
#define vlc_tracer_Trace(tracer,...)
Definition vlc_tracer.h:170
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:239
static void vlc_tracer_TracePCR(struct vlc_tracer *tracer, const char *type, const char *id, vlc_tick_t pcr)
Definition vlc_tracer.h:271
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:250
static void vlc_tracer_TraceEvent(struct vlc_tracer *tracer, const char *type, const char *id, const char *event)
Definition vlc_tracer.h:262
vlc_tracer_value
Trace message values.
Definition vlc_tracer.h:52
@ VLC_TRACER_STRING
Definition vlc_tracer.h:55
@ VLC_TRACER_INT
Definition vlc_tracer.h:53
@ VLC_TRACER_DOUBLE
Definition vlc_tracer.h:54
const char name[16]
Definition httpd.c:1298
VLC object common members.
Definition vlc_objects.h:53
Trace message.
Definition vlc_tracer.h:69
vlc_tracer_value_t value
Trace value.
Definition vlc_tracer.h:71
const char * key
Key to identify the value.
Definition vlc_tracer.h:70
enum vlc_tracer_value type
Type of the value.
Definition vlc_tracer.h:72
Tracer operations returned by the module probe function.
Definition vlc_tracer.h:95
void(* destroy)(void *sys)
Called to clean module specific resources.
Definition vlc_tracer.h:111
void(* trace)(void *sys, vlc_tick_t ts, const struct vlc_tracer_trace *trace)
Called when tracing data.
Definition vlc_tracer.h:104
Trace record containing the key-values from the trace.
Definition vlc_tracer.h:81
const struct vlc_tracer_entry * entries
Defines the list of key-value in the trace.
Definition vlc_tracer.h:87
Definition tracer.c:36
Definition vlc_tracer.h:59
const char * string
Definition vlc_tracer.h:62
double double_
Definition vlc_tracer.h:61
int64_t integer
Definition vlc_tracer.h:60
This file is a collection of common definitions and types.
Thread primitive declarations.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48