| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- $bpf_text = <<<EOT
- #include <uapi/linux/ptrace.h>
- #include <linux/blk-mq.h>
- BPF_HISTOGRAM(dist);
- BPF_HISTOGRAM(dist_linear);
- int trace_req_done(struct pt_regs *ctx, struct request *req)
- {
- dist.increment(bpf_log2l(req->__data_len / 1024));
- dist_linear.increment(req->__data_len / 1024);
- return 0;
- }
- EOT;
- $b = new Bpf(["text" => $bpf_text]);
- // Attach kprobe based on kernel version
- if ($b->get_kprobe_functions('__blk_account_io_done')) {
- // __blk_account_io_done is available before kernel v6.4
- $b->attach_kprobe('__blk_account_io_done', 'trace_req_done');
- } elseif ($b->get_kprobe_functions('blk_account_io_done')) {
- // blk_account_io_done is traceable (not inline) before v5.16
- $b->attach_kprobe('blk_account_io_done', 'trace_req_done');
- } else {
- $b->attach_kprobe('blk_mq_end_request', 'trace_req_done');
- }
- echo "Tracing... Hit Ctrl-C to end.\n";
- // Set up signal handler for Ctrl-C
- pcntl_signal(SIGINT, "signalHandler");
- pcntl_async_signals(true);
- // Keep running until interrupted
- while (true) {
- sleep(99999999);
- }
- function signalHandler($signo)
- {
- global $b;
- switch ($signo) {
- case SIGINT:
- echo "\n";
- echo "log2 histogram\n";
- echo "~~~~~~~~~~~~~~\n";
- $b->dist->print_log2_hist("kbytes");
- echo "\nlinear histogram\n";
- echo "~~~~~~~~~~~~~~~~\n";
- $b->dist_linear->print_linear_hist("kbytes");
- exit(0);
- }
- }
|