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

9
include/util/trace.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef UTIL_TRACE_H
#define UTIL_TRACE_H
#include <wlr/util/log.h>
void wlr_trace(const char *format, ...) _WLR_ATTRIB_PRINTF(1, 2);
void wlr_vtrace(const char *format, va_list args) _WLR_ATTRIB_PRINTF(1, 0);
#endif

View file

@ -13,6 +13,7 @@ wlr_files += files(
'shm.c',
'time.c',
'token.c',
'trace.c',
'transform.c',
'utf8.c',
)

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);
}