Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
547cde90
Commit
547cde90
authored
Apr 19, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
993ef469
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
go/neo/py/pyruntraced
go/neo/py/pyruntraced
+16
-9
No files found.
go/neo/py/pyruntraced
View file @
547cde90
...
...
@@ -78,12 +78,18 @@ import thread, threading
# See top-level module description for details.
class
Tracer
(
object
):
def
__init__
(
self
,
ftrace
):
self
.
ftrace
=
ftrace
# file object to communicate with tracer
self
.
txlock
=
threading
.
Lock
()
# serializes writes to .ftrace
def
__init__
(
self
,
ftracetx
,
ftracerx
):
self
.
ftx
=
ftracetx
# file object to send data to tracer
self
.
txlock
=
threading
.
Lock
()
# serializes writes to .ftx
self
.
frx
=
ftracerx
# file object to receive data from tracer
self
.
rxtab
=
{}
# {} tid -> RxQueue
self
.
rxlock
=
threading
.
Lock
()
# serializes access to .rxtab
# NOTE 2 separate ftx/frx file objects are used because python for
# stdio objects does locking and this way if it would be only 1 file
# object readline in _serve_recv() would block tx until readline wakes up.
self
.
trecv
=
threading
.
Thread
(
target
=
self
.
_serve_recv
)
self
.
trecv
.
daemon
=
True
# XXX better to gracefully stop it?
self
.
trecv
.
start
()
...
...
@@ -95,18 +101,18 @@ class Tracer(object):
tid
=
thread
.
get_ident
()
self
.
txlock
.
acquire
()
try
:
self
.
ft
race
.
write
((
'%d '
%
tid
)
+
line
+
'
\
n
'
)
self
.
ft
race
.
flush
()
self
.
ft
x
.
write
((
'%d '
%
tid
)
+
line
+
'
\
n
'
)
self
.
ft
x
.
flush
()
finally
:
self
.
txlock
.
release
()
# _serve_recv receives lines from .f
trace
and multiplexes them to
# _serve_recv receives lines from .f
rx
and multiplexes them to
# destination threads RX queues.
#
# runs in a dedicated thread.
def
_serve_recv
(
self
):
while
1
:
line
=
self
.
f
trace
.
readline
()
line
=
self
.
f
rx
.
readline
()
# tid SP rest \n
tid
,
line
=
line
.
split
(
None
,
1
)
line
=
line
.
rstrip
(
'
\
n
'
)
...
...
@@ -240,8 +246,9 @@ def main():
global
gtracer
fdtrace
=
argv
[
0
]
fdtrace
=
int
(
fdtrace
)
ftrace
=
os
.
fdopen
(
fdtrace
,
'r+'
)
gtracer
=
Tracer
(
ftrace
)
ttx
=
os
.
fdopen
(
fdtrace
,
'w'
)
trx
=
os
.
fdopen
(
fdtrace
,
'r'
)
gtracer
=
Tracer
(
ttx
,
trx
)
argv
=
argv
[
1
:]
# forbid fork (see top-level description about why)
...
...
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