使用ftrace的方法

有两种方法使用 ftrace:

  1. 使用 tracer

The Tracers

Here is the list of current tracers that may be configured.

“function”

Function call tracer to trace all kernel functions.

“function_graph”

Similar to the function tracer except that the
function tracer probes the functions on their entry
whereas the function graph tracer traces on both entry
and exit of the functions. It then provides the ability
to draw a graph of function calls similar to C code
source.

“irqsoff”

Traces the areas that disable interrupts and saves
the trace with the longest max latency.
See tracing_max_latency. When a new max is recorded,
it replaces the old trace. It is best to view this
trace with the latency-format option enabled.

“preemptoff”

Similar to irqsoff but traces and records the amount of
time for which preemption is disabled.

“preemptirqsoff”

Similar to irqsoff and preemptoff, but traces and
records the largest time for which irqs and/or preemption
is disabled.

“wakeup”

Traces and records the max latency that it takes for
the highest priority task to get scheduled after
it has been woken up.
    Traces all tasks as an average developer would expect.

“wakeup_rt”

    Traces and records the max latency that it takes for just
    RT tasks (as the current "wakeup" does). This is useful
    for those interested in wake up timings of RT tasks.

“nop”

This is the "trace nothing" tracer. To remove all
tracers from tracing simply echo "nop" into
current_tracer.

2. 使用event 
Tracepoints (see Documentation/trace/tracepoints.txt) can be used 
without creating custom kernel modules to register probe functions 
using the event tracing infrastructure.

Not all tracepoints can be traced using the event tracing system; 
the kernel developer must provide code snippets which define how the 
tracing information is saved into the tracing buffer, and how the 
tracing information should be printed. 
依赖tracepoints的event.

Via the ‘set_event’ interface

The events which are available for tracing can be found in the file 
/sys/kernel/debug/tracing/available_events.

To enable a particular event, such as ‘sched_wakeup’, simply echo it 
to /sys/kernel/debug/tracing/set_event. For example:

# echo sched_wakeup >> /sys/kernel/debug/tracing/set_event

4. Event formats
================


Each trace event has a 'format' file associated with it that contains
a description of each field in a logged event.  This information can
be used to parse the binary trace stream,
For example, here's the information displayed for the 'sched_wakeup'
event:


# cat /sys/kernel/debug/tracing/events/sched/sched_wakeup/format


name: sched_wakeup
ID: 60
format:
	field:unsigned short common_type;	offset:0;	size:2;
	field:unsigned char common_flags;	offset:2;	size:1;
	field:unsigned char common_preempt_count;	offset:3;	size:1;
	field:int common_pid;	offset:4;	size:4;
	field:int common_tgid;	offset:8;	size:4;


	field:char comm[TASK_COMM_LEN];	offset:12;	size:16;
	field:pid_t pid;	offset:28;	size:4;
	field:int prio;	offset:32;	size:4;
	field:int success;	offset:36;	size:4;
	field:int cpu;	offset:40;	size:4;


print fmt: "task %s:%d [%d] success=%d [%03d]", REC->comm, REC->pid,
	   REC->prio, REC->success, REC->cpu

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值