From patchwork Thu Dec 10 12:12:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 555243 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 DA5A4140307 for ; Fri, 11 Dec 2015 05:05:48 +1100 (AEDT) Received: from localhost ([::1]:43582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a75b8-00038v-QB for incoming@patchwork.ozlabs.org; Thu, 10 Dec 2015 13:05:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706k-0003HU-FX for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a706g-0003mC-E1 for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:02 -0500 Received: from e06smtp06.uk.ibm.com ([195.75.94.102]:43507) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706g-0003lH-4P for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:13:58 -0500 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Dec 2015 12:13:55 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp06.uk.ibm.com (192.168.101.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 10 Dec 2015 12:13:53 -0000 X-IBM-Helo: d06dlp03.portsmouth.uk.ibm.com X-IBM-MailFrom: frankja@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 3F41C1B0805F for ; Thu, 10 Dec 2015 12:14:22 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBACDqKo10355138 for ; Thu, 10 Dec 2015 12:13:52 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 tBACDqTn024981 for ; Thu, 10 Dec 2015 05:13:52 -0700 Received: from s38lp20.boeblingen.de.ibm.com (dyn-9-152-224-47.boeblingen.de.ibm.com [9.152.224.47]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tBACDpiU024936; Thu, 10 Dec 2015 05:13:52 -0700 From: Janosch Frank To: qemu-devel@nongnu.org Date: Thu, 10 Dec 2015 13:12:31 +0100 Message-Id: <1449749584-23214-2-git-send-email-frankja@linux.vnet.ibm.com> X-Mailer: git-send-email 2.3.0 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> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15121012-0025-0000-0000-00000534189A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.102 X-Mailman-Approved-At: Thu, 10 Dec 2015 13:02:43 -0500 Cc: cornelia.huck@de.ibm.com, frankja@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 01/34] scripts/kvm/kvm_stat: Cleanup of multiple imports 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 Removed multiple imports of the same module and moved all imports to the top. It is not necessary to import a module each time one of its functions/classes is used. For readability each import should get its own line. --- scripts/kvm/kvm_stat | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 7e5d256..3fadbfb 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -12,8 +12,16 @@ # the COPYING file in the top-level directory. import curses -import sys, os, time, optparse, ctypes -from ctypes import * +import sys +import os +import time +import optparse +import ctypes +import fcntl +import resource +import struct +import re +from collections import defaultdict class DebugfsProvider(object): def __init__(self): @@ -285,12 +293,10 @@ filters['kvm_userspace_exit'] = ('reason', invert(userspace_exit_reasons)) if exit_reasons: filters['kvm_exit'] = ('exit_reason', invert(exit_reasons)) -import struct, array - libc = ctypes.CDLL('libc.so.6') syscall = libc.syscall get_errno = libc.__errno_location -get_errno.restype = POINTER(c_int) +get_errno.restype = ctypes.POINTER(ctypes.c_int) class perf_event_attr(ctypes.Structure): _fields_ = [('type', ctypes.c_uint32), @@ -334,8 +340,6 @@ PERF_FORMAT_TOTAL_TIME_RUNNING = 1 << 1 PERF_FORMAT_ID = 1 << 2 PERF_FORMAT_GROUP = 1 << 3 -import re - sys_tracing = '/sys/kernel/debug/tracing' class Group(object): @@ -378,17 +382,13 @@ class Event(object): 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) self.fd = fd def enable(self): - import fcntl fcntl.ioctl(self.fd, ioctl_numbers['ENABLE'], 0) def disable(self): - import fcntl fcntl.ioctl(self.fd, ioctl_numbers['DISABLE'], 0) def reset(self): - import fcntl fcntl.ioctl(self.fd, ioctl_numbers['RESET'], 0) class TracepointProvider(object): @@ -426,7 +426,6 @@ class TracepointProvider(object): def _setup(self, _fields): self._fields = _fields cpus = self._online_cpus() - import resource nfiles = len(cpus) * 1000 resource.setrlimit(resource.RLIMIT_NOFILE, (nfiles, nfiles)) events = [] @@ -454,7 +453,6 @@ class TracepointProvider(object): else: event.disable() def read(self): - from collections import defaultdict ret = defaultdict(int) for group in self.group_leaders: for name, val in group.read().iteritems(): @@ -468,7 +466,6 @@ class Stats: self._update() def _update(self): def wanted(key): - import re if not self.fields_filter: return True return re.match(self.fields_filter, key) is not None @@ -640,7 +637,6 @@ stats = Stats(providers, fields = options.fields) if options.log: log(stats) elif not options.once: - import curses.wrapper curses.wrapper(tui, stats) else: batch(stats)