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
68ede064
Commit
68ede064
authored
Jul 23, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cpu builtin
parent
8a362f07
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
0 deletions
+20
-0
README.md
README.md
+1
-0
src/codegen_llvm.cpp
src/codegen_llvm.cpp
+4
-0
src/irbuilderbpf.cpp
src/irbuilderbpf.cpp
+13
-0
src/irbuilderbpf.h
src/irbuilderbpf.h
+1
-0
src/semantic_analyser.cpp
src/semantic_analyser.cpp
+1
-0
No files found.
README.md
View file @
68ede064
...
...
@@ -98,6 +98,7 @@ Variables:
-
`uid`
- User ID
-
`gid`
- Group ID
-
`nsecs`
- Nanosecond timestamp
-
`cpu`
- Processor ID
-
`comm`
- Process name
-
`stack`
- Kernel stack trace
-
`ustack`
- User stack trace
...
...
src/codegen_llvm.cpp
View file @
68ede064
...
...
@@ -60,6 +60,10 @@ void CodegenLLVM::visit(Builtin &builtin)
expr_
=
b_
.
CreateLShr
(
uidgid
,
32
);
}
}
else
if
(
builtin
.
ident
==
"cpu"
)
{
expr_
=
b_
.
CreateGetCpuId
();
}
else
if
(
builtin
.
ident
==
"comm"
)
{
AllocaInst
*
buf
=
b_
.
CreateAllocaBPF
(
builtin
.
type
,
"comm"
);
...
...
src/irbuilderbpf.cpp
View file @
68ede064
...
...
@@ -258,6 +258,19 @@ CallInst *IRBuilderBPF::CreateGetUidGid()
return
CreateCall
(
getuidgid_func
,
{},
"get_uid_gid"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetCpuId
()
{
// u32 bpf_raw_smp_processor_id(void)
// Return: SMP processor ID
FunctionType
*
getcpuid_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
false
);
PointerType
*
getcpuid_func_ptr_type
=
PointerType
::
get
(
getcpuid_func_type
,
0
);
Constant
*
getcpuid_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_smp_processor_id
),
getcpuid_func_ptr_type
);
return
CreateCall
(
getcpuid_func
,
{},
"get_cpu_id"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
)
{
Value
*
map_ptr
=
CreateBpfPseudoCall
(
bpftrace_
.
stackid_map_
->
mapfd_
);
...
...
src/irbuilderbpf.h
View file @
68ede064
...
...
@@ -32,6 +32,7 @@ public:
CallInst
*
CreateGetNs
();
CallInst
*
CreateGetPidTgid
();
CallInst
*
CreateGetUidGid
();
CallInst
*
CreateGetCpuId
();
CallInst
*
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
);
void
CreateGetCurrentComm
(
AllocaInst
*
buf
,
size_t
size
);
...
...
src/semantic_analyser.cpp
View file @
68ede064
...
...
@@ -28,6 +28,7 @@ void SemanticAnalyser::visit(Builtin &builtin)
builtin
.
ident
==
"tid"
||
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
||
builtin
.
ident
==
"cpu"
||
builtin
.
ident
==
"retval"
)
{
builtin
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
...
...
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