From 8f8951b4c1caf9bf5667a22b146ba22d184208e1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 27 Sep 2017 11:54:10 -0400 Subject: [PATCH] serialhdl: Make dump_debug() output atomic Build a single (very large) logging message with the debug state. This prevents the output from being fragmented. Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 4 ++-- klippy/serialhdl.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index f618f582..14bf5817 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -451,8 +451,8 @@ class MCU: return self._is_shutdown = True self._shutdown_msg = msg = params['#msg'] - logging.info("%s: %s", params['#name'], self._shutdown_msg) - self._serial.dump_debug() + logging.info("MCU '%s' %s: %s\n%s", self._name, params['#name'], + self._shutdown_msg, self._serial.dump_debug()) prefix = "MCU '%s' shutdown: " % (self._name,) if params['#name'] == 'is_shutdown': prefix = "Previous MCU '%s' shutdown: " % (self._name,) diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index ed7b3274..411c77b1 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -141,26 +141,28 @@ class SerialReader: self.ffi_lib.serialqueue_free_commandqueue) # Dumping debug lists def dump_debug(self): - logging.info("Dumping serial stats: %s" - , self.stats(self.reactor.monotonic())) + out = [] + out.append("Dumping serial stats: %s" % ( + self.stats(self.reactor.monotonic()),)) sdata = self.ffi_main.new('struct pull_queue_message[1024]') rdata = self.ffi_main.new('struct pull_queue_message[1024]') scount = self.ffi_lib.serialqueue_extract_old( self.serialqueue, 1, sdata, len(sdata)) rcount = self.ffi_lib.serialqueue_extract_old( self.serialqueue, 0, rdata, len(rdata)) - logging.info("Dumping send queue %d messages" % (scount,)) + out.append("Dumping send queue %d messages" % (scount,)) for i in range(scount): msg = sdata[i] cmds = self.msgparser.dump(msg.msg[0:msg.len]) - logging.info("Sent %d %f %f %d: %s" % ( + out.append("Sent %d %f %f %d: %s" % ( i, msg.receive_time, msg.sent_time, msg.len, ', '.join(cmds))) - logging.info("Dumping receive queue %d messages" % (rcount,)) + out.append("Dumping receive queue %d messages" % (rcount,)) for i in range(rcount): msg = rdata[i] cmds = self.msgparser.dump(msg.msg[0:msg.len]) - logging.info("Receive: %d %f %f %d: %s" % ( + out.append("Receive: %d %f %f %d: %s" % ( i, msg.receive_time, msg.sent_time, msg.len, ', '.join(cmds))) + return '\n'.join(out) # Default message handlers def handle_unknown(self, params): logging.warn("Unknown message type %d: %s" % (