Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitesize: switch to tracepoints #2281

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bitesize: switch to tracepoints
  • Loading branch information
brendangregg committed Mar 20, 2019
commit f7148cc7c0d99f2bc76067b516af1ae5040c6550
5 changes: 2 additions & 3 deletions man/man8/bitesize.8
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ bitesize \- Summarize block device I/O size as a histogram \- Linux eBPF/bcc.
.SH DESCRIPTION
Show I/O distribution for requested block sizes, by process name.

This works by tracing block I/O kernel functions using dynamic
tracing and prints a historgram of I/O size.
This works by tracing block:block_rq_insert and prints a historgram of I/O size.

Since this uses BPF, only the root user can use this tool.
.SH REQUIREMENTS
Expand All @@ -29,7 +28,7 @@ distribution
An ASCII bar chart to visualize the distribution (count column)

.SH OVERHEAD
This traces kernel block I/O functions to update a histgroam, which are
This traces a block I/O tracepoint to update a histogram, which is
asynchronously copied to user-space. This method is very efficient, and
the overhead for most storage I/O rates (< 10k IOPS) should be negligible.
If you have a higher IOPS storage environment, test and quantify the overhead
Expand Down
37 changes: 6 additions & 31 deletions tools/bitesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 05-Feb-2016 Allan McAleavy ran pep8 against file
# 19-Mar-2019 Brendan Gregg Switched to use tracepoints.

from bcc import BPF
from time import sleep
Expand All @@ -24,47 +25,21 @@
u64 slot;
};

struct val_t {
char name[TASK_COMM_LEN];
};

BPF_HISTOGRAM(dist, struct proc_key_t);
BPF_HASH(commbyreq, struct request *, struct val_t);

int trace_pid_start(struct pt_regs *ctx, struct request *req)
{
struct val_t val = {};

if (bpf_get_current_comm(&val.name, sizeof(val.name)) == 0) {
commbyreq.update(&req, &val);
}
return 0;
}

int do_count(struct pt_regs *ctx, struct request *req)
TRACEPOINT_PROBE(block, block_rq_insert)
{
struct val_t *valp;

valp = commbyreq.lookup(&req);
if (valp == 0) {
return 0;
}

if (req->__data_len > 0) {
struct proc_key_t key = {.slot = bpf_log2l(req->__data_len / 1024)};
bpf_probe_read(&key.name, sizeof(key.name),valp->name);
dist.increment(key);
}
struct proc_key_t key = {.slot = bpf_log2l(args->bytes / 1024)};
bpf_probe_read(&key.name, sizeof(key.name), args->comm);
dist.increment(key);
return 0;
}
"""

# load BPF program
b = BPF(text=bpf_text)
b.attach_kprobe(event="blk_account_io_start", fn_name="trace_pid_start")
b.attach_kprobe(event="blk_account_io_completion", fn_name="do_count")

print("Tracing... Hit Ctrl-C to end.")
print("Tracing block I/O... Hit Ctrl-C to end.")

# trace until Ctrl-C
dist = b.get_table("dist")
Expand Down