public
Demo1
linux/debug/ftrace/demo1.md
Concept Flow
Concept flow
1echo workqueue:workqueuequeuework > /sys/kernel/debug/tracing/setevent
2cat /sys/kernel/debug/tracing/tracepipe > /tmp/trace.log
echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event
cat /sys/kernel/debug/tracing/trace_pipe > /tmp/trace.log
The commands you provided are used to trace kernel events using the ftrace framework in the Linux kernel. Here is an explanation of what each command does and how to use them effectively.
Commands Breakdown:
-
Enable specific trace events:
echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event- This command enables tracing for the
workqueue_queue_workevent, which is part of theworkqueuesubsystem. - Writing the event name to
/sys/kernel/debug/tracing/set_eventadds it to the list of events to be traced.
- This command enables tracing for the
-
Capture trace output:
cat /sys/kernel/debug/tracing/trace_pipe > /tmp/trace.log- This command continuously reads from the
trace_pipefile, which contains real-time trace output. - Redirecting the output to
/tmp/trace.logsaves the trace data to a file.
- This command continuously reads from the
Steps to Perform Tracing:
-
Enable the trace event:
echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event -
Start capturing the trace output:
cat /sys/kernel/debug/tracing/trace_pipe > /tmp/trace.log- You might want to run this command in the background so you can continue working in the terminal. To do this, you can append
&at the end of the command:cat /sys/kernel/debug/tracing/trace_pipe > /tmp/trace.log &
- You might want to run this command in the background so you can continue working in the terminal. To do this, you can append
-
Perform the actions that you want to trace:
- At this point, perform any actions or run any workload that you want to trace. The events related to
workqueue_queue_workwill be captured.
- At this point, perform any actions or run any workload that you want to trace. The events related to
-
Stop capturing the trace output:
- To stop the tracing, you can kill the background
catprocess. First, find the process ID (PID) of thecatcommand:jobs -l - This will list the background jobs along with their PIDs. Then, kill the process using the PID:
kill <PID>
- To stop the tracing, you can kill the background
-
Analyze the trace log:
- Open
/tmp/trace.logto view and analyze the captured trace events:less /tmp/trace.log - Use text processing tools like
grep,awk, or any other log analysis tools to filter and analyze the trace data.
- Open
Example Workflow:
-
Enable tracing:
echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event -
Start tracing (in the background):
cat /sys/kernel/debug/tracing/trace_pipe > /tmp/trace.log & -
Perform actions that generate
workqueue_queue_workevents. -
Stop tracing:
jobs -l kill <PID> -
Analyze the trace log:
less /tmp/trace.log
By following these steps, you can effectively trace and analyze specific kernel events related to workqueues or any other subsystem you are interested in.