From 0abd41a04a1d77354db3d3f59c4dab57a67843e6 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 27 Feb 2015 00:17:11 -0700 Subject: [PATCH] pc_rpc: trace support in server --- artiq/frontend/artiq_client.py | 10 +++++----- artiq/gui/scheduler.py | 10 +++++----- artiq/protocols/pc_rpc.py | 18 ++++++++++++++++++ artiq/tools.py | 8 ++++---- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/artiq/frontend/artiq_client.py b/artiq/frontend/artiq_client.py index 89378e96f..dadcae572 100755 --- a/artiq/frontend/artiq_client.py +++ b/artiq/frontend/artiq_client.py @@ -12,7 +12,7 @@ from prettytable import PrettyTable from artiq.protocols.pc_rpc import Client from artiq.protocols.sync_struct import Subscriber from artiq.protocols import pyon -from artiq.tools import format_run_arguments +from artiq.tools import format_arguments def clear_screen(): @@ -151,8 +151,8 @@ def _show_queue(queue): for rid, run_params in queue: row = [rid, run_params["file"]] for x in run_params["unit"], run_params["timeout"]: - row.append("-" if x is None else x) - row.append(format_run_arguments(run_params["arguments"])) + row.append("" if x is None else x) + row.append(format_arguments(run_params["arguments"])) table.add_row(row) print(table) else: @@ -169,8 +169,8 @@ def _show_timed(timed): row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)), trid, run_params["file"]] for x in run_params["unit"], run_params["timeout"]: - row.append("-" if x is None else x) - row.append(format_run_arguments(run_params["arguments"])) + row.append("" if x is None else x) + row.append(format_arguments(run_params["arguments"])) table.add_row(row) print(table) else: diff --git a/artiq/gui/scheduler.py b/artiq/gui/scheduler.py index 8854354a6..14755000b 100644 --- a/artiq/gui/scheduler.py +++ b/artiq/gui/scheduler.py @@ -5,7 +5,7 @@ from gi.repository import Gtk from artiq.gui.tools import Window, ListSyncer, DictSyncer from artiq.protocols.sync_struct import Subscriber -from artiq.tools import format_run_arguments +from artiq.tools import format_arguments class _QueueStoreSyncer(ListSyncer): @@ -13,8 +13,8 @@ class _QueueStoreSyncer(ListSyncer): rid, run_params = x row = [rid, run_params["file"]] for e in run_params["unit"], run_params["timeout"]: - row.append("-" if e is None else str(e)) - row.append(format_run_arguments(run_params["arguments"])) + row.append("" if e is None else str(e)) + row.append(format_arguments(run_params["arguments"])) return row @@ -28,8 +28,8 @@ class _TimedStoreSyncer(DictSyncer): row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)), trid, run_params["file"]] for e in run_params["unit"], run_params["timeout"]: - row.append("-" if e is None else str(e)) - row.append(format_run_arguments(run_params["arguments"])) + row.append("" if e is None else str(e)) + row.append(format_arguments(run_params["arguments"])) return row diff --git a/artiq/protocols/pc_rpc.py b/artiq/protocols/pc_rpc.py index 8de2a3615..da2c5ae66 100644 --- a/artiq/protocols/pc_rpc.py +++ b/artiq/protocols/pc_rpc.py @@ -22,6 +22,7 @@ import inspect from artiq.protocols import pyon from artiq.protocols.asyncio_server import AsyncioServer as _AsyncioServer +from artiq.tools import format_arguments logger = logging.getLogger(__name__) @@ -373,6 +374,22 @@ class BestEffortClient: return proxy +class _PrettyPrintCall: + def __init__(self, obj): + self.obj = obj + + def __str__(self): + r = self.obj["name"] + "(" + args = ", ".join([repr(a) for a in self.obj["args"]]) + r += args + kwargs = format_arguments(self.obj["kwargs"]) + if args and kwargs: + r += ", " + r += kwargs + r += ")" + return r + + class Server(_AsyncioServer): """This class creates a TCP server that handles requests coming from ``Client`` objects. @@ -435,6 +452,7 @@ class Server(_AsyncioServer): inspect.getdoc(method)) obj = {"status": "ok", "ret": methods} elif obj["action"] == "call": + logger.debug("calling %s", _PrettyPrintCall(obj)) method = getattr(target, obj["name"]) ret = method(*obj["args"], **obj["kwargs"]) obj = {"status": "ok", "ret": ret} diff --git a/artiq/tools.py b/artiq/tools.py index 619fab412..e63d4b109 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -6,14 +6,14 @@ import sys import os.path -def format_run_arguments(arguments): +def format_arguments(arguments): fmtargs = [] for k, v in sorted(arguments.items(), key=itemgetter(0)): - fmtargs.append(k + "=" + str(v)) + fmtargs.append(k + "=" + repr(v)) if fmtargs: - return " ".join(fmtargs) + return ", ".join(fmtargs) else: - return "-" + return "" def file_import(filename):