From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lin Ma Subject: [PATCH 2/2] tools/kvm_stat: add '-f help' to get the available event list Date: Tue, 25 Jul 2017 19:05:54 +0800 Message-ID: <20170725110554.15967-3-lma@suse.com> References: <20170725110554.15967-1-lma@suse.com> Cc: pbonzini@redhat.com To: kvm@vger.kernel.org Return-path: Received: from prv3-mh.provo.novell.com ([137.65.250.26]:37758 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750861AbdGYLGX (ORCPT ); Tue, 25 Jul 2017 07:06:23 -0400 In-Reply-To: <20170725110554.15967-1-lma@suse.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Lin Ma --- tools/kvm/kvm_stat/kvm_stat | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/kvm/kvm_stat/kvm_stat b/tools/kvm/kvm_stat/kvm_stat index 5704044..32283d8 100755 --- a/tools/kvm/kvm_stat/kvm_stat +++ b/tools/kvm/kvm_stat/kvm_stat @@ -474,7 +474,7 @@ class Provider(object): @staticmethod def is_field_wanted(fields_filter, field): """Indicate whether field is valid according to fields_filter.""" - if not fields_filter: + if not fields_filter or fields_filter == "help": return True return re.match(fields_filter, field) is not None @@ -1496,7 +1496,8 @@ Press any other key to refresh statistics immediately. action='store', default=DEFAULT_REGEX, dest='fields', - help='fields to display (regex)', + help='''fields to display (regex) + "-f help" for a list of available events''', ) optparser.add_option('-p', '--pid', action='store', @@ -1559,6 +1560,17 @@ def main(): stats = Stats(options) + if options.fields == "help": + event_list = "\n" + s = stats.get() + for key in s.keys(): + if key.find('(') != -1: + key = key[0:key.find('(')] + if event_list.find('\n' + key + '\n') == -1: + event_list += key + '\n' + sys.stdout.write(event_list) + return "" + if options.log: log(stats) elif not options.once: -- 2.9.2