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

Merge pull request iovisor#3691 from chenhengqi/add-mdflush #3

Merged
merged 30 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4f59913
libbpf-tools: Add mdflush
chenhengqi Nov 8, 2021
63103fa
bcc: add method to close file descriptors
terceiro Mar 22, 2022
9d06ced
tools/tcplife: Remove dead code
chenhengqi Jun 2, 2022
02f0f5a
Merge pull request #4032 from chenhengqi/cleanup-tcplife
davemarchevsky Jun 2, 2022
42a84ed
Fixed 'getElementType() is deprecated' compile warning.
Rtoax May 29, 2022
65efffe
tools/exitsnoop: Use task->real_parent instead of task->parent (#4025)
xingfeng2510 Jun 3, 2022
ae680db
tools/biolatency: Add disk filter support (#4026)
xingfeng2510 Jun 3, 2022
aad64e4
docs: Add missing entries for CGROUP_SOCK_ADDR family
chenhengqi Jun 2, 2022
9541c9c
sync with laest libbpf repo
yonghong-song Jun 3, 2022
730ced2
libbpf-tools: add support for cross compilation
May 13, 2022
67b8cfb
libbpf-tools/klockstat: Flush stdout after print_stats()
namhyung May 11, 2022
bfccfe6
libbpf-tools/klockstat: Print human friendly time stats
namhyung May 11, 2022
5e3d41e
libbpf-tools/klockstat: Add --per-thread/-P option
namhyung May 11, 2022
a184f09
libbpf-tools: Fix bio tools
chenhengqi Jun 10, 2022
70e8a9b
Merge pull request #3919 from terceiro/python-bpf-close
davemarchevsky Jun 13, 2022
45f5df4
libbpf-tools: Remove map flag BPF_F_NO_PREALLOC
chenhengqi Jun 10, 2022
8e608ed
Remove executable permissions and extra spaces for "funcinterval.8".
Rtoax Jun 14, 2022
e345542
Merge pull request #4049 from Rtoax/patch-17-funcinterval.8-x
davemarchevsky Jun 14, 2022
16eab39
Add tracepoint:skb:kfree_skb if no tcp_drop() kprobe.
Rtoax Jun 15, 2022
1c0808d
Fix: Failed to load BPF program b'trace_read_return': Permission denied
Rtoax Jun 15, 2022
37c3f97
libbpf-tools: fix tcpconnect build errors
aspsk Jun 15, 2022
e16b628
Add more hints for error kprobe.
Rtoax Jun 17, 2022
dbb7b83
Merge pull request #4055 from Rtoax/patch-21-warn-inlined
davemarchevsky Jun 17, 2022
e84e46f
sync with latest libbpf repo
chantra Jun 20, 2022
1900809
backport `struct bpf_create_map_attr`
chantra Jun 20, 2022
10e3cd4
tools/syscount: Beautify output of syscall list
xingfeng2510 Jun 21, 2022
13b5563
Merge pull request #4062 from chantra/remove_bpf_create_map
davemarchevsky Jun 21, 2022
a409bf5
Merge pull request #4050 from Rtoax/patch-18-tcpdrop-reason
davemarchevsky Jun 24, 2022
21e18d1
Merge pull request #4063 from xingfeng2510/enhance
davemarchevsky Jun 24, 2022
9627312
Merge pull request #3691 from chenhengqi/add-mdflush
davemarchevsky Jun 24, 2022
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
Prev Previous commit
Next Next commit
tools/biolatency: Add disk filter support (iovisor#4026)
Sometimes, I just want to focus on a specified disk rather than all disks or per-disk. Refer to libbpf-tools/biolatency, this patch try to add disk filter support.
  • Loading branch information
xingfeng2510 committed Jun 3, 2022
commit ae680dba6a9e49c8d876f980fcf704e45a8fbaf7
7 changes: 5 additions & 2 deletions man/man8/biolatency.8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.SH NAME
biolatency \- Summarize block device I/O latency as a histogram.
.SH SYNOPSIS
.B biolatency [\-h] [\-F] [\-T] [\-Q] [\-m] [\-D] [\-e] [interval [count]]
.B biolatency [\-h] [\-F] [\-T] [\-Q] [\-m] [\-D] [\-F] [\-e] [\-j] [\-d DISK] [interval [count]]
.SH DESCRIPTION
biolatency traces block device I/O (disk I/O), and records the distribution
of I/O latency (time). This is printed as a histogram either on Ctrl-C, or
Expand Down Expand Up @@ -42,6 +42,9 @@ Print a histogram dictionary
\-e
Show extension summary(total, average)
.TP
\-d DISK
Trace this disk only
.TP
interval
Output interval, in seconds.
.TP
Expand Down Expand Up @@ -108,6 +111,6 @@ Linux
.SH STABILITY
Unstable - in development.
.SH AUTHOR
Brendan Gregg
Brendan Gregg, Rocky Xing
.SH SEE ALSO
biosnoop(8)
36 changes: 35 additions & 1 deletion tools/biolatency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
# biolatency Summarize block device I/O latency as a histogram.
# For Linux, uses BCC, eBPF.
#
# USAGE: biolatency [-h] [-T] [-Q] [-m] [-D] [-F] [-e] [-j] [interval] [count]
# USAGE: biolatency [-h] [-T] [-Q] [-m] [-D] [-F] [-e] [-j] [-d DISK] [interval] [count]
#
# Copyright (c) 2015 Brendan Gregg.
# Licensed under the Apache License, Version 2.0 (the "License")
#
# 20-Sep-2015 Brendan Gregg Created this.
# 31-Mar-2022 Rocky Xing Added disk filter support.

from __future__ import print_function
from bcc import BPF
from time import sleep, strftime
import argparse
import ctypes as ct
import os

# arguments
examples = """examples:
Expand All @@ -27,6 +29,7 @@
./biolatency -F # show I/O flags separately
./biolatency -j # print a dictionary
./biolatency -e # show extension summary(total, average)
./biolatency -d sdc # Trace sdc only
"""
parser = argparse.ArgumentParser(
description="Summarize block device I/O latency as a histogram",
Expand All @@ -52,6 +55,8 @@
help=argparse.SUPPRESS)
parser.add_argument("-j", "--json", action="store_true",
help="json output")
parser.add_argument("-d", "--disk", type=str,
help="Trace this disk only")

args = parser.parse_args()
countdown = int(args.count)
Expand Down Expand Up @@ -87,6 +92,8 @@
// time block I/O
int trace_req_start(struct pt_regs *ctx, struct request *req)
{
DISK_FILTER

u64 ts = bpf_ktime_get_ns();
start.update(&req, &ts);
return 0;
Expand Down Expand Up @@ -149,6 +156,33 @@
storage_str += "BPF_HISTOGRAM(dist);"
store_str += "dist.atomic_increment(bpf_log2l(delta));"

if args.disk is not None:
disk_path = os.path.join('/dev', args.disk)
if not os.path.exists(disk_path):
print("no such disk '%s'" % args.disk)
exit(1)

stat_info = os.stat(disk_path)
major = os.major(stat_info.st_rdev)
minor = os.minor(stat_info.st_rdev)

disk_field_str = ""
if BPF.kernel_struct_has_field(b'request', b'rq_disk') == 1:
disk_field_str = 'req->rq_disk'
else:
disk_field_str = 'req->q->disk'

disk_filter_str = """
struct gendisk *disk = %s;
if (!(disk->major == %d && disk->first_minor == %d)) {
return 0;
}
""" % (disk_field_str, major, minor)

bpf_text = bpf_text.replace('DISK_FILTER', disk_filter_str)
else:
bpf_text = bpf_text.replace('DISK_FILTER', '')

if args.extension:
storage_str += "BPF_ARRAY(extension, ext_val_t, 1);"
bpf_text = bpf_text.replace('EXTENSION', """
Expand Down
26 changes: 14 additions & 12 deletions tools/biolatency_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,24 +352,25 @@ The -j with -m prints a millisecond histogram dictionary. The `value_type` key i
USAGE message:

# ./biolatency -h
usage: biolatency.py [-h] [-T] [-Q] [-m] [-D] [-F] [-j]
[interval] [count]
usage: biolatency.py [-h] [-T] [-Q] [-m] [-D] [-F] [-e] [-j] [-d DISK]
[interval] [count]

Summarize block device I/O latency as a histogram

positional arguments:
interval output interval, in seconds
count number of outputs
interval output interval, in seconds
count number of outputs

optional arguments:
-h, --help show this help message and exit
-T, --timestamp include timestamp on output
-Q, --queued include OS queued time in I/O time
-m, --milliseconds millisecond histogram
-D, --disks print a histogram per disk device
-F, --flags print a histogram per set of I/O flags
-e, --extension also show extension summary(total, average)
-j, --json json output
-h, --help show this help message and exit
-T, --timestamp include timestamp on output
-Q, --queued include OS queued time in I/O time
-m, --milliseconds millisecond histogram
-D, --disks print a histogram per disk device
-F, --flags print a histogram per set of I/O flags
-e, --extension summarize average/total value
-j, --json json output
-d DISK, --disk DISK Trace this disk only

examples:
./biolatency # summarize block I/O latency as a histogram
Expand All @@ -380,3 +381,4 @@ examples:
./biolatency -F # show I/O flags separately
./biolatency -j # print a dictionary
./biolatency -e # show extension summary(total, average)
./biolatency -d sdc # Trace sdc only