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
762b1b45
Commit
762b1b45
authored
Aug 18, 2015
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python 2 & 3 compatibility
parent
177e07eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
14 deletions
+17
-14
examples/disksnoop.py
examples/disksnoop.py
+4
-3
tools/pidpersec
tools/pidpersec
+3
-3
tools/syncsnoop
tools/syncsnoop
+4
-3
tools/vfscount
tools/vfscount
+6
-5
No files found.
examples/disksnoop.py
View file @
762b1b45
...
...
@@ -10,6 +10,7 @@
#
# 11-Aug-2015 Brendan Gregg Created this.
from
__future__
import
print_function
from
bpf
import
BPF
import
sys
...
...
@@ -21,13 +22,13 @@ BPF.attach_kprobe(b.load_func("do_request", BPF.KPROBE), "blk_start_request")
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_completion"
,
BPF
.
KPROBE
),
"blk_update_request"
)
# header
print
"%-18s %-2s %-7s %8s"
%
(
"TIME(s)"
,
"T"
,
"BYTES"
,
"LAT(ms)"
)
print
(
"%-18s %-2s %-7s %8s"
%
(
"TIME(s)"
,
"T"
,
"BYTES"
,
"LAT(ms)"
)
)
# open trace pipe
try
:
trace
=
open
(
"/sys/kernel/debug/tracing/trace_pipe"
,
"r"
)
except
:
print
>>
sys
.
stderr
,
"ERROR: opening trace_pipe"
print
(
"ERROR: opening trace_pipe"
,
file
=
sys
.
stderr
)
exit
(
1
)
# format output
...
...
@@ -49,4 +50,4 @@ while 1:
type_s
=
"R"
ms
=
float
(
int
(
us_s
,
10
))
/
1000
print
"%-18s %-2s %-7s %8.2f"
%
(
time_s
,
type_s
,
bytes_s
,
ms
)
print
(
"%-18s %-2s %-7s %8.2f"
%
(
time_s
,
type_s
,
bytes_s
,
ms
)
)
tools/pidpersec
View file @
762b1b45
...
...
@@ -25,7 +25,7 @@ stats = b.get_table("stats")
S_COUNT
=
1
# header
print
"Tracing... Ctrl-C to end."
print
(
"Tracing... Ctrl-C to end."
)
# output
last
=
0
...
...
@@ -35,6 +35,6 @@ while (1):
except
KeyboardInterrupt
:
pass
;
exit
()
print
"%s: PIDs/sec: %d"
%
(
strftime
(
"%H:%M:%S"
),
(
stats
[
c_int
(
S_COUNT
)].
value
-
last
))
print
(
"%s: PIDs/sec: %d"
%
(
strftime
(
"%H:%M:%S"
),
(
stats
[
c_int
(
S_COUNT
)].
value
-
last
))
)
last
=
stats
[
c_int
(
S_COUNT
)].
value
tools/syncsnoop
View file @
762b1b45
...
...
@@ -11,6 +11,7 @@
#
# 13-Aug-2015 Brendan Gregg Created this.
from
__future__
import
print_function
from
bpf
import
BPF
import
sys
...
...
@@ -24,13 +25,13 @@ int do_sync(void *ctx) {
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_sync"
,
BPF
.
KPROBE
),
"sys_sync"
)
# header
print
"%-18s %s"
%
(
"TIME(s)"
,
"CALL"
)
print
(
"%-18s %s"
%
(
"TIME(s)"
,
"CALL"
)
)
# open trace pipe
try
:
trace
=
open
(
"/sys/kernel/debug/tracing/trace_pipe"
,
"r"
)
except
:
print
>>
sys
.
stderr
,
"ERROR: opening trace_pipe"
print
(
"ERROR: opening trace_pipe"
,
file
=
sys
.
stderr
)
exit
(
1
)
# format output
...
...
@@ -43,4 +44,4 @@ while 1:
prolog
,
time_s
,
colon
,
word
=
line
.
rsplit
(
" "
,
3
)
time_s
=
time_s
[:
-
1
]
# strip trailing ":"
print
"%-18s %s"
%
(
time_s
,
word
)
print
(
"%-18s %s"
%
(
time_s
,
word
)
)
tools/vfscount
View file @
762b1b45
...
...
@@ -10,6 +10,7 @@
#
# 14-Aug-2015 Brendan Gregg Created this.
from
__future__
import
print_function
from
bpf
import
BPF
from
ctypes
import
c_ushort
,
c_int
,
c_ulonglong
from
time
import
sleep
,
strftime
...
...
@@ -23,7 +24,7 @@ def load_kallsyms():
try
:
syms
=
open
(
symfile
,
"r"
)
except
:
print
>>
stderr
,
"ERROR: reading "
+
symfile
print
(
"ERROR: reading "
+
symfile
,
file
=
sys
.
stderr
)
exit
()
line
=
syms
.
readline
()
for
line
in
iter
(
syms
):
...
...
@@ -39,7 +40,7 @@ def ksym(addr):
start
=
-
1
end
=
len
(
ksym_addrs
)
while
end
!=
start
+
1
:
mid
=
(
start
+
end
)
/
2
mid
=
int
((
start
+
end
)
/
2
)
if
addr
<
ksym_addrs
[
mid
]:
end
=
mid
else
:
...
...
@@ -60,7 +61,7 @@ BPF.attach_kprobe(fn, "vfs_create")
counts
=
b
.
get_table
(
"counts"
)
# header
print
"Tracing... Ctrl-C to end."
print
(
"Tracing... Ctrl-C to end."
)
# output
try
:
...
...
@@ -68,6 +69,6 @@ try:
except
KeyboardInterrupt
:
pass
print
"
\
n
%-16s %-12s %8s"
%
(
"ADDR"
,
"FUNC"
,
"COUNT"
)
print
(
"
\
n
%-16s %-12s %8s"
%
(
"ADDR"
,
"FUNC"
,
"COUNT"
)
)
for
k
,
v
in
sorted
(
counts
.
items
(),
key
=
lambda
counts
:
counts
[
1
].
value
):
print
"%-16x %-12s %8d"
%
(
k
.
ip
,
ksym
(
k
.
ip
),
v
.
value
)
print
(
"%-16x %-12s %8d"
%
(
k
.
ip
,
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