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
f92e6683
Commit
f92e6683
authored
Sep 10, 2015
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve and shorten BPF_HASH usage
parent
c7edcd5e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
23 deletions
+12
-23
examples/disksnoop.c
examples/disksnoop.c
+4
-11
examples/vfsreadlat.c
examples/vfsreadlat.c
+8
-12
No files found.
examples/disksnoop.c
View file @
f92e6683
...
...
@@ -13,35 +13,28 @@
#include <uapi/linux/ptrace.h>
#include <linux/blkdev.h>
struct
key_t
{
struct
request
*
req
;
};
BPF_HASH
(
start
,
struct
key_t
);
BPF_HASH
(
start
,
struct
request
*
);
int
kprobe__blk_start_request
(
struct
pt_regs
*
ctx
,
struct
request
*
req
)
{
struct
key_t
key
=
{};
u64
ts
;
// stash start timestamp by request ptr
ts
=
bpf_ktime_get_ns
();
key
.
req
=
req
;
start
.
update
(
&
key
,
&
ts
);
start
.
update
(
&
req
,
&
ts
);
return
0
;
}
int
kprobe__blk_update_request
(
struct
pt_regs
*
ctx
,
struct
request
*
req
)
{
struct
key_t
key
=
{};
u64
*
tsp
,
delta
;
key
.
req
=
req
;
tsp
=
start
.
lookup
(
&
key
);
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
(
&
key
);
start
.
delete
(
&
req
);
}
return
0
;
...
...
examples/vfsreadlat.c
View file @
f92e6683
...
...
@@ -13,11 +13,7 @@
#include <uapi/linux/ptrace.h>
struct
key_t
{
u32
pid
;
};
BPF_HASH
(
start
,
struct
key_t
);
BPF_HASH
(
start
,
u32
);
BPF_TABLE
(
"array"
,
int
,
u64
,
dist
,
64
);
static
unsigned
int
log2
(
unsigned
int
v
)
...
...
@@ -44,29 +40,29 @@ static unsigned int log2l(unsigned long v)
int
do_entry
(
struct
pt_regs
*
ctx
)
{
struct
key_t
key
=
{}
;
u32
pid
;
u64
ts
,
*
val
,
zero
=
0
;
key
.
pid
=
bpf_get_current_pid_tgid
();
pid
=
bpf_get_current_pid_tgid
();
ts
=
bpf_ktime_get_ns
();
start
.
update
(
&
key
,
&
ts
);
start
.
update
(
&
pid
,
&
ts
);
return
0
;
}
int
do_return
(
struct
pt_regs
*
ctx
)
{
struct
key_t
key
=
{}
;
u32
pid
;
u64
*
tsp
,
delta
;
key
.
pid
=
bpf_get_current_pid_tgid
();
tsp
=
start
.
lookup
(
&
key
);
pid
=
bpf_get_current_pid_tgid
();
tsp
=
start
.
lookup
(
&
pid
);
if
(
tsp
!=
0
)
{
delta
=
bpf_ktime_get_ns
()
-
*
tsp
;
int
index
=
log2l
(
delta
/
1000
);
u64
*
leaf
=
dist
.
lookup
(
&
index
);
if
(
leaf
)
(
*
leaf
)
++
;
start
.
delete
(
&
key
);
start
.
delete
(
&
pid
);
}
return
0
;
...
...
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