From 086e501be397b3e14693b2dfd6a235dcc86844a0 Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Mon, 1 Feb 2016 18:21:28 -0800 Subject: util: ec3po: Add OOBM queue and dynamic loglevels. This commit adds an Out Of Band Managament queue which will allow the console to receive commands outside of the PTY which it can take action on. The first use of this is to dynamically change the logging level. Prior to this change, changing the log level using dut-control would not affect the log level of the console or interpreter. BUG=None BRANCH=None TEST=Launch modified servod; issue dut-control loglevel:debug, verify that debug messages from both servod and ec3po are emitted. Then issue dut-control loglevel:info and verify that no debug messages from either are emitted. Change-Id: I692824742b018da9540a81305985f6f355f716e6 Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/325134 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Randall Spangler --- util/ec3po/console.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'util/ec3po/console.py') diff --git a/util/ec3po/console.py b/util/ec3po/console.py index 2a426ac700..e75523e80b 100755 --- a/util/ec3po/console.py +++ b/util/ec3po/console.py @@ -86,6 +86,8 @@ class Console(object): dbg_pipe: A multiprocessing.Connection object which represents the console's read-only side of the debug pipe. This must be a unidirectional pipe attached to the intepreter. EC debug messages use this pipe. + oobm_queue: A multiprocessing.Queue which is used for out of band management + for the interactive console. input_buffer: A string representing the current input command. input_buffer_pos: An integer representing the current position in the buffer to insert a char. @@ -127,6 +129,7 @@ class Console(object): self.user_pty = user_pty self.cmd_pipe = cmd_pipe self.dbg_pipe = dbg_pipe + self.oobm_queue = multiprocessing.Queue() self.input_buffer = '' self.input_buffer_pos = 0 self.partial_cmd = '' @@ -145,6 +148,7 @@ class Console(object): string.append('user_pty: %s' % self.user_pty) string.append('cmd_pipe: %s' % self.cmd_pipe) string.append('dbg_pipe: %s' % self.dbg_pipe) + string.append('oobm_queue: %s' % self.oobm_queue) string.append('input_buffer: %s' % self.input_buffer) string.append('input_buffer_pos: %d' % self.input_buffer_pos) string.append('esc_state: %d' % self.esc_state) @@ -695,6 +699,19 @@ def StartLoop(console): console.logger.debug('|DBG|->\'%s\'', data) os.write(console.master_pty, data) + while not console.oobm_queue.empty(): + console.logger.debug('OOBM queue ready for reading.') + cmd = console.oobm_queue.get() + console.logger.debug('cmd: %s', cmd) + if cmd.startswith('loglevel'): + console.logger.debug('Log level change request.') + new_log_level = int(cmd.split(' ')[1]) + console.logger.logger.setLevel(new_log_level) + console.logger.info('Log level changed to %d.', new_log_level) + + # Forward the request to the interpreter as well. + console.cmd_pipe.send(cmd) + finally: # Close pipes. console.dbg_pipe.close() -- cgit v1.2.1