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
b950d6f8
Commit
b950d6f8
authored
Mar 21, 2016
by
Sasha Goldshtein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved auto-includes helper to __init__.py
parent
c08c431a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
39 deletions
+26
-39
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+24
-0
tools/argdist.py
tools/argdist.py
+1
-19
tools/trace.py
tools/trace.py
+1
-20
No files found.
src/python/bcc/__init__.py
View file @
b950d6f8
...
@@ -73,6 +73,30 @@ class BPF(object):
...
@@ -73,6 +73,30 @@ class BPF(object):
_lib_load_address_cache
=
{}
_lib_load_address_cache
=
{}
_lib_symbol_cache
=
{}
_lib_symbol_cache
=
{}
_auto_includes
=
{
"linux/time.h"
:
[
"time"
],
"linux/fs.h"
:
[
"fs"
,
"file"
],
"linux/blkdev.h"
:
[
"bio"
,
"request"
],
"linux/slab.h"
:
[
"alloc"
],
"linux/netdevice.h"
:
[
"sk_buff"
,
"net_device"
]
}
@
classmethod
def
generate_auto_includes
(
cls
,
program_words
):
"""
Generates #include statements automatically based on a set of
recognized types such as sk_buff and bio. The input is all the words
that appear in the BPF program, and the output is a (possibly empty)
string of #include statements, such as "#include <linux/fs.h>".
"""
headers
=
""
for
header
,
keywords
in
cls
.
_auto_includes
.
items
():
for
keyword
in
keywords
:
for
word
in
program_words
:
if
keyword
in
word
and
header
not
in
headers
:
headers
+=
"#include <%s>
\
n
"
%
header
return
headers
# defined for compatibility reasons, to be removed
# defined for compatibility reasons, to be removed
Table
=
Table
Table
=
Table
...
...
tools/argdist.py
View file @
b950d6f8
...
@@ -36,24 +36,6 @@ int PROBENAME(struct pt_regs *ctx SIGNATURE)
...
@@ -36,24 +36,6 @@ int PROBENAME(struct pt_regs *ctx SIGNATURE)
"""
"""
next_probe_index
=
0
next_probe_index
=
0
aliases
=
{
"$PID"
:
"bpf_get_current_pid_tgid()"
}
aliases
=
{
"$PID"
:
"bpf_get_current_pid_tgid()"
}
auto_includes
=
{
"linux/time.h"
:
[
"time"
],
"linux/fs.h"
:
[
"fs"
,
"file"
],
"linux/blkdev.h"
:
[
"bio"
,
"request"
],
"linux/slab.h"
:
[
"alloc"
],
"linux/netdevice.h"
:
[
"sk_buff"
,
"net_device"
]
}
@
staticmethod
def
generate_auto_includes
(
specifiers
):
headers
=
""
for
header
,
keywords
in
Specifier
.
auto_includes
.
items
():
for
keyword
in
keywords
:
for
specifier
in
specifiers
:
if
keyword
in
specifier
:
headers
+=
"#include <%s>
\
n
"
\
%
header
return
headers
def
_substitute_aliases
(
self
,
expr
):
def
_substitute_aliases
(
self
,
expr
):
if
expr
is
None
:
if
expr
is
None
:
...
@@ -590,7 +572,7 @@ struct __string_t { char s[%d]; };
...
@@ -590,7 +572,7 @@ struct __string_t { char s[%d]; };
""" % self.args.string_size
""" % self.args.string_size
for include in (self.args.include or []):
for include in (self.args.include or []):
bpf_source += "
#include <%s>\n" % include
bpf_source += "
#include <%s>\n" % include
bpf_source
+=
Specifier
.
generate_auto_includes
(
bpf_source
+=
BPF
.
generate_auto_includes
(
map
(
lambda
s
:
s
.
raw_spec
,
self
.
specifiers
))
map
(
lambda
s
:
s
.
raw_spec
,
self
.
specifiers
))
bpf_source
+=
Tracepoint
.
generate_decl
()
bpf_source
+=
Tracepoint
.
generate_decl
()
bpf_source
+=
Tracepoint
.
generate_entry_probe
()
bpf_source
+=
Tracepoint
.
generate_entry_probe
()
...
...
tools/trace.py
View file @
b950d6f8
...
@@ -328,25 +328,6 @@ int %s(struct pt_regs *ctx)
...
@@ -328,25 +328,6 @@ int %s(struct pt_regs *ctx)
def
_time_off_str
(
cls
,
timestamp_ns
):
def
_time_off_str
(
cls
,
timestamp_ns
):
return
"%.6f"
%
(
1e-9
*
(
timestamp_ns
-
cls
.
first_ts
))
return
"%.6f"
%
(
1e-9
*
(
timestamp_ns
-
cls
.
first_ts
))
auto_includes
=
{
"linux/time.h"
:
[
"time"
],
"linux/fs.h"
:
[
"fs"
,
"file"
],
"linux/blkdev.h"
:
[
"bio"
,
"request"
],
"linux/slab.h"
:
[
"alloc"
],
"linux/netdevice.h"
:
[
"sk_buff"
]
}
@
classmethod
def
generate_auto_includes
(
cls
,
probes
):
headers
=
""
for
header
,
keywords
in
cls
.
auto_includes
.
items
():
for
keyword
in
keywords
:
for
probe
in
probes
:
if
keyword
in
probe
:
headers
+=
"#include <%s>
\
n
"
\
%
header
return
headers
def
_display_function
(
self
):
def
_display_function
(
self
):
if
self
.
probe_type
!=
't'
:
if
self
.
probe_type
!=
't'
:
return
self
.
function
return
self
.
function
...
@@ -468,7 +449,7 @@ trace 't:block:block_rq_complete "sectors=%d", tp.nr_sector'
...
@@ -468,7 +449,7 @@ trace 't:block:block_rq_complete "sectors=%d", tp.nr_sector'
#include <linux/sched.h> /* For TASK_COMM_LEN */
#include <linux/sched.h> /* For TASK_COMM_LEN */
"""
"""
self
.
program
+=
Probe
.
generate_auto_includes
(
self
.
program
+=
BPF
.
generate_auto_includes
(
map
(
lambda
p
:
p
.
raw_probe
,
self
.
probes
))
map
(
lambda
p
:
p
.
raw_probe
,
self
.
probes
))
self
.
program
+=
Tracepoint
.
generate_decl
()
self
.
program
+=
Tracepoint
.
generate_decl
()
self
.
program
+=
Tracepoint
.
generate_entry_probe
()
self
.
program
+=
Tracepoint
.
generate_entry_probe
()
...
...
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