From patchwork Fri Jan 23 20:56:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 432304 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7406A140285 for ; Sat, 24 Jan 2015 08:02:44 +1100 (AEDT) Received: from localhost ([::1]:33133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YElNK-0002XV-OL for incoming@patchwork.ozlabs.org; Fri, 23 Jan 2015 16:02:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YElJt-0004p2-UI for qemu-devel@nongnu.org; Fri, 23 Jan 2015 15:59:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YElJn-0000i9-Q9 for qemu-devel@nongnu.org; Fri, 23 Jan 2015 15:59:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YElJn-0000hp-Jc for qemu-devel@nongnu.org; Fri, 23 Jan 2015 15:59:03 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0NKx11G005495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 23 Jan 2015 15:59:01 -0500 Received: from apm-mustang-ev3-09.ml3.eng.bos.redhat.com (apm-mustang-ev3-09.ml3.eng.bos.redhat.com [10.19.176.141]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0NKwxNX007446; Fri, 23 Jan 2015 15:59:01 -0500 From: Wei Huang To: qemu-devel@nongnu.org Date: Fri, 23 Jan 2015 15:56:02 -0500 Message-Id: <1422046564-10270-3-git-send-email-wei@redhat.com> In-Reply-To: <1422046564-10270-1-git-send-email-wei@redhat.com> References: <1422046564-10270-1-git-send-email-wei@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH V3 2/4] kvm_stat: Print errno when syscall to perf_event_open() fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org kvm_stat uses syscall() to call perf_event_open(). If this function call fails, the returned value is -1, which doesn't tell the details of the failure (i.e. ENOSYS or EINVAL). This patch retrieves errno and prints it when syscall() fails. The error message will look like "Exception: perf_event_open failed, errno = 38". Signed-off-by: Wei Huang --- scripts/kvm/kvm_stat | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 7ec84c0..cb23877 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -13,6 +13,7 @@ import curses import sys, os, time, optparse, ctypes +from ctypes import * class DebugfsProvider(object): def __init__(self): @@ -239,6 +240,9 @@ import struct, array libc = ctypes.CDLL('libc.so.6') syscall = libc.syscall +get_errno = libc.__errno_location +get_errno.restype = POINTER(c_int) + class perf_event_attr(ctypes.Structure): _fields_ = [('type', ctypes.c_uint32), ('size', ctypes.c_uint32), @@ -322,7 +326,8 @@ class Event(object): group_leader = group.events[0].fd fd = _perf_event_open(attr, -1, group.cpu, group_leader, 0) if fd == -1: - raise Exception('perf_event_open failed') + err = get_errno()[0] + raise Exception('perf_event_open failed, errno = ' + err.__str__()) if filter: import fcntl fcntl.ioctl(fd, ioctl_numbers['SET_FILTER'], filter)