问题描述
在BPF Performance Tools一书中,有tcp_retransmit_skb的kprobe实现。我想做同样的事情,而不是tcp_retransmit_skb @tcp_states,我想kprobe _ napi_schedule并包含'include / linux / netdevice.h'的枚举NAPI_STATE *。以上是我的实现:
1 #!/usr/local/bin/bpftrace
2
3 #include <linux/netdevice.h>
4
5 kprobe:__napi_schedule
6 {
7 $ns = (struct napi_struct *)arg0;
8
9 // Poll is scheduled
10 @napi[1] = "NAPI_STATE_SCHED";
11 @napi[2] = "NAPI_STATE_disABLE";
12 @napi[3] = "NAPI_STATE_NPSVC";
13 @napi[4] = "NAPI_STATE_HASHED";
14 @napi[5] = "NAPI_STATE_NO_BUSY_POLL";
15
16
17 printf("-------------------\n");
18 printf("\n");
19 printf("__napi_schedule: %s pid: %d\n",comm,pid);
20 printf("\n");
21 $state = $ns->state;
22 printf("$ns->state: %d\n",$state);
23 $statestr = @napi[$state];
24 printf("state is: %s\n",$statestr);
25 clear(@napi);
26 printf("--------------------\n");
27 }
当我尝试运行它时,它在我的printf中没有显示“状态为”。
输出为:
...
__napi_schedule: tmux: server pid: 9003
$ns->state: 17
state is:
--------------------
-------------------
__napi_schedule: tmux: server pid: 9003
$ns->state: 17
state is:
--------------------
-------------------
__napi_schedule: tmux: server pid: 9003
$ns->state: 17
state is:
--------------------
...
解决方法
$ns->state
是一个位数组,因此值17实际上是(1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED)
。
您将需要遍历位以解析值并显示等效的字符串。