@@ -47,6 +47,22 @@ class DflyStartException(Exception):
47
47
pass
48
48
49
49
50
+ def symbolize_stack_trace (binary_path , lines ):
51
+ pattern = rb"@\s*(0x[0-9a-fA-F]+)"
52
+ matcher = re .compile (pattern )
53
+ addr2line_proc = subprocess .Popen (
54
+ ["/usr/bin/addr2line" , "-fCa" , "-e" , binary_path ], stdin = subprocess .PIPE
55
+ )
56
+ for line in lines :
57
+ res = matcher .search (line )
58
+ if res :
59
+ g = res .group (1 ) + b"\n "
60
+ addr2line_proc .stdin .write (g )
61
+
62
+ addr2line_proc .stdin .close ()
63
+ addr2line_proc .wait ()
64
+
65
+
50
66
class DflyInstance :
51
67
"""
52
68
Represents a runnable and stoppable Dragonfly instance
@@ -60,8 +76,9 @@ def __init__(self, params: DflyParams, args):
60
76
self .proc : Optional [subprocess .Popen ] = None
61
77
self ._client : Optional [RedisClient ] = None
62
78
self .log_files : List [str ] = []
63
-
64
79
self .dynamic_port = False
80
+ self .sed_proc = None
81
+
65
82
if self .params .existing_port :
66
83
self ._port = self .params .existing_port
67
84
elif "port" in self .args :
@@ -150,7 +167,7 @@ def _wait_for_server(self):
150
167
sed_cmd = ["sed" , "-u" , "-e" , sed_format ]
151
168
if self .params .buffered_out :
152
169
sed_cmd .remove ("-u" )
153
- subprocess .Popen (sed_cmd , stdin = self .proc .stdout )
170
+ self . sed_proc = subprocess .Popen (sed_cmd , stdin = self .proc .stdout , stdout = subprocess . PIPE )
154
171
155
172
def set_proc_to_none (self ):
156
173
self .proc = None
@@ -188,6 +205,18 @@ def stop(self, kill=False):
188
205
proc .kill ()
189
206
proc .communicate ()
190
207
raise Exception ("Unable to terminate DragonflyDB gracefully, it was killed" )
208
+ finally :
209
+ if self .sed_proc :
210
+ sed_out = self .sed_proc .stdout .readlines ()
211
+
212
+ # Deduplicate output - we somewhere duplicate the output, probably due
213
+ # to tty redirections.
214
+ seen = set ()
215
+ sed_out = [x for x in sed_out if not (x in seen or seen .add (x ))]
216
+
217
+ for str in sed_out :
218
+ print (str .decode ())
219
+ symbolize_stack_trace (proc .args [0 ], sed_out )
191
220
192
221
def _start (self ):
193
222
if self .params .existing_port :
0 commit comments