1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>trace_printk</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Device Drivers"><link rel="up" href="ch01s09.html" title="Kernel utility functions"><link rel="prev" href="API-kstrtol.html" title="kstrtol"><link rel="next" href="API-trace-puts.html" title="trace_puts"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">trace_printk</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-kstrtol.html">Prev</a>&#160;</td><th width="60%" align="center">Kernel utility functions</th><td width="20%" align="right">&#160;<a accesskey="n" href="API-trace-puts.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-trace-printk"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>trace_printk &#8212; 
2     printf formatting in the ftrace buffer
3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef"> <b class="fsfunc">trace_printk </b>(</code></td><td> <var class="pdparam">fmt</var>, </td></tr><tr><td>&#160;</td><td> <var class="pdparam">...</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1108352140"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>fmt</code></em></span></dt><dd><p>
4     the printf format for printing
5    </p></dd><dt><span class="term"><em class="parameter"><code>...</code></em></span></dt><dd><p>
6     variable arguments
7    </p></dd></dl></div></div><div class="refsect1"><a name="idp1108354756"></a><h2>Note</h2><p>
8   __trace_printk is an internal function for trace_printk and
9   the <em class="parameter"><code>ip</code></em> is passed in via the trace_printk macro.
10   </p><p>
11
12   This function allows a kernel developer to debug fast path sections
13   that printk is not appropriate for. By scattering in various
14   printk like tracing in the code, a developer can quickly see
15   where problems are occurring.
16   </p><p>
17
18   This is intended as a debugging tool for the developer only.
19   Please refrain from leaving trace_printks scattered around in
20   your code. (Extra memory is used for special buffers that are
21   allocated when <code class="function">trace_printk</code> is used)
22   </p><p>
23
24   A little optization trick is done here. If there's only one
25   argument, there's no need to scan the string for printf formats.
26   The <code class="function">trace_puts</code> will suffice. But how can we take advantage of
27   using <code class="function">trace_puts</code> when <code class="function">trace_printk</code> has only one argument?
28   By stringifying the args and checking the size we can tell
29   whether or not there are args. __stringify((__VA_ARGS__)) will
30   turn into <span class="quote">&#8220;<span class="quote">()\0</span>&#8221;</span> with a size of 3 when there are no args, anything
31   else will be bigger. All we need to do is define a string to this,
32   and then take its size and compare to 3. If it's bigger, use
33   <code class="function">do_trace_printk</code> otherwise, optimize it to <code class="function">trace_puts</code>. Then just
34   let gcc optimize the rest.
35</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-kstrtol.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="ch01s09.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="API-trace-puts.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">kstrtol</span>&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;<span class="phrase">trace_puts</span></td></tr></table></div></body></html>
36