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
5472dbcd
Commit
5472dbcd
authored
Feb 13, 2017
by
4ast
Committed by
GitHub
Feb 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #964 from goldshtn/utools-missing-probes
u* tools: Gracefully handle missing probes
parents
6e1fac41
dc3a57cc
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
21 deletions
+39
-21
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+1
-1
src/python/bcc/usdt.py
src/python/bcc/usdt.py
+27
-9
tools/ucalls.py
tools/ucalls.py
+2
-2
tools/uflow.py
tools/uflow.py
+1
-1
tools/ugc.py
tools/ugc.py
+2
-2
tools/uobjnew.py
tools/uobjnew.py
+3
-3
tools/uthreads.py
tools/uthreads.py
+3
-3
No files found.
src/python/bcc/__init__.py
View file @
5472dbcd
...
...
@@ -1065,4 +1065,4 @@ class BPF(object):
self
.
cleanup
()
from
.usdt
import
USDT
from
.usdt
import
USDT
,
USDTException
src/python/bcc/usdt.py
View file @
5472dbcd
...
...
@@ -13,10 +13,14 @@
# limitations under the License.
import
ctypes
as
ct
import
sys
from
.libbcc
import
lib
,
_USDT_CB
,
_USDT_PROBE_CB
,
\
bcc_usdt_location
,
bcc_usdt_argument
,
\
BCC_USDT_ARGUMENT_FLAGS
class
USDTException
(
Exception
):
pass
class
USDTProbeArgument
(
object
):
def
__init__
(
self
,
argument
):
self
.
signed
=
argument
.
size
<
0
...
...
@@ -77,8 +81,9 @@ class USDTProbeLocation(object):
res
=
lib
.
bcc_usdt_get_argument
(
self
.
probe
.
context
,
self
.
probe
.
name
,
self
.
index
,
index
,
ct
.
pointer
(
arg
))
if
res
!=
0
:
raise
Exception
(
"error retrieving probe argument %d location %d"
%
(
index
,
self
.
index
))
raise
USDTException
(
"error retrieving probe argument %d location %d"
%
(
index
,
self
.
index
))
return
USDTProbeArgument
(
arg
)
class
USDTProbe
(
object
):
...
...
@@ -103,7 +108,7 @@ class USDTProbe(object):
res
=
lib
.
bcc_usdt_get_location
(
self
.
context
,
self
.
name
,
index
,
ct
.
pointer
(
loc
))
if
res
!=
0
:
raise
Exception
(
"error retrieving probe location %d"
%
index
)
raise
USDT
Exception
(
"error retrieving probe location %d"
%
index
)
return
USDTProbeLocation
(
self
,
index
,
loc
)
class
USDT
(
object
):
...
...
@@ -112,20 +117,33 @@ class USDT(object):
self
.
pid
=
pid
self
.
context
=
lib
.
bcc_usdt_new_frompid
(
pid
)
if
self
.
context
==
None
:
raise
Exception
(
"USDT failed to instrument PID %d"
%
pid
)
raise
USDT
Exception
(
"USDT failed to instrument PID %d"
%
pid
)
elif
path
:
self
.
path
=
path
self
.
context
=
lib
.
bcc_usdt_new_frompath
(
path
)
if
self
.
context
==
None
:
raise
Exception
(
"USDT failed to instrument path %s"
%
path
)
raise
USDT
Exception
(
"USDT failed to instrument path %s"
%
path
)
else
:
raise
Exception
(
"either a pid or a binary path must be specified"
)
raise
USDTException
(
"either a pid or a binary path must be specified"
)
def
enable_probe
(
self
,
probe
,
fn_name
):
if
lib
.
bcc_usdt_enable_probe
(
self
.
context
,
probe
,
fn_name
)
!=
0
:
raise
Exception
((
"failed to enable probe '%s'; a possible cause "
+
"can be that the probe requires a pid to enable"
)
%
probe
)
raise
USDTException
(
(
"failed to enable probe '%s'; a possible cause "
+
"can be that the probe requires a pid to enable"
)
%
probe
)
def
enable_probe_or_bail
(
self
,
probe
,
fn_name
):
if
lib
.
bcc_usdt_enable_probe
(
self
.
context
,
probe
,
fn_name
)
!=
0
:
print
(
"""Error attaching USDT probes: the specified pid might not contain the
given language's runtime, or the runtime was not built with the required
USDT probes. Look for a configure flag similar to --with-dtrace or
--enable-dtrace. To check which probes are present in the process, use the
tplist tool."""
)
sys
.
exit
(
1
)
def
get_text
(
self
):
return
lib
.
bcc_usdt_genargs
(
self
.
context
).
decode
()
...
...
tools/ucalls.py
View file @
5472dbcd
...
...
@@ -219,9 +219,9 @@ int syscall_return(struct pt_regs *ctx) {
if
args
.
language
:
usdt
=
USDT
(
pid
=
args
.
pid
)
usdt
.
enable_probe
(
entry_probe
,
"trace_entry"
)
usdt
.
enable_probe
_or_bail
(
entry_probe
,
"trace_entry"
)
if
args
.
latency
:
usdt
.
enable_probe
(
return_probe
,
"trace_return"
)
usdt
.
enable_probe
_or_bail
(
return_probe
,
"trace_return"
)
else
:
usdt
=
None
...
...
tools/uflow.py
View file @
5472dbcd
...
...
@@ -109,7 +109,7 @@ def enable_probe(probe_name, func_name, read_class, read_method, is_return):
.
replace
(
"FILTER_METHOD"
,
filter_method
)
\
.
replace
(
"DEPTH"
,
depth
)
\
.
replace
(
"UPDATE"
,
update
)
usdt
.
enable_probe
(
probe_name
,
func_name
)
usdt
.
enable_probe
_or_bail
(
probe_name
,
func_name
)
usdt
=
USDT
(
pid
=
args
.
pid
)
...
...
tools/ugc.py
View file @
5472dbcd
...
...
@@ -103,8 +103,8 @@ int trace_%s(struct pt_regs *ctx) {
return
text
def
attach
(
self
):
usdt
.
enable_probe
(
self
.
begin
,
"trace_%s"
%
self
.
begin
)
usdt
.
enable_probe
(
self
.
end
,
"trace_%s"
%
self
.
end
)
usdt
.
enable_probe
_or_bail
(
self
.
begin
,
"trace_%s"
%
self
.
begin
)
usdt
.
enable_probe
_or_bail
(
self
.
end
,
"trace_%s"
%
self
.
end
)
def
format
(
self
,
data
):
return
self
.
formatter
(
data
)
...
...
tools/uobjnew.py
View file @
5472dbcd
...
...
@@ -78,7 +78,7 @@ int alloc_entry(struct pt_regs *ctx) {
return 0;
}
"""
usdt
.
enable_probe
(
"object__alloc"
,
"alloc_entry"
)
usdt
.
enable_probe
_or_bail
(
"object__alloc"
,
"alloc_entry"
)
#
# Ruby
#
...
...
@@ -107,10 +107,10 @@ int object_alloc_entry(struct pt_regs *ctx) {
return 0;
}
"""
usdt
.
enable_probe
(
"object__create"
,
"object_alloc_entry"
)
usdt
.
enable_probe
_or_bail
(
"object__create"
,
"object_alloc_entry"
)
for
thing
in
[
"string"
,
"hash"
,
"array"
]:
program
+=
create_template
.
replace
(
"THETHING"
,
thing
)
usdt
.
enable_probe
(
"%s__create"
%
thing
,
"%s_alloc_entry"
%
thing
)
usdt
.
enable_probe
_or_bail
(
"%s__create"
%
thing
,
"%s_alloc_entry"
%
thing
)
#
# C
#
...
...
tools/uthreads.py
View file @
5472dbcd
...
...
@@ -57,7 +57,7 @@ int trace_pthread(struct pt_regs *ctx) {
return 0;
}
"""
usdt
.
enable_probe
(
"pthread_start"
,
"trace_pthread"
)
usdt
.
enable_probe
_or_bail
(
"pthread_start"
,
"trace_pthread"
)
if
args
.
language
==
"java"
:
template
=
"""
...
...
@@ -78,8 +78,8 @@ int %s(struct pt_regs *ctx) {
"""
program
+=
template
%
(
"trace_start"
,
"start"
)
program
+=
template
%
(
"trace_stop"
,
"stop"
)
usdt
.
enable_probe
(
"thread__start"
,
"trace_start"
)
usdt
.
enable_probe
(
"thread__stop"
,
"trace_stop"
)
usdt
.
enable_probe
_or_bail
(
"thread__start"
,
"trace_start"
)
usdt
.
enable_probe
_or_bail
(
"thread__stop"
,
"trace_stop"
)
if
args
.
verbose
:
print
(
usdt
.
get_text
())
...
...
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