daemon {type.id|path} <cmd>
Same as --admin-daemon, but auto-find admin socket
daemonperf {type.id | path} [stat-pats] [priority] [<interval>] [<count>]
+daemonperf {type.id | path} list [stat-pats] [priority]
Get selected perf stats from daemon/admin socket
Optional shell-glob comma-delim match string stat-pats
Optional selection priority (can abbreviate name):
critical, interesting, useful, noninteresting, debug
+ List shows a table of all available stats
Run <count> times (default forever),
once per <interval> seconds (default 1)
""", file=sys.stdout)
Handle daemonperf command; returns errno or 0
daemonperf <daemon> [priority string] [statpats] [interval] [count]
+ daemonperf <daemon> list [statpats]
"""
interval = 1
count = None
statpats = None
priority = None
+ do_list = False
def prio_from_name(arg):
# consume and analyze non-numeric args
while len(childargs) and not isnum(childargs[0]):
arg = childargs.pop(0)
+ # 'list'?
+ if arg == 'list':
+ do_list = True;
+ continue;
# prio?
priority = prio_from_name(arg)
if priority is not None:
return errno.EINVAL
count = int(arg)
- DaemonWatcher(sockpath, statpats, priority).run(interval, count)
+ watcher = DaemonWatcher(sockpath, statpats, priority)
+ if do_list:
+ watcher.list()
+ else:
+ watcher.run(interval, count)
return 0
from collections import OrderedDict
from fcntl import ioctl
from fnmatch import fnmatch
+from prettytable import PrettyTable, HEADER
from signal import signal, SIGWINCH
from termios import TIOCGWINSZ
def _gettermsize():
return struct.unpack('hhhh', ioctl(0, TIOCGWINSZ, 8*'\x00'))[0:2]
+
class Termsize(object):
def __init__(self):
except KeyboardInterrupt:
return
+
+ def list(self, ostr=sys.stdout):
+ """
+ Show all selected stats with section, full name, nick, and prio
+ """
+ table = PrettyTable(('section', 'name', 'nick', 'prio'))
+ table.align['section'] = 'l'
+ table.align['name'] = 'l'
+ table.align['nick'] = 'l'
+ table.align['prio'] = 'r'
+ self._load_schema()
+ for section_name, section_stats in self._stats.items():
+ for name, nick in section_stats.items():
+ prio = self._schema[section_name][name].get('priority') or 0
+ table.add_row((section_name, name, nick, prio))
+ ostr.write(table.get_string(hrules=HEADER) + '\n')