urandomread-explicit.php 674 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. $bpf_text = <<<EOT
  3. #include <uapi/linux/ptrace.h>
  4. struct urandom_read_args {
  5. u64 __unused__;
  6. u32 got_bits;
  7. u32 pool_left;
  8. u32 input_left;
  9. };
  10. int printarg(struct urandom_read_args *args) {
  11. bpf_trace_printk("%d\\n", args->got_bits);
  12. return 0;
  13. }
  14. EOT;
  15. $b = new Bpf(["text" => $bpf_text]);
  16. $b->attach_tracepoint("random:urandom_read", "printarg");
  17. echo sprintf("%-18s %-16s %-6s %s\n", "TIME(s)", "COMM", "PID", "GOTBITS");
  18. while (true) {
  19. try {
  20. list($task, $pid, $cpu, $flags, $ts, $msg) = $ebpf->trace_fields();
  21. printf("%-18.9f %-16s %-6d %s\n", $ts, $task, $pid, $msg);
  22. } catch (Exception $e) {
  23. break;
  24. }
  25. }