---
name: "trace_printk"
section: "9"
platform: "linux"
package: "linux-manual-3.16"
version: "3.16.56-1+deb8u1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/trace_printk"
---

# trace\_printk(9)

printf formatting in the ftrace buffer

## NAME

trace\_printk - printf formatting in the ftrace buffer

## SYNOPSIS

**trace\_printk(***fmt***,** *...***);**

## ARGUMENTS

*fmt*

the printf format for printing

*...*

variable arguments

## NOTE

\_\_trace\_printk is an internal function for trace\_printk and the *ip* is passed in via the trace\_printk macro.

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.

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 **trace\_printk** is used)

A little optization trick is done here. If there's only one argument, there's no need to scan the string for printf formats. The **trace\_puts** will suffice. But how can we take advantage of using **trace\_puts** when **trace\_printk** 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 “()\\0” 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's bigger, use **do\_trace\_printk** otherwise, optimize it to **trace\_puts**. Then just let gcc optimize the rest.

## COPYRIGHT
