Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
993ef469
Commit
993ef469
authored
Apr 19, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8d23a6cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
10 deletions
+44
-10
go/neo/py/pyruntraced
go/neo/py/pyruntraced
+44
-10
No files found.
go/neo/py/pyruntraced
View file @
993ef469
...
...
@@ -42,7 +42,7 @@ Implementation notes
The channel for tracing communication in between driver and traced process is
passed as opened file descriptor by driver, and its number is specified via
$PYRUNTRACED_FD environment variable
.
<fd> commandline argument
.
The protocol in between driver and traced process is as follows (from the point
of view of traced process):
...
...
@@ -50,14 +50,18 @@ of view of traced process):
> tid T eventname event # event happenned on a thread
< tid C # driver tells tracee to continue execution
< tid !... # driver asks tracee to evaluate ... in context where probe is attached
> tid E
problem
# tracee reports result as exception
> tid E
exception
# tracee reports result as exception
> tid R result # tracee reports result
eventname is just regular string
event,
problem
, result are JSON-encoded objects.
event,
exception
, result are JSON-encoded objects.
Fork is not allowed in order not to confuse the driver(*).
Tracepoints and probes definitions are provided in separate files that are
passed as <trace>* command line arguments.
(*) fork could be supported by making every new process to reattach to the
driver via new file descriptor - e.g. connecting via socket.
...
...
@@ -217,26 +221,57 @@ def trace_entry(func, eventname):
import
os
,
sys
,
code
,
runpy
def
usage
(
out
):
print
>>
out
,
"Usage: pyruntraced <fd> <trace>* -- ..."
def
die
(
msg
):
print
>>
sys
.
stderr
,
msg
sys
.
exit
(
2
)
# main mimics `python ...`,
# but with tracepoints already attached.
def
main
():
argv
=
sys
.
argv
[
1
:]
if
not
argv
:
usage
(
sys
.
stderr
)
sys
.
exit
(
2
)
# setup global tracer
global
gtracer
fdtrace
=
os
.
getenv
(
"PYRUNTRACED_FD"
)
if
fdtrace
is
None
:
print
>>
sys
.
stderr
,
"$PYRUNTRACED_FD must be set"
sys
.
exit
(
1
)
fdtrace
=
argv
[
0
]
fdtrace
=
int
(
fdtrace
)
ftrace
=
os
.
fdopen
(
fdtrace
,
'r+'
)
gtracer
=
Tracer
(
ftrace
)
argv
=
argv
[
1
:]
# forbid fork (see top-level description about why)
def
nofork
():
raise
RuntimeError
(
'pyruntraced: fork forbidden'
)
os
.
fork
=
nofork
os
.
forkpty
=
nofork
# load trace probes
# NOTE list of trace files to load might be empty
tracev
=
[]
dashdash
=
False
for
i
,
arg
in
enumerate
(
argv
):
if
arg
==
'--'
:
dashdash
=
True
break
if
arg
.
startswith
(
'-'
):
die
(
"option '%s' goes before '--'"
%
arg
)
tracev
.
append
(
arg
)
if
not
dashdash
:
die
(
"no '--' found"
)
argv
=
argv
[
i
+
1
:]
for
t
in
tracev
:
# load in current context so that e.g. @trace_entry is visible in the
# tracing code.
execfile
(
t
,
globals
())
# now mimic `python ...`
argv
=
sys
.
argv
[
1
:]
# interactive console
if
not
argv
:
...
...
@@ -260,8 +295,7 @@ def main():
runpy
.
run_module
(
sys
.
argv
[
0
],
init_globals
=
{
'__doc__'
:
None
},
run_name
=
'__main__'
)
elif
argv
[
0
].
startswith
(
'-'
):
print
>>
sys
.
stderr
,
"invalid option '%s'"
%
argv
[
0
]
sys
.
exit
(
2
)
die
(
"invalid option '%s'"
%
argv
[
0
])
# file
else
:
...
...
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