mirror of https://github.com/m-labs/artiq.git
pc_rpc: trace support in server
This commit is contained in:
parent
3e46a36a4d
commit
0abd41a04a
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue