diff --git a/bpf/standalone/zil.py b/bpf/standalone/zil.py index 0589e80..14003d9 100755 --- a/bpf/standalone/zil.py +++ b/bpf/standalone/zil.py @@ -22,6 +22,7 @@ from bcc import BPF from time import sleep, strftime +import argparse import sys import os repo_lib_dir = os.path.dirname(__file__) + "/../../lib/" @@ -46,8 +47,19 @@ #include """ -if len(sys.argv) > 1: - bpf_text += '#define POOL "' + sys.argv[1] + '"' +parser = argparse.ArgumentParser( + description='Collect zil latency statistics.', + usage='estat zil [options]') +parser.add_argument('-c', '--coll', type=int, action='store', + dest='collection_sec', + help='The collection interval in seconds') +parser.add_argument('-p', '--pool', type=str, action='store', + dest='pool', + help='The pool to monitor (default: domain0)') +args = parser.parse_args() + +if (args.pool): + bpf_text += '#define POOL "' + str(args.pool) + '"' else: bpf_text += '#define POOL "domain0"' @@ -276,7 +288,22 @@ BCCHelper.AVERAGE_AGGREGATION, "avg") alloc_helper.add_key_type("name") -print(" Tracing enabled... Hit Ctrl-C to end.") +if (not args.collection_sec): + print(" Tracing enabled... Hit Ctrl-C to end.") + +# Collect data for a collection interval if specified +if (args.collection_sec): + sleep(args.collection_sec) + try: + print("%-16s\n" % strftime("%D - %H:%M:%S %Z")) + latency_helper.printall() + alloc_helper.printall() + exit(0) + except Exception as e: + print(str(e)) + exit(0) + +# Collect data until keyborad interrupt with output for each second while (1): try: sleep(60) diff --git a/lib/bcchelper.py b/lib/bcchelper.py index 6690c61..1b54300 100755 --- a/lib/bcchelper.py +++ b/lib/bcchelper.py @@ -571,6 +571,9 @@ def items_to_string(self, agg_items): stripped_key = "" try: stripped_key = keystr[keystr.index(',')+1:len(keystr)-1] + stripped_key = stripped_key.strip() + if stripped_key[-1:] == ",": + stripped_key = stripped_key[:-1] except ValueError: pass