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
a46c36ae
Commit
a46c36ae
authored
Feb 15, 2017
by
Brenden Blanco
Committed by
GitHub
Feb 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #969 from goldshtn/clock-monotonic
Move monotonic_time to BPF class, use CLOCK_MONOTONIC
parents
63c9d94d
60c41924
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
80 deletions
+27
-80
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+24
-0
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.
src/python/bcc/__init__.py
View file @
a46c36ae
...
...
@@ -115,6 +115,30 @@ class BPF(object):
"linux/netdevice.h"
:
[
"sk_buff"
,
"net_device"
]
}
# 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
=
1
# 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
)]
@
classmethod
def
monotonic_time
(
cls
):
"""monotonic_time()
Returns the system monotonic time from clock_gettime, using the
CLOCK_MONOTONIC constant. The time returned is in nanoseconds.
"""
t
=
cls
.
timespec
()
if
cls
.
_clock_gettime
(
cls
.
CLOCK_MONOTONIC
,
ct
.
pointer
(
t
))
!=
0
:
errno
=
ct
.
get_errno
()
raise
OSError
(
errno
,
os
.
strerror
(
errno
))
return
t
.
tv_sec
*
1e9
+
t
.
tv_nsec
@
classmethod
def
generate_auto_includes
(
cls
,
program_words
):
"""
...
...
tools/memleak.py
View file @
a46c36ae
...
...
@@ -16,34 +16,8 @@ from time import sleep
from
datetime
import
datetime
import
argparse
import
subprocess
import
ctypes
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
):
def
refresh
(
self
):
pass
...
...
@@ -275,7 +249,7 @@ def print_outstanding():
allocs
=
bpf_program
[
"allocs"
]
stack_traces
=
bpf_program
[
"stack_traces"
]
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
if
info
.
stack_id
<
0
:
continue
...
...
tools/old/memleak.py
View file @
a46c36ae
...
...
@@ -16,34 +16,8 @@ from time import sleep
from
datetime
import
datetime
import
argparse
import
subprocess
import
ctypes
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
):
def
__init__
(
self
,
pid
):
self
.
pid
=
pid
...
...
@@ -289,7 +263,7 @@ def print_outstanding():
(
datetime
.
now
().
strftime
(
"%H:%M:%S"
),
top_stacks
))
allocs
=
bpf_program
.
get_table
(
"allocs"
)
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
stack
=
decoder
.
decode_stack
(
info
,
kernel_trace
)
if
stack
in
stacks
:
...
...
tools/trace.py
View file @
a46c36ae
...
...
@@ -20,31 +20,6 @@ import os
import
traceback
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
):
probe_count
=
0
streq_index
=
0
...
...
@@ -60,7 +35,7 @@ class Probe(object):
cls
.
max_events
=
args
.
max_events
cls
.
print_time
=
args
.
timestamp
or
args
.
time
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
.
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