Skip to content

Commit c1aefb7

Browse files
author
Don Brady
committed
commas in the output of keys in estat [Backport of #22 to 6.0.3.0]
estat: remove mandatory final positional duration argument estat: too many arguments output when there are too few
1 parent f19c981 commit c1aefb7

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

bpf/standalone/zil.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from bcc import BPF
2424
from time import sleep, strftime
25+
import argparse
2526
import sys
2627
import os
2728
repo_lib_dir = os.path.dirname(__file__) + "/../../lib/"
@@ -46,8 +47,19 @@
4647
#include <sys/zil_impl.h>
4748
"""
4849

49-
if len(sys.argv) > 1:
50-
bpf_text += '#define POOL "' + sys.argv[1] + '"'
50+
parser = argparse.ArgumentParser(
51+
description='Collect zil latency statistics.',
52+
usage='estat zil [options]')
53+
parser.add_argument('-c', '--coll', type=int, action='store',
54+
dest='collection_sec',
55+
help='The collection interval in seconds')
56+
parser.add_argument('-p', '--pool', type=str, action='store',
57+
dest='pool',
58+
help='The pool to monitor (default: domain0)')
59+
args = parser.parse_args()
60+
61+
if (args.pool):
62+
bpf_text += '#define POOL "' + str(args.pool) + '"'
5163
else:
5264
bpf_text += '#define POOL "domain0"'
5365

@@ -276,7 +288,22 @@
276288
BCCHelper.AVERAGE_AGGREGATION, "avg")
277289
alloc_helper.add_key_type("name")
278290

279-
print(" Tracing enabled... Hit Ctrl-C to end.")
291+
if (not args.collection_sec):
292+
print(" Tracing enabled... Hit Ctrl-C to end.")
293+
294+
# Collect data for a collection interval if specified
295+
if (args.collection_sec):
296+
sleep(args.collection_sec)
297+
try:
298+
print("%-16s\n" % strftime("%D - %H:%M:%S %Z"))
299+
latency_helper.printall()
300+
alloc_helper.printall()
301+
exit(0)
302+
except Exception as e:
303+
print(str(e))
304+
exit(0)
305+
306+
# Collect data until keyborad interrupt with output for each second
280307
while (1):
281308
try:
282309
sleep(60)

lib/bcchelper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ def items_to_string(self, agg_items):
571571
stripped_key = ""
572572
try:
573573
stripped_key = keystr[keystr.index(',')+1:len(keystr)-1]
574+
stripped_key = stripped_key.strip()
575+
if stripped_key[-1:] == ",":
576+
stripped_key = stripped_key[:-1]
574577
except ValueError:
575578
pass
576579

0 commit comments

Comments
 (0)