| 123456789101112131415161718192021222324252627 |
- <?php
- $bpf_text = <<<EOT
- #include <uapi/linux/ptrace.h>
- int test(struct pt_regs *ctx)
- {
- bpf_trace_printk("%d---%d\\n",ctx->di,ctx->si);
- return 1;
- }
- EOT;
- $ebpf = new Bpf(["text" => $bpf_text]);
- // $arr = array("pid"=>-1);
- $ebpf->attach_uprobe("/opt/github/phpcpp_helloworld/a.out","add","test",[]);
- // $ebpf->trace_print();
- # header
- printf("%-18s %-16s %-6s %s\n", "TIME(s)", "COMM", "PID", "MESSAGE");
- # format output
- while (true) {
- try {
- list($task, $pid, $cpu, $flags, $ts, $msg) = $ebpf->trace_fields();
- printf("%-18.9f %-16s %-6d %s\n", $ts, $task, $pid, $msg);
- flush();
- } catch (Exception $e) {
- continue;
- }
- }
|