blob: cd309b4f2e86941836db3b5dab9211392eca03f9 [file] [log] [blame]
Brendan Greggebdb2422015-08-18 16:53:41 -07001#!/usr/bin/python
Brendan Gregg48fbc3e2015-08-18 14:56:14 -07002#
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 Gregg48fbc3e2015-08-18 14:56:14 -07008# 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 Blancoc35989d2015-09-02 18:04:07 -070016from bcc import BPF
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070017from time import sleep
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070018
19# load BPF program
20b = BPF(src_file = "bitehist.c")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070021
22# header
23print("Tracing... Hit Ctrl-C to end.")
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070024
Brendan Gregg0823f562015-09-25 11:07:35 -070025# trace until Ctrl-C
Brendan Greggf32a67c2015-09-07 14:42:12 -070026try:
27 sleep(99999999)
28except KeyboardInterrupt:
Brendan Gregg48fbc3e2015-08-18 14:56:14 -070029 print
Brendan Greggf32a67c2015-09-07 14:42:12 -070030
Brendan Gregg0823f562015-09-25 11:07:35 -070031# output
Brendan Gregg665c5b02015-09-21 11:55:52 -070032b["dist"].print_log2_hist("kbytes")