Received: from eggs.gnu.org ([2001:4830:134:3::10]:43524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQt1B-0001og-MS for qemu-devel@nongnu.org; Wed, 03 Feb 2016 03:42:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQt18-0004Md-EL for qemu-devel@nongnu.org; Wed, 03 Feb 2016 03:42:29 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:60001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQt18-0004MN-53 for qemu-devel@nongnu.org; Wed, 03 Feb 2016 03:42:26 -0500 Received: from localhost by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 3 Feb 2016 08:42:24 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8940A17D805A for ; Wed, 3 Feb 2016 08:42:32 +0000 (GMT) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u138gKsi4456830 for ; Wed, 3 Feb 2016 08:42:20 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u138gKc9023299 for ; Wed, 3 Feb 2016 01:42:20 -0700 From: Janosch Frank Date: Wed, 3 Feb 2016 09:40:47 +0100 Message-Id: <1454488847-46617-1-git-send-email-frankja@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2] scripts/kvm/kvm_stat: Fix tracefs access checking List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: frankja@linux.vnet.ibm.com, borntraeger@de.ibm.com, pbonzini@redhat.com On kernels build without CONFIG_TRACING kvm_stat will bail out even when traces are not used. This is not very helpful, especially if the user can't install a new kernel. Instead, we should warn the user and fall back to debugfs statistics. These changes check if trace statistics were selected without kernel support and warn the user. If they were not selected explicitly, we wait five seconds to let the user read the warning and then set the debugfs statistics to True and the tracefs ones to False. Otherwise we exit. Fixes: 7aa4ee5 ('scripts/kvm/kvm_stat: Improve debugfs access checking') Signed-off-by: Janosch Frank --- v1 to v2: Exit if -t is set explicitly scripts/kvm/kvm_stat | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index d43e8f3..4756eee 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -22,6 +22,7 @@ import resource import struct import re from collections import defaultdict +from time import sleep VMX_EXIT_REASONS = { 'EXCEPTION_NMI': 0, @@ -778,7 +779,7 @@ def get_providers(options): return providers -def check_access(): +def check_access(options): if not os.path.exists('/sys/kernel/debug'): sys.stderr.write('Please enable CONFIG_DEBUG_FS in your kernel.') sys.exit(1) @@ -790,14 +791,26 @@ def check_access(): "Also ensure, that the kvm modules are loaded.\n") sys.exit(1) - if not os.path.exists(PATH_DEBUGFS_TRACING): - sys.stderr.write("Please make {0} readable by the current user.\n" + if not os.path.exists(PATH_DEBUGFS_TRACING) and (options.tracepoints + or not options.debugfs): + sys.stderr.write("Please enable CONFIG_TRACING in your kernel " + "when using the option -t (default).\n" + "If it is enabled, make {0} readable by the " + "current user.\n" .format(PATH_DEBUGFS_TRACING)) - sys.exit(1) + + if options.tracepoints: + sys.exit(1) + + sys.stderr.write("Falling back to debugfs statistics!\n") + options.debugfs = True + sleep(5) + + return options def main(): - check_access() options = get_options() + options = check_access(options) providers = get_providers(options) stats = Stats(providers, fields=options.fields) -- 2.3.0