ftrace code
ftrace event kmem:rss_stat
trace event definition
include/trace/events/kmem.h
TRACE_EVENT(rss_stat, TP_PROTO(struct mm_struct *mm, int member, long count), TP_ARGS(mm, member, count), TP_STRUCT__entry( __field(unsigned int, mm_id) __field(unsigned int, curr) __field(int, member) __field(long, size) ), TP_fast_assign( __entry->mm_id = mm_ptr_to_hash(mm); __entry->curr = !!(current->mm == mm); __entry->member = member; __entry->size = (count << PAGE_SHIFT); ), TP_printk("mm_id=%u curr=%d type=%s size=%ldB", __entry->mm_id, __entry->curr, __print_symbolic(__entry->member, TRACE_MM_PAGES), __entry->size) );
上面TP_PROTO定义了参数列表,实际调用例子如下trace_rss_stat(mm, member, count)
上面TP_printk()定义了此trace event输出log的格式,在对应的trace event目录下的format就是来自于这里的定义。
上面TP_fast_assign()对TP_printk()里打印的变量进行赋值。
mm/memory.c
#define TRACE_MM_COUNTER_THRESHOLD 128 void mm_trace_rss_stat(struct mm_struct *mm, int member, long count, long value) { long thresh_mask = ~(TRACE_MM_COUNTER_THRESHOLD - 1); /* Threshold roll-over, trace it */ if ((count & thresh_mask) != ((count - value) & thresh_mask)) trace_rss_stat(mm, member, count); }
name: rss_stat ID: 416 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; size:1; signed:0; field:int common_pid; offset:4; size:4; signed:1; field:unsigned int mm_id; offset:8; size:4; signed:0; field:unsigned int curr; offset:12; size:4; signed:0; field:int member; offset:16; size:4; signed:1; field:long size; offset:24; size:8; signed:1; print fmt: "mm_id=%u curr=%d member=%d size=%ldB", REC->mm_id, REC->curr, REC->member, REC->size
注:上面ID: 416是表示rss_stat traceevent的ID,ID是全局编号的。