调查事件的格式
可以从各事件的format特殊文件中查看各事件中记录的信息和该信息的显示格式等。
[tracing]#cat events/irq/irq_handler_entry/format
name:irq_handler_entry
ID:98
format:
field:unsigned short common_type;offset:0;size:2;signed:0;
field:unsigned char common_flags;offset:2;size:1;signed:0;
field:unsigned char common_preempt_count;offset:3;s i z e:1;
signed:0;
field:int common_pid;offset:4;size:4;signed:1;
field:int common_lock_depth;offset:8;size:4;signed:1;
field:int irq;offset:12;size:4;signed:1;
field:__data_loc char[]name;offset:16;size:4;signed:1;
print fmt:"irq=%d name=%s",REC->irq,__get_str(name)
这个格式中同时记录了ftrace将事件记录到缓冲区时的二进制格式信息、用户将事件读出为文本信息时的格式信息(见表8-10)。
二进制格式信息在field:后面分别显示各参数的(C语言的)类型名称、项上的变量名称、离入口开头的字节偏移量、字节大小、变量是否带符号。各参数的类型名称基本与C语言的类型名称相同,因此这个入口的内存映像与下列结构基本相同。
struct irq_handler_entry_structure{
unsigned short common_type;
unsigned char common_flags;
unsigned char common_preempt_count;
int common_pid;
int common_lock_depth;
int irq;
char*name;
}attribute((__packed));
可以看出,字段的定义分为上面5个字段和其他字段。空行上方为所有事件共同的变量,空行下方为这个事件特有的变量。追踪事件共同的变量具有下列意义(见表8-11)。
如果有内核的源代码,还可以查看各事件特有变量的意义。例如,irq_handler_entry事件在内核源码树的include/trace/events/irq.h下写有下列命令。
/**
*irq_handler_entry-called immediately before the irq action handler
*@irq:irq number
*@action:pointer to struct irqaction
*
*The struct irqaction pointed to by@action contains various
*information about the handler, including the device name,
*@action->name, and the device id,@action->dev_id.When used in
*conjunction with the irq_handler_exit tracepoint, we can figure
*out irq handler latencies.
*/
但是,这里有一点需要注意。上述注释并不是irq_handler_entry追踪事件的注释,而是内核内部使用的API的注释,因此参数有一些不同。要调查各追踪事件的参数相当于API的哪个参数,需要阅读各个事件的代码。在这个示例中,备注中的@action->name在追踪事件中为name。