[RFC]Sample module for Kernel access to Ftrace instances.

From: Divya Indi
Date: Fri Sep 20 2019 - 20:00:07 EST


[PATCH] tracing: Sample module to demonstrate kernel access to Ftrace

Hi,

This patch is for a sample module to demonstrate the use of APIs that
were introduced/exported in order to access Ftrace instances from within the kernel.

Please Note: This module is dependent on -
- commit: f45d122 tracing: Kernel access to Ftrace instances
- Patches pending review: https://lore.kernel.org/lkml/1565805327-579-1-git-send-email-divya.indi@xxxxxxxxxx/

The sample module creates/lookup a trace array called sample-instance on module load time.
We then start a kernel thread(simple-thread) to -
1) Enable tracing for event "sample_event" to buffer associated with the trace array - "sample-instance".
2) Start a timer that will disable tracing to this buffer after 5 sec. (Tracing disabled after 5 sec ie at count=4)
3) Write to the buffer using trace_array_printk()
4) Stop the kernel thread and destroy the buffer during module unload.

A sample output for the same -

# tracer: nop
#
# entries-in-buffer/entries-written: 16/16 #P:4
#
# _-----=> irqs-off
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth
# ||| / delay
# TASK-PID CPU# |||| TIMESTAMP FUNCTION
# | | | |||| | |
sample-instance-26797 [003] .... 955180.489833: simple_thread: trace_array_printk: count=0
sample-instance-26797 [003] .... 955180.489836: sample_event: count value=0 at jiffies=5249940864
sample-instance-26797 [003] .... 955181.513722: simple_thread: trace_array_printk: count=1
sample-instance-26797 [003] .... 955181.513724: sample_event: count value=1 at jiffies=5249941888
sample-instance-26797 [003] .... 955182.537629: simple_thread: trace_array_printk: count=2
sample-instance-26797 [003] .... 955182.537631: sample_event: count value=2 at jiffies=5249942912
sample-instance-26797 [003] .... 955183.561516: simple_thread: trace_array_printk: count=3
sample-instance-26797 [003] .... 955183.561518: sample_event: count value=3 at jiffies=5249943936
sample-instance-26797 [003] .... 955184.585423: simple_thread: trace_array_printk: count=4
sample-instance-26797 [003] .... 955184.585427: sample_event: count value=4 at jiffies=5249944960
sample-instance-26797 [003] .... 955185.609344: simple_thread: trace_array_printk: count=5
sample-instance-26797 [003] .... 955186.633241: simple_thread: trace_array_printk: count=6
sample-instance-26797 [003] .... 955187.657157: simple_thread: trace_array_printk: count=7
sample-instance-26797 [003] .... 955188.681039: simple_thread: trace_array_printk: count=8
sample-instance-26797 [003] .... 955189.704937: simple_thread: trace_array_printk: count=9
sample-instance-26797 [003] .... 955190.728840: simple_thread: trace_array_printk: count=10

Let me know if you have any questions.

Thanks,
Divya