From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706s-0003JE-8o for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a706n-0003qk-NR for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:10 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:58679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706n-0003qO-E6 for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:05 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Dec 2015 12:14:04 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id E5F0717D8056 for ; Thu, 10 Dec 2015 12:14:31 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBACDxn610813930 for ; Thu, 10 Dec 2015 12:13:59 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tBACDwnX025533 for ; Thu, 10 Dec 2015 05:13:59 -0700 From: Janosch Frank Date: Thu, 10 Dec 2015 13:13:00 +0100 Message-Id: <1449749584-23214-31-git-send-email-frankja@linux.vnet.ibm.com> In-Reply-To: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 30/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: qemu-devel@nongnu.org Cc: cornelia.huck@de.ibm.com, frankja@linux.vnet.ibm.com 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. --- 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 109c22c..ab10b1a 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -312,6 +312,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), @@ -348,11 +355,7 @@ class Event(object): tracepoint, '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, event_data): -- 2.3.0