util/trace: add ftrace utilities

This commit is contained in:
Simon Ser 2021-03-17 10:19:23 +01:00
parent 462046ffdc
commit 79b5dcb17d
3 changed files with 40 additions and 0 deletions

30
util/trace.c Normal file
View file

@ -0,0 +1,30 @@
#include <stdio.h>
#include "util/trace.h"
static bool trace_initialized = false;
static FILE *trace_file = NULL;
void wlr_vtrace(const char *fmt, va_list args) {
if (!trace_initialized) {
trace_initialized = true;
trace_file = fopen("/sys/kernel/tracing/trace_marker", "w");
if (trace_file != NULL) {
wlr_log(WLR_INFO, "Kernel tracing is enabled");
}
}
if (trace_file == NULL) {
return;
}
vfprintf(trace_file, fmt, args);
fprintf(trace_file, "\n");
fflush(trace_file);
}
void wlr_trace(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
wlr_vtrace(fmt, args);
va_end(args);
}