如何在ftrace中使用跟踪标记来记录用户事件?我使用了以下代码,但是编译器不能定义WR_ONLY
static int trace_fd = -1;
void trace_write(const char *fmt, ...)
{
va_list ap;
char buf[256];
int n;
if (trace_fd < 0)
return;
va_start(ap, fmt);
n = vsnprintf(buf, 256, fmt, ap);
va_end(ap);
write(trace_fd, buf, n);
}
[...]
trace_fd = open("trace_marker", WR_ONLY);然后,使用trace_write()函数记录到ftrace缓冲区中。
trace_write("record this event\n")编译器错误:
error: C++ requires a type specifier for all declarations
trace_fd = open("trace_marker", WR_ONLY);发布于 2019-04-11 07:15:25
在ftrace documentation中似乎有一个错误,您似乎已经从其中复制了代码。尝试使用O_WRONLY (#include <sys/fcntl.h>获取其定义),而不是WR_ONLY。
注意,您还需要trace_marker的完整路径,它是/sys/kernel/debug/tracing/trace_marker还是/sys/kernel/tracing/trace_marker,具体取决于您的内核版本和tracefs的挂载位置。
https://stackoverflow.com/questions/50050973
复制相似问题