• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2#
3# bitehist.py	Block I/O size histogram.
4#		For Linux, uses BCC, eBPF. Embedded C.
5#
6# Written as a basic example of using a histogram to show a distribution.
7#
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
16from __future__ import print_function
17from bcc import BPF
18from time import sleep
19
20# load BPF program
21b = BPF(text="""
22#include <uapi/linux/ptrace.h>
23#include <linux/blkdev.h>
24
25BPF_HISTOGRAM(dist);
26
27int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req)
28{
29	dist.increment(bpf_log2l(req->__data_len / 1024));
30	return 0;
31}
32""")
33
34# header
35print("Tracing... Hit Ctrl-C to end.")
36
37# trace until Ctrl-C
38try:
39	sleep(99999999)
40except KeyboardInterrupt:
41	print()
42
43# output
44b["dist"].print_log2_hist("kbytes")
45