'\" t .\" Title: trace_printk .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.79.1 .\" Date: January 2017 .\" Manual: Driver Basics .\" Source: Kernel Hackers Manual 4.8.15 .\" Language: English .\" .TH "TRACE_PRINTK" "9" "January 2017" "Kernel Hackers Manual 4\&.8\&." "Driver Basics" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" trace_printk \- printf formatting in the ftrace buffer .SH "SYNOPSIS" .HP \w'trace_printk('u .BI "trace_printk(" "fmt" ", " "\&.\&.\&." ");" .SH "ARGUMENTS" .PP \fIfmt\fR .RS 4 the printf format for printing .RE .PP \fI\&.\&.\&.\fR .RS 4 variable arguments .RE .SH "NOTE" .PP __trace_printk is an internal function for trace_printk and the \fIip\fR is passed in via the trace_printk macro\&. .PP This function allows a kernel developer to debug fast path sections that printk is not appropriate for\&. By scattering in various printk like tracing in the code, a developer can quickly see where problems are occurring\&. .PP This is intended as a debugging tool for the developer only\&. Please refrain from leaving trace_printks scattered around in your code\&. (Extra memory is used for special buffers that are allocated when \fBtrace_printk\fR is used) .PP A little optization trick is done here\&. If there\*(Aqs only one argument, there\*(Aqs no need to scan the string for printf formats\&. The \fBtrace_puts\fR will suffice\&. But how can we take advantage of using \fBtrace_puts\fR when \fBtrace_printk\fR has only one argument? By stringifying the args and checking the size we can tell whether or not there are args\&. __stringify((__VA_ARGS__)) will turn into \(lq()\e0\(rq with a size of 3 when there are no args, anything else will be bigger\&. All we need to do is define a string to this, and then take its size and compare to 3\&. If it\*(Aqs bigger, use \fBdo_trace_printk\fR otherwise, optimize it to \fBtrace_puts\fR\&. Then just let gcc optimize the rest\&. .SH "COPYRIGHT" .br