Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
9894e3e0
Commit
9894e3e0
authored
Jul 24, 2016
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge disksnoop example
parent
310ab537
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
38 deletions
+28
-38
README.md
README.md
+1
-1
examples/tracing/disksnoop.c
examples/tracing/disksnoop.c
+0
-35
examples/tracing/disksnoop.py
examples/tracing/disksnoop.py
+27
-2
No files found.
README.md
View file @
9894e3e0
...
...
@@ -60,7 +60,7 @@ pair of .c and .py files, and some are directories of files.
Examples:
-
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/tracing/
[
disksnoop.py
](
examples/tracing/disksnoop.py
)
: 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
)
.
-
examples/tracing/
[
trace_fields.py
](
examples/tracing/trace_fields.py
)
: Simple example of printing fields from traced events.
...
...
examples/tracing/disksnoop.c
deleted
100644 → 0
View file @
310ab537
/*
* disksnoop.c Trace block device I/O: basic version of iosnoop.
* For Linux, uses BCC, eBPF. See .py file.
*
* Copyright (c) 2015 Brendan Gregg.
* 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.
*
* 11-Aug-2015 Brendan Gregg Created this.
*/
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
BPF_HASH
(
start
,
struct
request
*
);
void
trace_start
(
struct
pt_regs
*
ctx
,
struct
request
*
req
)
{
// stash start timestamp by request ptr
u64
ts
=
bpf_ktime_get_ns
();
start
.
update
(
&
req
,
&
ts
);
}
void
trace_completion
(
struct
pt_regs
*
ctx
,
struct
request
*
req
)
{
u64
*
tsp
,
delta
;
tsp
=
start
.
lookup
(
&
req
);
if
(
tsp
!=
0
)
{
delta
=
bpf_ktime_get_ns
()
-
*
tsp
;
bpf_trace_printk
(
"%d %x %d
\n
"
,
req
->
__data_len
,
req
->
cmd_flags
,
delta
/
1000
);
start
.
delete
(
&
req
);
}
}
examples/tracing/disksnoop.py
View file @
9894e3e0
#!/usr/bin/python
#
# disksnoop.py Trace block device I/O: basic version of iosnoop.
# For Linux, uses BCC, eBPF.
See .c file
.
# For Linux, uses BCC, eBPF.
Embedded C
.
#
# Written as a basic example of tracing latency.
#
...
...
@@ -16,7 +16,32 @@ from bcc import BPF
REQ_WRITE
=
1
# from include/linux/blk_types.h
# load BPF program
b
=
BPF
(
src_file
=
"disksnoop.c"
)
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
BPF_HASH(start, struct request *);
void trace_start(struct pt_regs *ctx, struct request *req) {
// stash start timestamp by request ptr
u64 ts = bpf_ktime_get_ns();
start.update(&req, &ts);
}
void trace_completion(struct pt_regs *ctx, struct request *req) {
u64 *tsp, delta;
tsp = start.lookup(&req);
if (tsp != 0) {
delta = bpf_ktime_get_ns() - *tsp;
bpf_trace_printk("%d %x %d
\
\
n", req->__data_len,
req->cmd_flags, delta / 1000);
start.delete(&req);
}
}
"""
)
b
.
attach_kprobe
(
event
=
"blk_start_request"
,
fn_name
=
"trace_start"
)
b
.
attach_kprobe
(
event
=
"blk_mq_start_request"
,
fn_name
=
"trace_start"
)
b
.
attach_kprobe
(
event
=
"blk_account_io_completion"
,
fn_name
=
"trace_completion"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment