| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- $prog = <<<EOT
- BPF_TASK_STORAGE(task_storage_map, __u64);
- KFUNC_PROBE(inet_listen)
- {
- __u64 ts = bpf_ktime_get_ns();
- /* save timestamp to local storage on function entry */
- task_storage_map.task_storage_get(bpf_get_current_task_btf(), &ts, BPF_LOCAL_STORAGE_GET_F_CREATE);
- bpf_trace_printk("inet_listen entry: store timestamp %lld", ts);
- return 0;
- }
- KRETFUNC_PROBE(inet_listen)
- {
- __u64 *ts;
- /* retrieve timestamp stored at local storage on function exit */
- ts = task_storage_map.task_storage_get(bpf_get_current_task_btf(), 0, 0);
- if (!ts)
- return 0;
- /* delete timestamp from local storage */
- task_storage_map.task_storage_delete(bpf_get_current_task_btf());
- /* calculate latency */
- bpf_trace_printk("inet_listen exit: cost %lldus", (bpf_ktime_get_ns() - *ts) / 1000);
- return 0;
- }
- EOT;
- # load BPF program
- $ebpf = new Bpf(["text" => $prog]);
- # format output
- while (true) {
- try {
- $ebpf->trace_print();
- } catch (Exception $e) {
- continue;
- }
- }
|