如何在tracepoint上註冊函數

register_trace_##name宏中node

tracepoint_probe_register在這個函數中在同一個cp上能夠掛多個處理函數,函數

查看函數:trace_block_rq_issue中定義了這個tracepoint以及tracepoint的鉤子函數code

tracepoint中給你輸入了trace_block_rq_issue(q, rq);其中q是request_queue,rq是struct request,這兩個東西是tracepoint提供給你的,全部的函數都可以獲得,這個函數的執行的流程是啥樣子的啊,鉤子函數中必定是要有void函數的,各路ftrace啥的都註冊了本身的函數,包括perf也是在函數中註冊了本身的函數,看下ftrace註冊的什麼函數呢,ftrace中確定是註冊了本身的特定的函數orm

kernel/trace/trace_events.c中有許多的鉤子函數blog

ftrace_enable_fopsget

ftrace_event_format_fopsit

__ftrace_event_enable_disable鉤子

使用牛逼的systemtap能夠垂手可得地獲得函數中的鉤子是啥:call->class->reg(call, TRACE_REG_UNREGISTER, file);event

獲得鉤子的地址是:trace_event_regast

而後鉤子函數是啥子咧,發現是是函數 trace_event_raw_event_block_rq_issue

這個函數是咋生成的呢?

都是在頭文件中生成的

./include/trace/events/f2fs.h

DECLARE_EVENT_CLASS在這個宏中會擴展函數trace_event_raw_event_block_rq_issue函數

以f2fs的declare_event_class函數中

122 DECLARE_EVENT_CLASS(f2fs__inode,
 123 
 124     TP_PROTO(struct inode *inode),
 125 
 126     TP_ARGS(inode),
 127 
 128     TP_STRUCT__entry(
 129         __field(dev_t,  dev)
 130         __field(ino_t,  ino)
 131         __field(ino_t,  pino)
 132         __field(umode_t, mode)
 133         __field(loff_t, size)
 134         __field(unsigned int, nlink)
 135         __field(blkcnt_t, blocks)
 136         __field(__u8,   advise)
 137     ),
 138 
 139     TP_fast_assign(
 140         __entry->dev    = inode->i_sb->s_dev;
 141         __entry->ino    = inode->i_ino;
 142         __entry->pino   = F2FS_I(inode)->i_pino;
 143         __entry->mode   = inode->i_mode;
 144         __entry->nlink  = inode->i_nlink;
 145         __entry->size   = inode->i_size;
 146         __entry->blocks = inode->i_blocks;
 147         __entry->advise = F2FS_I(inode)->i_advise;
 148     ),
 149 
 150     TP_printk("dev = (%d,%d), ino = %lu, pino = %lu, i_mode = 0x%hx, "
 151         "i_size = %lld, i_nlink = %u, i_blocks = %llu, i_advise = 0x%x",
 152         show_dev_ino(__entry),
 153         (unsigned long)__entry->pino,
 154         __entry->mode,
 155         __entry->size,
 156         (unsigned int)__entry->nlink,
 157         (unsigned long long)__entry->blocks,
 158         (unsigned char)__entry->advise)
 159 );

 函數中:

./include/trace/trace_events.h

664 static notrace void                         \
665 trace_event_raw_event_##call(void *__data, proto)           \
666 {                                   \
667     struct trace_event_file *trace_file = __data;           \
668     struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
669     struct trace_event_buffer fbuffer;              \
670     struct trace_event_raw_##call *entry;               \
671     int __data_size;                        \
672                                     \
673     if (trace_trigger_soft_disabled(trace_file))            \
674         return;                         \
675                                     \   
676     __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
677                                     \
678     entry = trace_event_buffer_reserve(&fbuffer, trace_file,    \
679                  sizeof(*entry) + __data_size);     \
680                                     \
681     if (!entry)                         \
682         return;                         \
683                                     \   
684     tstruct                             \
685                                     \   
686     { assign; }                         \
687                                     \   
688     trace_event_buffer_commit(&fbuffer);                \
689 }

 按說,ftrace的printk部分

perf註冊的函數是perf_trace_##call函數,include/trace/perf.h文件

相關文章
相關標籤/搜索