0

How to use trace marker in ftrace in order to record user events? I use the following, but the compiler cannot define 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);

And later, using the trace_write() function to record into the ftrace buffer.

    trace_write("record this event\n")

The compiler error:

error: C++ requires a type specifier for all declarations
trace_fd = open("trace_marker", WR_ONLY);
Tsyvarev
  • 60,011
  • 17
  • 110
  • 153

1 Answers1

0

There appears to be an error in the ftrace documentation where you seem to have copied your code from. Try O_WRONLY (#include <sys/fcntl.h> to get its definition) instead of WR_ONLY.

Note that you'll also need the full path to trace_marker, which is /sys/kernel/debug/tracing/trace_marker or /sys/kernel/tracing/trace_marker depending on your kernel version and mount location of the tracefs.

Sam Nobs
  • 61
  • 2
  • 6