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
a4159da8
Commit
a4159da8
authored
Jul 11, 2016
by
Brendan Gregg
Committed by
4ast
Jul 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use new tracepoint support (#608)
parent
74520801
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
21 deletions
+59
-21
examples/tracing/urandomread-explicit.py
examples/tracing/urandomread-explicit.py
+52
-0
examples/tracing/urandomread.py
examples/tracing/urandomread.py
+7
-21
No files found.
examples/tracing/urandomread-explicit.py
0 → 100755
View file @
a4159da8
#!/usr/bin/python
#
# urandomread-explicit Example of instrumenting a kernel tracepoint.
# For Linux, uses BCC, BPF. Embedded C.
#
# This is an older example of instrumenting a tracepoint, which defines
# the argument struct and makes an explicit call to attach_tracepoint().
# See urandomread for a newer version that uses TRACEPOINT_PROBE().
#
# REQUIRES: Linux 4.7+ (BPF_PROG_TYPE_TRACEPOINT support).
#
# Test by running this, then in another shell, run:
# dd if=/dev/urandom of=/dev/null bs=1k count=5
#
# Copyright 2016 Netflix, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
from
__future__
import
print_function
from
bcc
import
BPF
# define BPF program
bpf_text
=
"""
#include <uapi/linux/ptrace.h>
struct urandom_read_args {
// from /sys/kernel/debug/tracing/events/random/urandom_read/format
u64 __unused__;
u32 got_bits;
u32 pool_left;
u32 input_left;
};
int printarg(struct urandom_read_args *args) {
bpf_trace_printk("%d
\
\
n", args->got_bits);
return 0;
};
"""
# load BPF program
b
=
BPF
(
text
=
bpf_text
)
b
.
attach_tracepoint
(
"random:urandom_read"
,
"printarg"
)
# header
print
(
"%-18s %-16s %-6s %s"
%
(
"TIME(s)"
,
"COMM"
,
"PID"
,
"GOTBITS"
))
# format output
while
1
:
try
:
(
task
,
pid
,
cpu
,
flags
,
ts
,
msg
)
=
b
.
trace_fields
()
except
ValueError
:
continue
print
(
"%-18.9f %-16s %-6d %s"
%
(
ts
,
task
,
pid
,
msg
))
examples/tracing/urandomread.py
View file @
a4159da8
#!/usr/bin/python
#
#
tracepoint
Example of instrumenting a kernel tracepoint.
#
urandomread
Example of instrumenting a kernel tracepoint.
# For Linux, uses BCC, BPF. Embedded C.
#
# REQUIRES: Linux 4.7+ (BPF_PROG_TYPE_TRACEPOINT support).
...
...
@@ -14,28 +14,14 @@
from
__future__
import
print_function
from
bcc
import
BPF
# define BPF program
bpf_text
=
"""
#include <uapi/linux/ptrace.h>
struct urandom_read_args {
// from /sys/kernel/debug/tracing/events/random/urandom_read/format
// this may be automatically generated in a future bcc version
u64 __unused__;
u32 got_bits;
u32 pool_left;
u32 input_left;
};
int printarg(struct urandom_read_args *args) {
# load BPF program
b
=
BPF
(
text
=
"""
TRACEPOINT_PROBE(random, urandom_read) {
// args is from /sys/kernel/debug/tracing/events/random/urandom_read/format
bpf_trace_printk("%d
\
\
n", args->got_bits);
return 0;
};
"""
# load BPF program
b
=
BPF
(
text
=
bpf_text
)
b
.
attach_tracepoint
(
"random:urandom_read"
,
"printarg"
)
"""
)
# header
print
(
"%-18s %-16s %-6s %s"
%
(
"TIME(s)"
,
"COMM"
,
"PID"
,
"GOTBITS"
))
...
...
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