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
921008e0
Commit
921008e0
authored
Aug 29, 2015
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make use of BPF.ksym()
parent
952b3a34
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
38 deletions
+1
-38
tools/vfscount
tools/vfscount
+1
-38
No files found.
tools/vfscount
View file @
921008e0
...
...
@@ -16,43 +16,6 @@ from ctypes import c_ushort, c_int, c_ulonglong
from
time
import
sleep
,
strftime
from
sys
import
stderr
# kernel symbol translation
ksym_addrs
=
[]
# addresses for binary search
ksym_names
=
[]
# same index as ksym_addrs
def
load_kallsyms
():
symfile
=
"/proc/kallsyms"
try
:
syms
=
open
(
symfile
,
"r"
)
except
:
print
(
"ERROR: reading "
+
symfile
,
file
=
sys
.
stderr
)
exit
()
line
=
syms
.
readline
()
for
line
in
iter
(
syms
):
cols
=
line
.
split
()
name
=
cols
[
2
]
if
name
[:
4
]
!=
"vfs_"
:
# perf optimization
continue
addr
=
int
(
cols
[
0
],
16
)
ksym_addrs
.
append
(
addr
)
ksym_names
.
append
(
name
)
syms
.
close
()
def
_ksym_addr2index
(
addr
):
start
=
-
1
end
=
len
(
ksym_addrs
)
while
end
!=
start
+
1
:
mid
=
int
((
start
+
end
)
/
2
)
if
addr
<
ksym_addrs
[
mid
]:
end
=
mid
else
:
start
=
mid
return
start
def
ksym
(
addr
):
idx
=
_ksym_addr2index
(
addr
)
if
idx
==
-
1
:
return
"[unknown]"
return
ksym_names
[
idx
]
load_kallsyms
()
# load BPF program
b
=
BPF
(
src_file
=
"vfscount.c"
)
b
.
attach_kprobe
(
event_re
=
"^vfs_.*"
,
fn_name
=
"do_count"
)
...
...
@@ -69,4 +32,4 @@ except KeyboardInterrupt:
print
(
"
\
n
%-16s %-26s %8s"
%
(
"ADDR"
,
"FUNC"
,
"COUNT"
))
counts
=
b
.
get_table
(
"counts"
)
for
k
,
v
in
sorted
(
counts
.
items
(),
key
=
lambda
counts
:
counts
[
1
].
value
):
print
(
"%-16x %-26s %8d"
%
(
k
.
ip
,
ksym
(
k
.
ip
),
v
.
value
))
print
(
"%-16x %-26s %8d"
%
(
k
.
ip
,
b
.
ksym
(
k
.
ip
),
v
.
value
))
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