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
265c2fe4
Commit
265c2fe4
authored
Oct 09, 2018
by
Brendan Gregg
Committed by
GitHub
Oct 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #158 from kinvolk/alban/filter_cgroup
Add filter by cgroup-v2 id
parents
94940a23
22110ad2
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
26 additions
and
1 deletion
+26
-1
README.md
README.md
+4
-0
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+4
-0
src/ast/irbuilderbpf.cpp
src/ast/irbuilderbpf.cpp
+13
-0
src/ast/irbuilderbpf.h
src/ast/irbuilderbpf.h
+1
-0
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+1
-0
src/lexer.l
src/lexer.l
+1
-1
tests/parser.cpp
tests/parser.cpp
+1
-0
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+1
-0
No files found.
README.md
View file @
265c2fe4
...
...
@@ -130,6 +130,9 @@ bpftrace -e 'hardware:cache-misses:1000000 { @[comm, pid] = count(); }'
# Profile user-level stacks at 99 Hertz, for PID 189:
bpftrace -e 'profile:hz:99 /pid == 189/ { @[ustack] = count(); }'
# Files opened, for processes in the root cgroup-v2
bpftrace -e 'tracepoint:syscalls:sys_enter_open /cgroup == 0x100000001/ { printf("%s\n", str(args->filename)); }'
```
## Tools
...
...
@@ -234,6 +237,7 @@ The following variables and functions are available for use in bpftrace scripts:
Variables:
-
`pid`
- Process ID (kernel tgid)
-
`tid`
- Thread ID (kernel pid)
-
`cgroup`
- Cgroup ID of the current process
-
`uid`
- User ID
-
`gid`
- Group ID
-
`nsecs`
- Nanosecond timestamp
...
...
src/ast/codegen_llvm.cpp
View file @
265c2fe4
...
...
@@ -54,6 +54,10 @@ void CodegenLLVM::visit(Builtin &builtin)
expr_
=
b_
.
CreateAnd
(
pidtgid
,
0xffffffff
);
}
}
else
if
(
builtin
.
ident
==
"cgroup"
)
{
expr_
=
b_
.
CreateGetCurrentCgroupId
();
}
else
if
(
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
||
builtin
.
ident
==
"username"
)
{
Value
*
uidgid
=
b_
.
CreateGetUidGid
();
...
...
src/ast/irbuilderbpf.cpp
View file @
265c2fe4
...
...
@@ -411,6 +411,19 @@ CallInst *IRBuilderBPF::CreateGetPidTgid()
return
CreateCall
(
getpidtgid_func
,
{},
"get_pid_tgid"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetCurrentCgroupId
()
{
// u64 bpf_get_current_cgroup_id(void)
// Return: 64-bit cgroup-v2 id
FunctionType
*
getcgroupid_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
false
);
PointerType
*
getcgroupid_func_ptr_type
=
PointerType
::
get
(
getcgroupid_func_type
,
0
);
Constant
*
getcgroupid_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_cgroup_id
),
getcgroupid_func_ptr_type
);
return
CreateCall
(
getcgroupid_func
,
{},
"get_cgroup_id"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetUidGid
()
{
// u64 bpf_get_current_uid_gid(void)
...
...
src/ast/irbuilderbpf.h
View file @
265c2fe4
...
...
@@ -38,6 +38,7 @@ public:
Value
*
CreateStrcmp
(
Value
*
val
,
std
::
string
str
,
bool
inverse
=
false
);
CallInst
*
CreateGetNs
();
CallInst
*
CreateGetPidTgid
();
CallInst
*
CreateGetCurrentCgroupId
();
CallInst
*
CreateGetUidGid
();
CallInst
*
CreateGetCpuId
();
CallInst
*
CreateGetCurrentTask
();
...
...
src/ast/semantic_analyser.cpp
View file @
265c2fe4
...
...
@@ -31,6 +31,7 @@ void SemanticAnalyser::visit(Builtin &builtin)
if
(
builtin
.
ident
==
"nsecs"
||
builtin
.
ident
==
"pid"
||
builtin
.
ident
==
"tid"
||
builtin
.
ident
==
"cgroup"
||
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
||
builtin
.
ident
==
"cpu"
||
...
...
src/lexer.l
View file @
265c2fe4
...
...
@@ -48,7 +48,7 @@ path :(\\.|[_\-\./a-zA-Z0-9])*:
<COMMENT>"*/" BEGIN(INITIAL);
<COMMENT>"EOF" driver.error(loc, std::string("end of file during comment"));
pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name|curtask|rand|ctx|username|args {
pid|tid|
cgroup|
uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name|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); }
...
...
tests/parser.cpp
View file @
265c2fe4
...
...
@@ -25,6 +25,7 @@ TEST(Parser, builtin_variables)
{
test
(
"kprobe:f { pid }"
,
"Program
\n
kprobe:f
\n
builtin: pid
\n
"
);
test
(
"kprobe:f { tid }"
,
"Program
\n
kprobe:f
\n
builtin: tid
\n
"
);
test
(
"kprobe:f { cgroup }"
,
"Program
\n
kprobe:f
\n
builtin: cgroup
\n
"
);
test
(
"kprobe:f { uid }"
,
"Program
\n
kprobe:f
\n
builtin: uid
\n
"
);
test
(
"kprobe:f { username }"
,
"Program
\n
kprobe:f
\n
builtin: username
\n
"
);
test
(
"kprobe:f { gid }"
,
"Program
\n
kprobe:f
\n
builtin: gid
\n
"
);
...
...
tests/semantic_analyser.cpp
View file @
265c2fe4
...
...
@@ -48,6 +48,7 @@ TEST(semantic_analyser, builtin_variables)
{
test
(
"kprobe:f { pid }"
,
0
);
test
(
"kprobe:f { tid }"
,
0
);
test
(
"kprobe:f { cgroup }"
,
0
);
test
(
"kprobe:f { uid }"
,
0
);
test
(
"kprobe:f { username }"
,
0
);
test
(
"kprobe:f { gid }"
,
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