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
60c41924
Commit
60c41924
authored
Feb 09, 2017
by
Sasha Goldshtein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tools to use new BPF.monotonic_time method
parent
d5e24d91
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
80 deletions
+3
-80
tools/memleak.py
tools/memleak.py
+1
-27
tools/old/memleak.py
tools/old/memleak.py
+1
-27
tools/trace.py
tools/trace.py
+1
-26
No files found.
tools/memleak.py
View file @
60c41924
...
@@ -16,34 +16,8 @@ from time import sleep
...
@@ -16,34 +16,8 @@ from time import sleep
from
datetime
import
datetime
from
datetime
import
datetime
import
argparse
import
argparse
import
subprocess
import
subprocess
import
ctypes
import
os
import
os
class
Time
(
object
):
# BPF timestamps come from the monotonic clock. To be able to filter
# and compare them from Python, we need to invoke clock_gettime.
# Adapted from http://stackoverflow.com/a/1205762
CLOCK_MONOTONIC_RAW
=
4
# see <linux/time.h>
class
timespec
(
ctypes
.
Structure
):
_fields_
=
[
(
'tv_sec'
,
ctypes
.
c_long
),
(
'tv_nsec'
,
ctypes
.
c_long
)
]
librt
=
ctypes
.
CDLL
(
'librt.so.1'
,
use_errno
=
True
)
clock_gettime
=
librt
.
clock_gettime
clock_gettime
.
argtypes
=
[
ctypes
.
c_int
,
ctypes
.
POINTER
(
timespec
)]
@
staticmethod
def
monotonic_time
():
t
=
Time
.
timespec
()
if
Time
.
clock_gettime
(
Time
.
CLOCK_MONOTONIC_RAW
,
ctypes
.
pointer
(
t
))
!=
0
:
errno_
=
ctypes
.
get_errno
()
raise
OSError
(
errno_
,
os
.
strerror
(
errno_
))
return
t
.
tv_sec
*
1e9
+
t
.
tv_nsec
class
KStackDecoder
(
object
):
class
KStackDecoder
(
object
):
def
refresh
(
self
):
def
refresh
(
self
):
pass
pass
...
@@ -275,7 +249,7 @@ def print_outstanding():
...
@@ -275,7 +249,7 @@ def print_outstanding():
allocs
=
bpf_program
[
"allocs"
]
allocs
=
bpf_program
[
"allocs"
]
stack_traces
=
bpf_program
[
"stack_traces"
]
stack_traces
=
bpf_program
[
"stack_traces"
]
for
address
,
info
in
sorted
(
allocs
.
items
(),
key
=
lambda
a
:
a
[
1
].
size
):
for
address
,
info
in
sorted
(
allocs
.
items
(),
key
=
lambda
a
:
a
[
1
].
size
):
if
Time
.
monotonic_time
()
-
min_age_ns
<
info
.
timestamp_ns
:
if
BPF
.
monotonic_time
()
-
min_age_ns
<
info
.
timestamp_ns
:
continue
continue
if
info
.
stack_id
<
0
:
if
info
.
stack_id
<
0
:
continue
continue
...
...
tools/old/memleak.py
View file @
60c41924
...
@@ -16,34 +16,8 @@ from time import sleep
...
@@ -16,34 +16,8 @@ from time import sleep
from
datetime
import
datetime
from
datetime
import
datetime
import
argparse
import
argparse
import
subprocess
import
subprocess
import
ctypes
import
os
import
os
class
Time
(
object
):
# BPF timestamps come from the monotonic clock. To be able to filter
# and compare them from Python, we need to invoke clock_gettime.
# Adapted from http://stackoverflow.com/a/1205762
CLOCK_MONOTONIC_RAW
=
4
# see <linux/time.h>
class
timespec
(
ctypes
.
Structure
):
_fields_
=
[
(
'tv_sec'
,
ctypes
.
c_long
),
(
'tv_nsec'
,
ctypes
.
c_long
)
]
librt
=
ctypes
.
CDLL
(
'librt.so.1'
,
use_errno
=
True
)
clock_gettime
=
librt
.
clock_gettime
clock_gettime
.
argtypes
=
[
ctypes
.
c_int
,
ctypes
.
POINTER
(
timespec
)]
@
staticmethod
def
monotonic_time
():
t
=
Time
.
timespec
()
if
Time
.
clock_gettime
(
Time
.
CLOCK_MONOTONIC_RAW
,
ctypes
.
pointer
(
t
))
!=
0
:
errno_
=
ctypes
.
get_errno
()
raise
OSError
(
errno_
,
os
.
strerror
(
errno_
))
return
t
.
tv_sec
*
1e9
+
t
.
tv_nsec
class
StackDecoder
(
object
):
class
StackDecoder
(
object
):
def
__init__
(
self
,
pid
):
def
__init__
(
self
,
pid
):
self
.
pid
=
pid
self
.
pid
=
pid
...
@@ -289,7 +263,7 @@ def print_outstanding():
...
@@ -289,7 +263,7 @@ def print_outstanding():
(
datetime
.
now
().
strftime
(
"%H:%M:%S"
),
top_stacks
))
(
datetime
.
now
().
strftime
(
"%H:%M:%S"
),
top_stacks
))
allocs
=
bpf_program
.
get_table
(
"allocs"
)
allocs
=
bpf_program
.
get_table
(
"allocs"
)
for
address
,
info
in
sorted
(
allocs
.
items
(),
key
=
lambda
a
:
a
[
1
].
size
):
for
address
,
info
in
sorted
(
allocs
.
items
(),
key
=
lambda
a
:
a
[
1
].
size
):
if
Time
.
monotonic_time
()
-
min_age_ns
<
info
.
timestamp_ns
:
if
BPF
.
monotonic_time
()
-
min_age_ns
<
info
.
timestamp_ns
:
continue
continue
stack
=
decoder
.
decode_stack
(
info
,
kernel_trace
)
stack
=
decoder
.
decode_stack
(
info
,
kernel_trace
)
if
stack
in
stacks
:
if
stack
in
stacks
:
...
...
tools/trace.py
View file @
60c41924
...
@@ -20,31 +20,6 @@ import os
...
@@ -20,31 +20,6 @@ import os
import
traceback
import
traceback
import
sys
import
sys
class
Time
(
object
):
# BPF timestamps come from the monotonic clock. To be able to filter
# and compare them from Python, we need to invoke clock_gettime.
# Adapted from http://stackoverflow.com/a/1205762
CLOCK_MONOTONIC_RAW
=
4
# see <linux/time.h>
class
timespec
(
ct
.
Structure
):
_fields_
=
[
(
'tv_sec'
,
ct
.
c_long
),
(
'tv_nsec'
,
ct
.
c_long
)
]
librt
=
ct
.
CDLL
(
'librt.so.1'
,
use_errno
=
True
)
clock_gettime
=
librt
.
clock_gettime
clock_gettime
.
argtypes
=
[
ct
.
c_int
,
ct
.
POINTER
(
timespec
)]
@
staticmethod
def
monotonic_time
():
t
=
Time
.
timespec
()
if
Time
.
clock_gettime
(
Time
.
CLOCK_MONOTONIC_RAW
,
ct
.
pointer
(
t
))
!=
0
:
errno_
=
ct
.
get_errno
()
raise
OSError
(
errno_
,
os
.
strerror
(
errno_
))
return
t
.
tv_sec
*
1e9
+
t
.
tv_nsec
class
Probe
(
object
):
class
Probe
(
object
):
probe_count
=
0
probe_count
=
0
streq_index
=
0
streq_index
=
0
...
@@ -60,7 +35,7 @@ class Probe(object):
...
@@ -60,7 +35,7 @@ class Probe(object):
cls
.
max_events
=
args
.
max_events
cls
.
max_events
=
args
.
max_events
cls
.
print_time
=
args
.
timestamp
or
args
.
time
cls
.
print_time
=
args
.
timestamp
or
args
.
time
cls
.
use_localtime
=
not
args
.
timestamp
cls
.
use_localtime
=
not
args
.
timestamp
cls
.
first_ts
=
Time
.
monotonic_time
()
cls
.
first_ts
=
BPF
.
monotonic_time
()
cls
.
tgid
=
args
.
tgid
or
-
1
cls
.
tgid
=
args
.
tgid
or
-
1
cls
.
pid
=
args
.
pid
or
-
1
cls
.
pid
=
args
.
pid
or
-
1
...
...
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