tracer: move tick conversion in modules

This commit is contained in:
Thomas Guillem 2022-05-12 15:59:08 +02:00 committed by Felix Paul Kühne
parent 31c7dc1204
commit 425f4424d6
2 changed files with 11 additions and 5 deletions

View File

@ -43,17 +43,17 @@
enum vlc_tracer_value
{
VLC_TRACER_INT,
VLC_TRACER_TICK,
VLC_TRACER_STRING
};
typedef union
{
int64_t integer;
vlc_tick_t tick;
const char *string;
} vlc_tracer_value_t;
#define VLC_TRACER_TIME_FROM_TICK(ts) NS_FROM_VLC_TICK(ts)
/**
* Trace message
*/
@ -102,8 +102,8 @@ VLC_API void vlc_tracer_Trace(struct vlc_tracer *tracer, ...);
static inline struct vlc_tracer_entry vlc_tracer_entry_FromTick(const char *key, vlc_tick_t value)
{
vlc_tracer_value_t tracer_value;
tracer_value.integer = VLC_TRACER_TIME_FROM_TICK(value);
struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_INT };
tracer_value.integer = value;
struct vlc_tracer_entry trace = { key, tracer_value, VLC_TRACER_TICK };
return trace;
}

View File

@ -39,6 +39,8 @@
#define JSON_FILENAME "vlc-log.json"
#define TIME_FROM_TICK(ts) NS_FROM_VLC_TICK(ts)
typedef struct
{
FILE *stream;
@ -161,7 +163,7 @@ static void TraceJson(void *opaque, va_list entries)
flockfile(stream);
JsonStartObjectSection(stream, NULL);
JsonPrintKeyValueNumber(stream, "Timestamp", VLC_TRACER_TIME_FROM_TICK(vlc_tick_now()));
JsonPrintKeyValueNumber(stream, "Timestamp", TIME_FROM_TICK(vlc_tick_now()));
fputc(',', stream);
JsonStartObjectSection(stream, "Body");
@ -174,6 +176,10 @@ static void TraceJson(void *opaque, va_list entries)
case VLC_TRACER_INT:
JsonPrintKeyValueNumber(stream, entry.key, entry.value.integer);
break;
case VLC_TRACER_TICK:
JsonPrintKeyValueNumber(stream, entry.key,
TIME_FROM_TICK(entry.value.tick));
break;
case VLC_TRACER_STRING:
JsonPrintKeyValueLabel(stream, entry.key, entry.value.string);
break;