From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeFh-0001jL-JG for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:19:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIeFf-0001un-2U for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:19:25 -0500 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:43321) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeFe-0001uE-OX for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:19:22 -0500 Received: from localhost by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Jan 2016 15:19:22 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 483331B08069 for ; Mon, 11 Jan 2016 15:19:21 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0BFJKKG47054860 for ; Mon, 11 Jan 2016 15:19:20 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0BFJKQC019035 for ; Mon, 11 Jan 2016 08:19:20 -0700 From: Janosch Frank Date: Mon, 11 Jan 2016 16:17:59 +0100 Message-Id: <1452525484-32309-30-git-send-email-frankja@linux.vnet.ibm.com> In-Reply-To: <1452525484-32309-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1452525484-32309-1-git-send-email-frankja@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 29/34] scripts/kvm/kvm_stat: Cleanup and pre-init perf_event_attr List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: pbonzini@redhat.com Cc: frankja@linux.vnet.ibm.com, qemu-devel@nongnu.org All initializations of the ctypes struct that don't need additional information were moved to its init method. The unneeded initializations for sample_type and sample_period were removed as they do not affect the counters that are read. This improves readability of the setup_event_attribute by halfing its LOC. Signed-off-by: Janosch Frank --- scripts/kvm/kvm_stat | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 3c32046..ea5bae8 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -331,6 +331,13 @@ class perf_event_attr(ctypes.Structure): ('bp_addr', ctypes.c_uint64), ('bp_len', ctypes.c_uint64), ] + + def __init__(self): + super(self.__class__, self).__init__() + self.type = PERF_TYPE_TRACEPOINT + self.size = ctypes.sizeof(self) + self.read_format = PERF_FORMAT_GROUP + def perf_event_open(attr, pid, cpu, group_fd, flags): return syscall(ARCH.sc_perf_evt_open, ctypes.pointer(attr), ctypes.c_int(pid), ctypes.c_int(cpu), @@ -369,11 +376,7 @@ class Event(object): trace_point, 'id') event_attr = perf_event_attr() - event_attr.type = PERF_TYPE_TRACEPOINT - event_attr.size = ctypes.sizeof(event_attr) event_attr.config = int(open(id_path).read()) - event_attr.sample_period = 1 - event_attr.read_format = PERF_FORMAT_GROUP return event_attr def setup_event(self, group, trace_cpu, trace_point, trace_filter, -- 2.3.0