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 | # |
| 3 | # bitehist.py Block I/O size histogram. |
| 4 | # For Linux, uses BCC, eBPF. See .c file. |
| 5 | # |
| 6 | # Written as a basic example of using a histogram to show a distribution. |
| 7 | # |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 8 | # The default interval is 5 seconds. A Ctrl-C will print the partially |
| 9 | # gathered histogram then exit. |
| 10 | # |
| 11 | # Copyright (c) 2015 Brendan Gregg. |
| 12 | # Licensed under the Apache License, Version 2.0 (the "License") |
| 13 | # |
| 14 | # 15-Aug-2015 Brendan Gregg Created this. |
| 15 | |
Brenden Blanco | c35989d | 2015-09-02 18:04:07 -0700 | [diff] [blame] | 16 | from bcc import BPF |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 17 | from time import sleep |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 18 | |
| 19 | # load BPF program |
| 20 | b = BPF(src_file = "bitehist.c") |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 21 | |
| 22 | # header |
| 23 | print("Tracing... Hit Ctrl-C to end.") |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 24 | |
Brendan Gregg | 0823f56 | 2015-09-25 11:07:35 -0700 | [diff] [blame] | 25 | # trace until Ctrl-C |
Brendan Gregg | f32a67c | 2015-09-07 14:42:12 -0700 | [diff] [blame] | 26 | try: |
| 27 | sleep(99999999) |
| 28 | except KeyboardInterrupt: |
Brendan Gregg | 48fbc3e | 2015-08-18 14:56:14 -0700 | [diff] [blame] | 29 | print |
Brendan Gregg | f32a67c | 2015-09-07 14:42:12 -0700 | [diff] [blame] | 30 | |
Brendan Gregg | 0823f56 | 2015-09-25 11:07:35 -0700 | [diff] [blame] | 31 | # output |
Brendan Gregg | 665c5b0 | 2015-09-21 11:55:52 -0700 | [diff] [blame] | 32 | b["dist"].print_log2_hist("kbytes") |