0

在 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:
--------------------
...
4

1 回答 1

1

$ns->state是一个位数组,所以值 17 实际上是(1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED).

您将需要逐位解析值并显示等效字符串。

于 2020-08-27T11:14:23.100 回答