From 310ab53710cfd46095c1f6b3e44f1dbc8d1a41d8 Mon Sep 17 00:00:00 2001 From: Brendan Gregg Date: Sun, 24 Jul 2016 13:34:40 -0700 Subject: [PATCH] merge bitehist example --- README.md | 9 ++++----- examples/tracing/bitehist.c | 22 ---------------------- examples/tracing/bitehist.py | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 29 deletions(-) delete mode 100644 examples/tracing/bitehist.c diff --git a/README.md b/README.md index 44d4bc7b6b16..ded4d9e72075 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,9 @@ Tracing... Hit Ctrl-C to end. The above output shows a bimodal distribution, where the largest mode of 800 I/O was between 128 and 255 Kbytes in size. -See the source: [bitehist.c](examples/tracing/bitehist.c) and -[bitehist.py](examples/tracing/bitehist.py). What this traces, what this stores, and how -the data is presented, can be entirely customized. This shows only some of -many possible capabilities. +See the source: [bitehist.py](examples/tracing/bitehist.py). What this traces, +what this stores, and how the data is presented, can be entirely customized. +This shows only some of many possible capabilities. ## Installing @@ -60,7 +59,7 @@ pair of .c and .py files, and some are directories of files. Examples: -- examples/tracing/[bitehist.py](examples/tracing/bitehist.py) examples/tracing/[bitehist.c](examples/tracing/bitehist.c): Block I/O size histogram. [Examples](examples/tracing/bitehist_example.txt). +- examples/tracing/[bitehist.py](examples/tracing/bitehist.py): Block I/O size histogram. [Examples](examples/tracing/bitehist_example.txt). - examples/tracing/[disksnoop.py](examples/tracing/disksnoop.py) examples/tracing/[disksnoop.c](examples/tracing/disksnoop.c): Trace block device I/O latency. [Examples](examples/tracing/disksnoop_example.txt). - examples/[hello_world.py](examples/hello_world.py): Prints "Hello, World!" for new processes. - examples/tracing/[tcpv4connect.py](examples/tracing/tcpv4connect.py): Trace TCP IPv4 active connections. [Examples](examples/tracing/tcpv4connect_example.txt). diff --git a/examples/tracing/bitehist.c b/examples/tracing/bitehist.c deleted file mode 100644 index 102ee4db9801..000000000000 --- a/examples/tracing/bitehist.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * bitehist.c Block I/O size histogram. - * For Linux, uses BCC, eBPF. See .py file. - * - * Copyright (c) 2013-2015 PLUMgrid, http://plumgrid.com - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * 15-Aug-2015 Brendan Gregg Created this. - */ - -#include -#include - -BPF_HISTOGRAM(dist); - -int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req) -{ - dist.increment(bpf_log2l(req->__data_len / 1024)); - return 0; -} diff --git a/examples/tracing/bitehist.py b/examples/tracing/bitehist.py index cd309b4f2e86..1dee5dc05937 100755 --- a/examples/tracing/bitehist.py +++ b/examples/tracing/bitehist.py @@ -1,7 +1,7 @@ #!/usr/bin/python # # bitehist.py Block I/O size histogram. -# For Linux, uses BCC, eBPF. See .c file. +# For Linux, uses BCC, eBPF. Embedded C. # # Written as a basic example of using a histogram to show a distribution. # @@ -17,7 +17,18 @@ from time import sleep # load BPF program -b = BPF(src_file = "bitehist.c") +b = BPF(text=""" +#include +#include + +BPF_HISTOGRAM(dist); + +int kprobe__blk_account_io_completion(struct pt_regs *ctx, struct request *req) +{ + dist.increment(bpf_log2l(req->__data_len / 1024)); + return 0; +} +""") # header print("Tracing... Hit Ctrl-C to end.")