| # strlen_hist.py Histogram of system-wide strlen return values |
| # A basic example of using uprobes along with a histogram to show |
| # Runs until ctrl-c is pressed. |
| # Copyright (c) PLUMgrid, Inc. |
| # Licensed under the Apache License, Version 2.0 (the "License") |
| # $ sudo ./strlen_hist.py |
| # strlen return: : count distribution |
| # 0 -> 1 : 2106 |**************** | |
| # 2 -> 3 : 1172 |********* | |
| # 4 -> 7 : 3892 |****************************** | |
| # 8 -> 15 : 5096 |****************************************| |
| # 16 -> 31 : 2201 |***************** | |
| from __future__ import print_function |
| #include <uapi/linux/ptrace.h> |
| int count(struct pt_regs *ctx) { |
| dist.increment(bpf_log2l(PT_REGS_RC(ctx))); |
| b.attach_uretprobe(name="c", sym=sym, fn_name="count") |
| print("%-8s\n" % time.strftime("%H:%M:%S"), end="") |
| dist.print_log2_hist(sym + " return:") |
| except KeyboardInterrupt: |