mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-06 13:29:45 -05:00
util/trace: add ftrace utilities
This commit is contained in:
parent
462046ffdc
commit
79b5dcb17d
3 changed files with 40 additions and 0 deletions
9
include/util/trace.h
Normal file
9
include/util/trace.h
Normal 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
|
||||
|
|
@ -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
30
util/trace.c
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue