uprobe.php 664 B

123456789101112131415161718192021222324252627
  1. <?php
  2. $bpf_text = <<<EOT
  3. #include <uapi/linux/ptrace.h>
  4. int test(struct pt_regs *ctx)
  5. {
  6. bpf_trace_printk("%d---%d\\n",ctx->di,ctx->si);
  7. return 1;
  8. }
  9. EOT;
  10. $ebpf = new Ebpf($bpf_text);
  11. // $arr = array("pid"=>-1);
  12. $ebpf->attach_uprobe("/opt/github/phpcpp_helloworld/a.out","add","test",[]);
  13. // $ebpf->trace_print();
  14. # header
  15. printf("%-18s %-16s %-6s %s\n", "TIME(s)", "COMM", "PID", "MESSAGE");
  16. # format output
  17. while (true) {
  18. try {
  19. list($task, $pid, $cpu, $flags, $ts, $msg) = $ebpf->trace_fields();
  20. printf("%-18.9f %-16s %-6d %s\n", $ts, $task, $pid, $msg);
  21. flush();
  22. } catch (Exception $e) {
  23. continue;
  24. }
  25. }