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
6255f1f0
Commit
6255f1f0
authored
Sep 24, 2015
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for char[N] as a histogram key
Signed-off-by:
Brenden Blanco
<
bblanco@plumgrid.com
>
parent
f0b15c49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
4 deletions
+25
-4
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+2
-0
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+5
-3
tests/cc/test_histogram.py
tests/cc/test_histogram.py
+18
-1
No files found.
src/cc/frontends/clang/b_frontend_action.cc
View file @
6255f1f0
...
...
@@ -70,6 +70,8 @@ bool BMapDeclVisitor::VisitRecordDecl(RecordDecl *D) {
result_
+=
"
\"
"
+
F
->
getName
().
str
()
+
"
\"
,
\"
unsigned long long
\"
"
;
else
TraverseDecl
(
F
);
if
(
const
ConstantArrayType
*
T
=
dyn_cast
<
ConstantArrayType
>
(
F
->
getType
()))
result_
+=
", ["
+
T
->
getSize
().
toString
(
10
,
false
)
+
"]"
;
if
(
F
->
isBitField
())
result_
+=
", "
+
to_string
(
F
->
getBitWidthValue
(
C
));
result_
+=
"], "
;
...
...
src/python/bcc/__init__.py
View file @
6255f1f0
...
...
@@ -256,7 +256,7 @@ class BPF(object):
slot
=
getattr
(
k
,
f2
)
vals
[
slot
]
=
v
.
value
for
bucket
,
vals
in
tmp
.
items
():
print
(
"
\
n
Bucket %s = %
x
"
%
(
bucket_type
,
bucket
))
print
(
"
\
n
Bucket %s = %
r
"
%
(
bucket_type
,
bucket
))
self
.
_print_log2_hist
(
vals
,
val_type
,
0
)
else
:
vals
=
[
0
]
*
65
...
...
@@ -429,7 +429,6 @@ class BPF(object):
u"_Bool"
:
ct
.
c_bool
,
u"char"
:
ct
.
c_char
,
u"wchar_t"
:
ct
.
c_wchar
,
u"char"
:
ct
.
c_byte
,
u"unsigned char"
:
ct
.
c_ubyte
,
u"short"
:
ct
.
c_short
,
u"unsigned short"
:
ct
.
c_ushort
,
...
...
@@ -452,7 +451,10 @@ class BPF(object):
if
len
(
t
)
==
2
:
fields
.
append
((
t
[
0
],
BPF
.
_decode_table_type
(
t
[
1
])))
elif
len
(
t
)
==
3
:
fields
.
append
((
t
[
0
],
BPF
.
_decode_table_type
(
t
[
1
]),
t
[
2
]))
if
isinstance
(
t
[
2
],
list
):
fields
.
append
((
t
[
0
],
BPF
.
_decode_table_type
(
t
[
1
])
*
t
[
2
][
0
]))
else
:
fields
.
append
((
t
[
0
],
BPF
.
_decode_table_type
(
t
[
1
]),
t
[
2
]))
else
:
raise
Exception
(
"Failed to decode type %s"
%
str
(
t
))
cls
=
type
(
str
(
desc
[
0
]),
(
ct
.
Structure
,),
dict
(
_fields_
=
fields
))
...
...
tests/cc/test_histogram.py
View file @
6255f1f0
...
...
@@ -5,10 +5,11 @@
from
bcc
import
BPF
from
ctypes
import
c_int
,
c_ulonglong
import
random
import
time
from
unittest
import
main
,
TestCase
class
TestHistogram
(
TestCase
):
def
_
test_simple
(
self
):
def
test_simple
(
self
):
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
#include <linux/bpf.h>
...
...
@@ -52,6 +53,22 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
except
:
pass
b
[
"hist1"
].
print_log2_hist
()
def
test_chars
(
self
):
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
#include <linux/sched.h>
typedef struct { char name[TASK_COMM_LEN]; u64 slot; } Key;
BPF_HISTOGRAM(hist1, Key, 1024);
int kprobe__finish_task_switch(struct pt_regs *ctx, struct task_struct *prev) {
Key k = {.slot = bpf_log2l(prev->real_start_time)};
if (!bpf_get_current_comm(&k.name, sizeof(k.name)))
hist1.increment(k);
return 0;
}
"""
)
for
i
in
range
(
0
,
100
):
time
.
sleep
(
0.01
)
b
[
"hist1"
].
print_log2_hist
()
if
__name__
==
"__main__"
:
main
()
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