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
9f682382
Commit
9f682382
authored
May 30, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calculate key size in Map's constructor
parent
7afeeb5e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
125 additions
and
85 deletions
+125
-85
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/bpftrace.cpp
src/bpftrace.cpp
+0
-32
src/bpftrace.h
src/bpftrace.h
+1
-27
src/irbuilderbpf.cpp
src/irbuilderbpf.cpp
+11
-23
src/map.cpp
src/map.cpp
+29
-2
src/map.h
src/map.h
+4
-1
src/semantic_analyser.h
src/semantic_analyser.h
+1
-0
src/types.cpp
src/types.cpp
+39
-0
src/types.h
src/types.h
+38
-0
tests/CMakeLists.txt
tests/CMakeLists.txt
+1
-0
No files found.
src/CMakeLists.txt
View file @
9f682382
...
...
@@ -24,6 +24,7 @@ add_executable(bpftrace
parser.tab.cc
printer.cpp
semantic_analyser.cpp
types.cpp
)
llvm_map_components_to_libnames
(
llvm_libs bpfcodegen ipo irreader mcjit
)
...
...
src/bpftrace.cpp
View file @
9f682382
...
...
@@ -6,38 +6,6 @@
namespace
ebpf
{
namespace
bpftrace
{
std
::
string
typestr
(
Type
t
)
{
switch
(
t
)
{
case
Type
:
:
none
:
return
"none"
;
break
;
case
Type
:
:
integer
:
return
"integer"
;
break
;
case
Type
:
:
quantize
:
return
"quantize"
;
break
;
case
Type
:
:
count
:
return
"count"
;
break
;
default:
abort
();
}
}
bpf_probe_attach_type
attachtype
(
ProbeType
t
)
{
switch
(
t
)
{
case
ProbeType
:
:
kprobe
:
return
BPF_PROBE_ENTRY
;
break
;
case
ProbeType
:
:
kretprobe
:
return
BPF_PROBE_RETURN
;
break
;
default:
abort
();
}
}
bpf_prog_type
progtype
(
ProbeType
t
)
{
switch
(
t
)
{
case
ProbeType
:
:
kprobe
:
return
BPF_PROG_TYPE_KPROBE
;
break
;
case
ProbeType
:
:
kretprobe
:
return
BPF_PROG_TYPE_KPROBE
;
break
;
default:
abort
();
}
}
int
BPFtrace
::
add_probe
(
ast
::
Probe
&
p
)
{
Probe
probe
;
...
...
src/bpftrace.h
View file @
9f682382
...
...
@@ -4,39 +4,13 @@
#include <memory>
#include <vector>
#include "libbpf.h"
#include "ast.h"
#include "map.h"
#include "types.h"
namespace
ebpf
{
namespace
bpftrace
{
enum
class
Type
{
none
,
integer
,
quantize
,
count
,
};
enum
class
ProbeType
{
kprobe
,
kretprobe
,
};
std
::
string
typestr
(
Type
t
);
bpf_probe_attach_type
attachtype
(
ProbeType
t
);
bpf_prog_type
progtype
(
ProbeType
t
);
class
Probe
{
public:
ProbeType
type
;
std
::
string
attach_point
;
std
::
string
name
;
};
class
BPFtrace
{
public:
...
...
src/irbuilderbpf.cpp
View file @
9f682382
...
...
@@ -43,29 +43,17 @@ CallInst *IRBuilderBPF::CreateBpfPseudoCall(Map &map)
int
mapfd
;
if
(
bpftrace_
.
maps_
.
find
(
map
.
ident
)
==
bpftrace_
.
maps_
.
end
())
{
// Create map since it doesn't already exist
int
key_size
=
0
;
if
(
map
.
vargs
)
{
auto
map_args
=
bpftrace_
.
map_args_
.
find
(
map
.
ident
);
if
(
map_args
==
bpftrace_
.
map_args_
.
end
())
abort
();
for
(
auto
type
:
map_args
->
second
)
{
switch
(
type
)
{
case
Type
:
:
integer
:
key_size
+=
8
;
break
;
default:
abort
();
}
}
}
else
{
key_size
=
8
;
}
bpftrace_
.
maps_
[
map
.
ident
]
=
std
::
make_unique
<
ebpf
::
bpftrace
::
Map
>
(
map
.
ident
,
key_size
);
auto
search_val
=
bpftrace_
.
map_val_
.
find
(
map
.
ident
);
if
(
search_val
==
bpftrace_
.
map_val_
.
end
())
abort
();
Type
type
=
search_val
->
second
;
auto
search_args
=
bpftrace_
.
map_args_
.
find
(
map
.
ident
);
if
(
search_args
==
bpftrace_
.
map_args_
.
end
())
abort
();
auto
&
args
=
search_args
->
second
;
bpftrace_
.
maps_
[
map
.
ident
]
=
std
::
make_unique
<
ebpf
::
bpftrace
::
Map
>
(
map
.
ident
,
type
,
args
);
}
mapfd
=
bpftrace_
.
maps_
[
map
.
ident
]
->
mapfd_
;
...
...
src/map.cpp
View file @
9f682382
...
...
@@ -7,7 +7,33 @@
namespace
ebpf
{
namespace
bpftrace
{
Map
::
Map
(
std
::
string
&
name
,
int
key_size
)
:
name_
(
name
)
{
Map
::
Map
(
std
::
string
&
name
,
Type
type
,
std
::
vector
<
Type
>
&
args
)
:
name_
(
name
)
{
int
key_size
=
0
;
if
(
args
.
size
()
>
0
)
{
for
(
auto
type
:
args
)
{
switch
(
type
)
{
case
Type
:
:
integer
:
key_size
+=
8
;
break
;
default:
abort
();
}
}
}
else
{
key_size
=
8
;
}
if
(
type
==
Type
::
quantize
)
{
key_size
+=
8
;
}
int
value_size
=
8
;
int
max_entries
=
128
;
int
flags
=
0
;
...
...
@@ -18,7 +44,8 @@ Map::Map(std::string &name, int key_size) : name_(name) {
}
}
Map
::~
Map
()
{
Map
::~
Map
()
{
close
(
mapfd_
);
}
...
...
src/map.h
View file @
9f682382
...
...
@@ -2,13 +2,16 @@
#include <map>
#include <string>
#include <vector>
#include "types.h"
namespace
ebpf
{
namespace
bpftrace
{
class
Map
{
public:
Map
(
std
::
string
&
,
int
key_size
);
Map
(
std
::
string
&
,
Type
type
,
std
::
vector
<
Type
>
&
args
);
~
Map
();
Map
(
const
Map
&
)
=
delete
;
Map
&
operator
=
(
const
Map
&
)
=
delete
;
...
...
src/semantic_analyser.h
View file @
9f682382
...
...
@@ -5,6 +5,7 @@
#include "ast.h"
#include "bpftrace.h"
#include "map.h"
#include "types.h"
namespace
ebpf
{
namespace
bpftrace
{
...
...
src/types.cpp
0 → 100644
View file @
9f682382
#include "types.h"
namespace
ebpf
{
namespace
bpftrace
{
std
::
string
typestr
(
Type
t
)
{
switch
(
t
)
{
case
Type
:
:
none
:
return
"none"
;
break
;
case
Type
:
:
integer
:
return
"integer"
;
break
;
case
Type
:
:
quantize
:
return
"quantize"
;
break
;
case
Type
:
:
count
:
return
"count"
;
break
;
default:
abort
();
}
}
bpf_probe_attach_type
attachtype
(
ProbeType
t
)
{
switch
(
t
)
{
case
ProbeType
:
:
kprobe
:
return
BPF_PROBE_ENTRY
;
break
;
case
ProbeType
:
:
kretprobe
:
return
BPF_PROBE_RETURN
;
break
;
default:
abort
();
}
}
bpf_prog_type
progtype
(
ProbeType
t
)
{
switch
(
t
)
{
case
ProbeType
:
:
kprobe
:
return
BPF_PROG_TYPE_KPROBE
;
break
;
case
ProbeType
:
:
kretprobe
:
return
BPF_PROG_TYPE_KPROBE
;
break
;
default:
abort
();
}
}
}
// namespace bpftrace
}
// namespace ebpf
src/types.h
0 → 100644
View file @
9f682382
#pragma once
#include <unistd.h>
#include <string>
#include "libbpf.h"
namespace
ebpf
{
namespace
bpftrace
{
enum
class
Type
{
none
,
integer
,
quantize
,
count
,
};
enum
class
ProbeType
{
kprobe
,
kretprobe
,
};
std
::
string
typestr
(
Type
t
);
bpf_probe_attach_type
attachtype
(
ProbeType
t
);
bpf_prog_type
progtype
(
ProbeType
t
);
class
Probe
{
public:
ProbeType
type
;
std
::
string
attach_point
;
std
::
string
name
;
};
}
// namespace bpftrace
}
// namespace ebpf
tests/CMakeLists.txt
View file @
9f682382
...
...
@@ -14,6 +14,7 @@ add_executable(bpftrace_test
${
CMAKE_SOURCE_DIR
}
/src/bpftrace.cpp
${
CMAKE_SOURCE_DIR
}
/src/map.cpp
${
CMAKE_SOURCE_DIR
}
/src/semantic_analyser.cpp
${
CMAKE_SOURCE_DIR
}
/src/types.cpp
)
add_dependencies
(
bpftrace_test bcc-build
)
...
...
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