[vlc-commits] [Git][videolan/vlc][master] tracer: use an array of entries instead of va_list
François Cartegnie (@fcartegnie)
gitlab at videolan.org
Thu Mar 7 09:57:06 UTC 2024
François Cartegnie pushed to branch master at VideoLAN / VLC
Commits:
6ea08ff6 by Alexandre Janniaux at 2024-03-07T09:26:22+00:00
tracer: use an array of entries instead of va_list
Forward the tracing key/value entries as an array instead of using
va_list. Using an array is easier to interop with in other languages,
but also and more importantly much easier to store and forward.
This will allow to implement hierarchical tracing context.
- - - - -
5 changed files:
- include/vlc_tracer.h
- modules/logger/json.c
- src/libvlccore.sym
- src/misc/tracer.c
- test/src/clock/clock.c
Changes:
=====================================
include/vlc_tracer.h
=====================================
@@ -73,6 +73,20 @@ struct vlc_tracer_entry
struct vlc_tracer;
+/**
+ * Trace record containing the key-values from the trace.
+ */
+struct vlc_tracer_trace
+{
+ /**
+ * Defines the list of key-value in the trace. The entries must link
+ * towards an array terminated by a VLC_TRACE_END entry, which remains
+ * valid as long as the trace itself should remain valid.
+ **/
+ const struct vlc_tracer_entry *entries;
+};
+
+
/**
* Tracer operations returned by the module probe function
*/
@@ -86,7 +100,7 @@ struct vlc_tracer_operations
* \param entries can only be \ref vlc_tracer_entry and the va-args list
* should be ended by a \ref vlc_tracer_entry with a NULL key.
*/
- void (*trace)(void *sys, vlc_tick_t ts, va_list entries);
+ void (*trace)(void *sys, vlc_tick_t ts, const struct vlc_tracer_trace *trace);
/**
* Called to clean module specific resources
@@ -138,23 +152,19 @@ VLC_API void vlc_tracer_Destroy(struct vlc_tracer *tracer);
*
* \param tracer tracer emitting the traces
* \param ts timestamp of the current trace
- * \param entries list of key / value parameters.
- * Key must be a not NULL string.
- * Value has to be defined with one of the type defined
- * in the \ref vlc_tracer_entry union.
+ * \param trace the trace to register with its list of key / value parameters.
+ * Key must be a not NULL string. Value has to be defined with
+ * one of the type defined in the \ref vlc_tracer_entry union.
*/
-VLC_API void vlc_tracer_vaTraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts,
- va_list entries);
-/**
- * Emit traces
- *
- * cf. vlc_tracer_vaTraceWithTs()
- *
- * \param tracer tracer emitting the traces
- * \param ts timestamp of the current trace
- */
-VLC_API void vlc_tracer_TraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts, ...);
+VLC_API void vlc_tracer_TraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts,
+ const struct vlc_tracer_trace *trace);
+#define vlc_tracer_TraceWithTs(tracer, ts, ...) \
+ (vlc_tracer_TraceWithTs)(tracer, ts, &(const struct vlc_tracer_trace) { \
+ .entries = (const struct vlc_tracer_entry[]) { \
+ __VA_ARGS__ \
+ } \
+ })
#define vlc_tracer_Trace(tracer, ...) \
vlc_tracer_TraceWithTs(tracer, vlc_tick_now(), __VA_ARGS__)
=====================================
modules/logger/json.c
=====================================
@@ -164,7 +164,7 @@ static void JsonEndObjectSection(FILE *stream)
fputc('}', stream);
}
-static void TraceJson(void *opaque, vlc_tick_t ts, va_list entries)
+static void TraceJson(void *opaque, vlc_tick_t ts, const struct vlc_tracer_trace *trace)
{
vlc_tracer_sys_t *sys = opaque;
FILE* stream = sys->stream;
@@ -176,26 +176,26 @@ static void TraceJson(void *opaque, vlc_tick_t ts, va_list entries)
JsonStartObjectSection(stream, "Body");
- struct vlc_tracer_entry entry = va_arg(entries, struct vlc_tracer_entry);
- while (entry.key != NULL)
+ const struct vlc_tracer_entry *entry = trace->entries;
+ while (entry->key != NULL)
{
- switch (entry.type)
+ switch (entry->type)
{
case VLC_TRACER_INT:
- JsonPrintKeyValueNumber(stream, entry.key, entry.value.integer);
+ JsonPrintKeyValueNumber(stream, entry->key, entry->value.integer);
break;
case VLC_TRACER_DOUBLE:
- JsonPrintKeyValueNumberFromDouble(stream, entry.key, entry.value.double_);
+ JsonPrintKeyValueNumberFromDouble(stream, entry->key, entry->value.double_);
break;
case VLC_TRACER_STRING:
- JsonPrintKeyValueLabel(stream, entry.key, entry.value.string);
+ JsonPrintKeyValueLabel(stream, entry->key, entry->value.string);
break;
default:
vlc_assert_unreachable();
break;
}
- entry = va_arg(entries, struct vlc_tracer_entry);
- if (entry.key != NULL)
+ entry++;
+ if (entry->key != NULL)
{
fputc(',', stream);
}
=====================================
src/libvlccore.sym
=====================================
@@ -294,7 +294,6 @@ vlc_vaLog
vlc_tracer_Create
vlc_tracer_Destroy
vlc_tracer_TraceWithTs
-vlc_tracer_vaTraceWithTs
vlc_LogHeaderCreate
vlc_LogDestroy
vlc_strerror
=====================================
src/misc/tracer.c
=====================================
@@ -46,30 +46,16 @@ struct vlc_tracer_module {
void *opaque;
};
-void vlc_tracer_vaTraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts,
- va_list entries)
-{
- assert(tracer->ops->trace != NULL);
- struct vlc_tracer_module *module =
- container_of(tracer, struct vlc_tracer_module, tracer);
-
- va_list copy;
- va_copy(copy, entries);
- tracer->ops->trace(module->opaque, ts, copy);
- va_end(copy);
-}
-
-void vlc_tracer_TraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts, ...)
+#undef vlc_tracer_TraceWithTs
+void vlc_tracer_TraceWithTs(struct vlc_tracer *tracer, vlc_tick_t ts,
+ const struct vlc_tracer_trace *trace)
{
assert(tracer->ops->trace != NULL);
struct vlc_tracer_module *module =
container_of(tracer, struct vlc_tracer_module, tracer);
/* Pass message to the callback */
- va_list entries;
- va_start(entries, ts);
- tracer->ops->trace(module->opaque, ts, entries);
- va_end(entries);
+ tracer->ops->trace(module->opaque, ts, trace);
}
static int vlc_tracer_load(void *func, bool forced, va_list ap)
=====================================
test/src/clock/clock.c
=====================================
@@ -176,13 +176,12 @@ static void tracer_ctx_PushStatus(struct tracer_ctx *ctx,
assert(ret);
}
-static void TracerTrace(void *opaque, vlc_tick_t ts, va_list entries)
+static void TracerTrace(void *opaque, vlc_tick_t ts,
+ const struct vlc_tracer_trace *trace)
{
struct vlc_tracer *libvlc_tracer = opaque;
- va_list copy;
- va_copy(copy, entries);
- struct vlc_tracer_entry entry = va_arg(entries, struct vlc_tracer_entry);
+ const struct vlc_tracer_entry *entry = trace->entries;
bool is_render = false, is_render_video = false, is_status = false;
unsigned nb_update = 0;
@@ -191,55 +190,55 @@ static void TracerTrace(void *opaque, vlc_tick_t ts, va_list entries)
vlc_tick_t render_video_pts = VLC_TICK_INVALID;
enum tracer_event_status status = 0;
- while (entry.key != NULL)
+ while (entry->key != NULL)
{
- switch (entry.type)
+ switch (entry->type)
{
case VLC_TRACER_INT:
if (!is_render)
continue;
assert(!is_status);
- if (strcmp(entry.key, "offset") == 0)
+ if (strcmp(entry->key, "offset") == 0)
{
nb_update++;
- offset = VLC_TICK_FROM_NS(entry.value.integer);
+ offset = VLC_TICK_FROM_NS(entry->value.integer);
}
- else if (strcmp(entry.key, "render_pts") == 0)
- render_video_pts = VLC_TICK_FROM_NS(entry.value.integer);
+ else if (strcmp(entry->key, "render_pts") == 0)
+ render_video_pts = VLC_TICK_FROM_NS(entry->value.integer);
break;
case VLC_TRACER_DOUBLE:
if (!is_render)
continue;
assert(!is_status);
- if (strcmp(entry.key, "coeff") == 0)
+ if (strcmp(entry->key, "coeff") == 0)
{
nb_update++;
- coeff = entry.value.double_;
+ coeff = entry->value.double_;
}
break;
case VLC_TRACER_STRING:
- if (strcmp(entry.key, "type") == 0)
+ if (strcmp(entry->key, "type") == 0)
{
- if (strcmp(entry.value.string, "RENDER") == 0)
+ if (strcmp(entry->value.string, "RENDER") == 0)
is_render = true;
}
- else if (strcmp(entry.key, "id") == 0)
+ else if (strcmp(entry->key, "id") == 0)
{
- if (strcmp(entry.value.string, "video") == 0)
+ if (strcmp(entry->value.string, "video") == 0)
is_render_video= true;
}
if (!is_render)
continue;
/* Assert that there is no "reset_bad_source" */
- if (strcmp(entry.key, "event") == 0)
+ if (strcmp(entry->key, "event") == 0)
{
is_status = true;
- if (strcmp(entry.value.string, "reset_bad_source") == 0)
+ if (strcmp(entry->value.string, "reset_bad_source") == 0)
status = TRACER_EVENT_STATUS_RESET_BADSOURCE;
- else if (strcmp(entry.value.string, "reset_user") == 0)
+ else if (strcmp(entry->value.string, "reset_user") == 0)
status = TRACER_EVENT_STATUS_RESET_USER;
else
vlc_assert_unreachable();
@@ -248,7 +247,7 @@ static void TracerTrace(void *opaque, vlc_tick_t ts, va_list entries)
break;
default: vlc_assert_unreachable();
}
- entry = va_arg(entries, struct vlc_tracer_entry);
+ entry++;
}
if (libvlc_tracer != NULL)
@@ -260,9 +259,8 @@ static void TracerTrace(void *opaque, vlc_tick_t ts, va_list entries)
/* Use the original ts for the "render_pts" entry */
vlc_tick_t tracer_ts = render_video_pts != VLC_TICK_INVALID ?
ts : tracer_ctx.forced_ts;
- vlc_tracer_vaTraceWithTs(libvlc_tracer, tracer_ts, copy);
+ (vlc_tracer_TraceWithTs)(libvlc_tracer, tracer_ts, trace);
}
- va_end(copy);
if (!is_render)
return;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6ea08ff624fe3f16239ab1932b238159ce5e6883
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6ea08ff624fe3f16239ab1932b238159ce5e6883
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list