Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
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
bpftrace
Commits
f158e693
Commit
f158e693
authored
Oct 21, 2018
by
williangaspar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes:
https://github.com/iovisor/bpftrace/issues/125
parent
c489081e
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
45 additions
and
45 deletions
+45
-45
README.md
README.md
+3
-3
docs/tutorial_one_liners.md
docs/tutorial_one_liners.md
+3
-3
man/man8/bpftrace.8
man/man8/bpftrace.8
+2
-2
src/ast/ast.h
src/ast/ast.h
+1
-1
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+7
-7
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+2
-2
src/bpftrace.cpp
src/bpftrace.cpp
+7
-7
src/bpftrace.h
src/bpftrace.h
+2
-2
src/lexer.l
src/lexer.l
+1
-1
src/mapkey.cpp
src/mapkey.cpp
+2
-2
src/printf.cpp
src/printf.cpp
+1
-1
src/types.cpp
src/types.cpp
+1
-1
src/types.h
src/types.h
+1
-1
tests/codegen.cpp
tests/codegen.cpp
+4
-4
tests/parser.cpp
tests/parser.cpp
+1
-1
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+7
-7
No files found.
README.md
View file @
f158e693
...
...
@@ -12,7 +12,7 @@ For build and install instructions, see [INSTALL.md](INSTALL.md).
Count system calls using tracepoints:
```
# bpftrace -e 'tracepoint:syscalls:sys_enter_* { @[
nam
e] = count(); }'
# bpftrace -e 'tracepoint:syscalls:sys_enter_* { @[
prob
e] = count(); }'
Attaching 320 probes...
^C
...
...
@@ -248,7 +248,7 @@ Variables:
-
`arg0`
,
`arg1`
, ... etc. - Arguments to the function being traced
-
`retval`
- Return value from function being traced
-
`func`
- Name of the function currently being traced
-
`
nam
e`
- Full name of the probe
-
`
prob
e`
- Full name of the probe
-
`curtask`
- Current task_struct as a u64.
-
`rand`
- Random number of type u32.
...
...
docs/tutorial_one_liners.md
View file @
f158e693
...
...
@@ -165,7 +165,7 @@ Summarize the time spent in read(), in nanoseconds, as a histogram, by process n
# Lesson 8. Count Process-Level Events
```
# bpftrace -e 'tracepoint:sched:sched* { @[
nam
e] = count(); } interval:s:5 { exit(); }'
# bpftrace -e 'tracepoint:sched:sched* { @[
prob
e] = count(); } interval:s:5 { exit(); }'
Attaching 25 probes...
@[tracepoint:sched:sched_wakeup_new]: 1
@[tracepoint:sched:sched_process_fork]: 1
...
...
man/man8/bpftrace.8
View file @
f158e693
...
...
@@ -108,7 +108,7 @@ Syscall count by program
.
.TP
Syscall count by syscall
\fBtracepoint:syscalls:sys_enter_* { @[
nam
e] = count(); }\fR
\fBtracepoint:syscalls:sys_enter_* { @[
prob
e] = count(); }\fR
.
.TP
Syscall count by process
...
...
@@ -273,7 +273,7 @@ Return value from function being traced
Name of the function currently being traced
.
.TP
\fB
nam
e\fR
\fB
prob
e\fR
Full name of the probe
.
.TP
...
...
src/ast/ast.h
View file @
f158e693
...
...
@@ -50,7 +50,7 @@ class Builtin : public Expression {
public:
explicit
Builtin
(
std
::
string
ident
)
:
ident
(
ident
)
{
}
std
::
string
ident
;
int
nam
e_id
;
int
prob
e_id
;
void
accept
(
Visitor
&
v
)
override
;
};
...
...
src/ast/codegen_llvm.cpp
View file @
f158e693
...
...
@@ -117,13 +117,13 @@ void CodegenLLVM::visit(Builtin &builtin)
expr_
=
b_
.
CreateLoad
(
dst
);
b_
.
CreateLifetimeEnd
(
dst
);
}
else
if
(
builtin
.
ident
==
"
nam
e"
)
else
if
(
builtin
.
ident
==
"
prob
e"
)
{
static
int
nam
e_id
=
0
;
bpftrace_
.
nam
e_ids_
.
push_back
(
probefull_
);
builtin
.
name_id
=
nam
e_id
;
nam
e_id
++
;
expr_
=
b_
.
getInt64
(
builtin
.
nam
e_id
);
static
int
prob
e_id
=
0
;
bpftrace_
.
prob
e_ids_
.
push_back
(
probefull_
);
builtin
.
probe_id
=
prob
e_id
;
prob
e_id
++
;
expr_
=
b_
.
getInt64
(
builtin
.
prob
e_id
);
}
else
if
(
builtin
.
ident
==
"args"
)
{
...
...
@@ -1057,7 +1057,7 @@ void CodegenLLVM::visit(Probe &probe)
/*
* Most of the time, we can take a probe like kprobe:do_f* and build a
* single BPF program for that, called "s_kprobe:do_f*", and attach it to
* each wildcard match. An exception is the "
nam
e" builtin, where we need
* each wildcard match. An exception is the "
prob
e" builtin, where we need
* to build different BPF programs for each wildcard match that cantains an
* ID for the match. Those programs will be called "s_kprobe:do_fcntl" etc.
*/
...
...
src/ast/semantic_analyser.cpp
View file @
f158e693
...
...
@@ -80,8 +80,8 @@ void SemanticAnalyser::visit(Builtin &builtin)
err_
<<
arch
::
name
()
<<
" doesn't support "
<<
builtin
.
ident
<<
std
::
endl
;
builtin
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
else
if
(
builtin
.
ident
==
"
nam
e"
)
{
builtin
.
type
=
SizedType
(
Type
::
nam
e
,
8
);
else
if
(
builtin
.
ident
==
"
prob
e"
)
{
builtin
.
type
=
SizedType
(
Type
::
prob
e
,
8
);
probe_
->
need_expansion
=
true
;
}
else
if
(
builtin
.
ident
==
"username"
)
{
...
...
src/bpftrace.cpp
View file @
f158e693
...
...
@@ -350,8 +350,8 @@ std::vector<uint64_t> BPFtrace::get_arg_values(std::vector<Field> args, uint8_t*
resolve_uid
(
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
)).
c_str
()));
arg_values
.
push_back
((
uint64_t
)
resolved_usernames
.
back
().
get
());
break
;
case
Type
:
:
nam
e
:
name
=
strdup
(
resolve_
nam
e
(
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
)).
c_str
());
case
Type
:
:
prob
e
:
name
=
strdup
(
resolve_
prob
e
(
*
(
uint64_t
*
)(
arg_data
+
arg
.
offset
)).
c_str
());
arg_values
.
push_back
((
uint64_t
)
name
);
break
;
case
Type
:
:
stack
:
...
...
@@ -757,8 +757,8 @@ int BPFtrace::print_map(IMap &map, uint32_t top, uint32_t div)
std
::
cout
<<
min_value
(
value
,
ncpus_
)
/
div
<<
std
::
endl
;
else
if
(
map
.
type_
.
type
==
Type
::
max
)
std
::
cout
<<
max_value
(
value
,
ncpus_
)
/
div
<<
std
::
endl
;
else
if
(
map
.
type_
.
type
==
Type
::
nam
e
)
std
::
cout
<<
resolve_
nam
e
(
*
(
uint64_t
*
)
value
.
data
())
<<
std
::
endl
;
else
if
(
map
.
type_
.
type
==
Type
::
prob
e
)
std
::
cout
<<
resolve_
prob
e
(
*
(
uint64_t
*
)
value
.
data
())
<<
std
::
endl
;
else
std
::
cout
<<
*
(
int64_t
*
)
value
.
data
()
/
div
<<
std
::
endl
;
}
...
...
@@ -1372,10 +1372,10 @@ std::string BPFtrace::resolve_usym(uintptr_t addr, int pid, bool show_offset)
return
symbol
.
str
();
}
std
::
string
BPFtrace
::
resolve_
name
(
uint64_t
nam
e_id
)
std
::
string
BPFtrace
::
resolve_
probe
(
uint64_t
prob
e_id
)
{
assert
(
name_id
<
nam
e_ids_
.
size
());
return
name_ids_
[
nam
e_id
];
assert
(
probe_id
<
prob
e_ids_
.
size
());
return
probe_ids_
[
prob
e_id
];
}
void
BPFtrace
::
sort_by_key
(
std
::
vector
<
SizedType
>
key_args
,
...
...
src/bpftrace.h
View file @
f158e693
...
...
@@ -64,7 +64,7 @@ public:
std
::
string
resolve_uid
(
uintptr_t
addr
);
uint64_t
resolve_kname
(
const
std
::
string
&
name
);
uint64_t
resolve_uname
(
const
std
::
string
&
name
,
const
std
::
string
&
path
);
std
::
string
resolve_
name
(
uint64_t
nam
e_id
);
std
::
string
resolve_
probe
(
uint64_t
prob
e_id
);
uint64_t
resolve_cgroupid
(
const
std
::
string
&
path
);
std
::
vector
<
uint64_t
>
get_arg_values
(
std
::
vector
<
Field
>
args
,
uint8_t
*
arg_data
);
int
pid_
;
...
...
@@ -77,7 +77,7 @@ public:
std
::
unique_ptr
<
IMap
>
stackid_map_
;
std
::
unique_ptr
<
IMap
>
join_map_
;
std
::
unique_ptr
<
IMap
>
perf_event_map_
;
std
::
vector
<
std
::
string
>
nam
e_ids_
;
std
::
vector
<
std
::
string
>
prob
e_ids_
;
int
join_argnum_
;
int
join_argsize_
;
...
...
src/lexer.l
View file @
f158e693
...
...
@@ -49,7 +49,7 @@ path :(\\.|[_\-\./a-zA-Z0-9])*:
<COMMENT>"*/" BEGIN(INITIAL);
<COMMENT>"EOF" driver.error(loc, std::string("end of file during comment"));
pid|tid|cgroup|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|
nam
e|curtask|rand|ctx|username|args {
pid|tid|cgroup|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|
prob
e|curtask|rand|ctx|username|args {
return Parser::make_BUILTIN(yytext, loc); }
{path} { return Parser::make_PATH(yytext, loc); }
{map} { return Parser::make_MAP(yytext, loc); }
...
...
src/mapkey.cpp
View file @
f158e693
...
...
@@ -76,8 +76,8 @@ std::string MapKey::argument_value(BPFtrace &bpftrace,
return
bpftrace
.
resolve_usym
(
*
(
uint64_t
*
)
data
,
*
(
uint64_t
*
)(
arg_data
+
8
));
case
Type
:
:
username
:
return
bpftrace
.
resolve_uid
(
*
(
uint64_t
*
)
data
);
case
Type
:
:
nam
e
:
return
bpftrace
.
nam
e_ids_
[
*
(
uint64_t
*
)
data
];
case
Type
:
:
prob
e
:
return
bpftrace
.
prob
e_ids_
[
*
(
uint64_t
*
)
data
];
case
Type
:
:
string
:
return
std
::
string
((
char
*
)
data
);
}
...
...
src/printf.cpp
View file @
f158e693
...
...
@@ -33,7 +33,7 @@ std::string verify_format_string(const std::string &fmt, std::vector<Field> args
for
(
int
i
=
0
;
i
<
num_args
;
i
++
,
token_iter
++
)
{
Type
arg_type
=
args
.
at
(
i
).
type
.
type
;
if
(
arg_type
==
Type
::
sym
||
arg_type
==
Type
::
usym
||
arg_type
==
Type
::
nam
e
||
if
(
arg_type
==
Type
::
sym
||
arg_type
==
Type
::
usym
||
arg_type
==
Type
::
prob
e
||
arg_type
==
Type
::
username
||
arg_type
==
Type
::
stack
||
arg_type
==
Type
::
ustack
)
arg_type
=
Type
::
string
;
// Symbols should be printed as strings
int
offset
=
1
;
...
...
src/types.cpp
View file @
f158e693
...
...
@@ -48,7 +48,7 @@ std::string typestr(Type t)
case
Type
:
:
sym
:
return
"sym"
;
break
;
case
Type
:
:
usym
:
return
"usym"
;
break
;
case
Type
:
:
cast
:
return
"cast"
;
break
;
case
Type
:
:
name
:
return
"name"
;
break
;
case
Type
:
:
probe
:
return
"probe"
;
break
;
default:
abort
();
}
}
...
...
src/types.h
View file @
f158e693
...
...
@@ -31,7 +31,7 @@ enum class Type
usym
,
cast
,
join
,
nam
e
,
prob
e
,
username
,
};
...
...
tests/codegen.cpp
View file @
f158e693
...
...
@@ -902,9 +902,9 @@ attributes #1 = { argmemonly nounwind }
)EXPECTED"
);
}
TEST
(
codegen
,
builtin_
nam
e
)
TEST
(
codegen
,
builtin_
prob
e
)
{
test
(
"tracepoint:syscalls:sys_enter_nanosleep { @x =
nam
e }"
,
test
(
"tracepoint:syscalls:sys_enter_nanosleep { @x =
prob
e }"
,
R"EXPECTED(; Function Attrs: nounwind
declare i64 @llvm.bpf.pseudo(i64, i64) #0
...
...
@@ -979,9 +979,9 @@ attributes #1 = { argmemonly nounwind }
)EXPECTED"
);
}
TEST
(
codegen
,
builtin_
nam
e_wild
)
TEST
(
codegen
,
builtin_
prob
e_wild
)
{
test
(
"tracepoint:syscalls:sys_enter_nanoslee* { @x =
nam
e }"
,
test
(
"tracepoint:syscalls:sys_enter_nanoslee* { @x =
prob
e }"
,
R"EXPECTED(; Function Attrs: nounwind
declare i64 @llvm.bpf.pseudo(i64, i64) #0
...
...
tests/parser.cpp
View file @
f158e693
...
...
@@ -40,7 +40,7 @@ TEST(Parser, builtin_variables)
test
(
"kprobe:f { arg0 }"
,
"Program
\n
kprobe:f
\n
builtin: arg0
\n
"
);
test
(
"kprobe:f { retval }"
,
"Program
\n
kprobe:f
\n
builtin: retval
\n
"
);
test
(
"kprobe:f { func }"
,
"Program
\n
kprobe:f
\n
builtin: func
\n
"
);
test
(
"kprobe:f {
name }"
,
"Program
\n
kprobe:f
\n
builtin: nam
e
\n
"
);
test
(
"kprobe:f {
probe }"
,
"Program
\n
kprobe:f
\n
builtin: prov
e
\n
"
);
test
(
"kprobe:f { args }"
,
"Program
\n
kprobe:f
\n
builtin: args
\n
"
);
}
...
...
tests/semantic_analyser.cpp
View file @
f158e693
...
...
@@ -63,7 +63,7 @@ TEST(semantic_analyser, builtin_variables)
test
(
"kprobe:f { arg0 }"
,
0
);
test
(
"kprobe:f { retval }"
,
0
);
test
(
"kprobe:f { func }"
,
0
);
test
(
"kprobe:f {
nam
e }"
,
0
);
test
(
"kprobe:f {
prob
e }"
,
0
);
test
(
"tracepoint:a:b { args }"
,
0
);
// test("kprobe:f { fake }", 1);
}
...
...
@@ -270,13 +270,13 @@ TEST(semantic_analyser, call_func)
test
(
"kprobe:f { func(123); }"
,
1
);
}
TEST
(
semantic_analyser
,
call_
nam
e
)
TEST
(
semantic_analyser
,
call_
prob
e
)
{
test
(
"kprobe:f { @[
nam
e] = count(); }"
,
0
);
test
(
"kprobe:f { printf(
\"
%s
\"
,
nam
e); }"
,
0
);
test
(
"kprobe:f {
nam
e(
\"
blah
\"
); }"
,
1
);
test
(
"kprobe:f {
nam
e(); }"
,
1
);
test
(
"kprobe:f {
nam
e(123); }"
,
1
);
test
(
"kprobe:f { @[
prob
e] = count(); }"
,
0
);
test
(
"kprobe:f { printf(
\"
%s
\"
,
prob
e); }"
,
0
);
test
(
"kprobe:f {
prob
e(
\"
blah
\"
); }"
,
1
);
test
(
"kprobe:f {
prob
e(); }"
,
1
);
test
(
"kprobe:f {
prob
e(123); }"
,
1
);
}
TEST
(
semantic_analyser
,
map_reassignment
)
...
...
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