Brendan Gregg | ebdb242 | 2015-08-18 16:53:41 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 2 | # |
Brendan Gregg | 4cbdef7 | 2015-08-29 14:53:22 +1000 | [diff] [blame] | 3 | # vfscount Count VFS calls ("vfs_*"). |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 4 | # For Linux, uses BCC, eBPF. See .c file. |
| 5 | # |
| 6 | # Written as a basic example of counting functions. |
| 7 | # |
| 8 | # Copyright (c) 2015 Brendan Gregg. |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License") |
| 10 | # |
| 11 | # 14-Aug-2015 Brendan Gregg Created this. |
| 12 | |
Brendan Gregg | 762b1b4 | 2015-08-18 16:49:48 -0700 | [diff] [blame] | 13 | from __future__ import print_function |
Brenden Blanco | c35989d | 2015-09-02 18:04:07 -0700 | [diff] [blame] | 14 | from bcc import BPF |
Brendan Gregg | d21af64 | 2015-09-04 17:42:51 -0700 | [diff] [blame] | 15 | from time import sleep |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 16 | |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 17 | # load BPF program |
| 18 | b = BPF(src_file = "vfscount.c") |
Brendan Gregg | 4cbdef7 | 2015-08-29 14:53:22 +1000 | [diff] [blame] | 19 | b.attach_kprobe(event_re="^vfs_.*", fn_name="do_count") |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 20 | |
| 21 | # header |
Brendan Gregg | 762b1b4 | 2015-08-18 16:49:48 -0700 | [diff] [blame] | 22 | print("Tracing... Ctrl-C to end.") |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 23 | |
| 24 | # output |
| 25 | try: |
| 26 | sleep(99999999) |
| 27 | except KeyboardInterrupt: |
| 28 | pass |
| 29 | |
Brendan Gregg | 4cbdef7 | 2015-08-29 14:53:22 +1000 | [diff] [blame] | 30 | print("\n%-16s %-26s %8s" % ("ADDR", "FUNC", "COUNT")) |
Brendan Gregg | 057b078 | 2015-08-20 12:40:37 -0700 | [diff] [blame] | 31 | counts = b.get_table("counts") |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 32 | for k, v in sorted(counts.items(), key=lambda counts: counts[1].value): |
Brendan Gregg | 921008e | 2015-08-29 15:14:07 +1000 | [diff] [blame] | 33 | print("%-16x %-26s %8d" % (k.ip, b.ksym(k.ip), v.value)) |