[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/49] scripts/kvm/kvm_stat: Cleanup of multiple impo
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 07/49] scripts/kvm/kvm_stat: Cleanup of multiple imports |
Date: |
Tue, 26 Jan 2016 14:46:39 +0100 |
From: Janosch Frank <address@hidden>
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.
Signed-off-by: Janosch Frank <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
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)
--
1.8.3.1
- [Qemu-devel] [PULL 00/49] chardev, NBD, cpus, scripts/ changes for 2015-01-26, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 01/49] char: remove fixed length filename allocation, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 04/49] char: introduce support for TLS encrypted TCP chardev backend, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 02/49] char: convert from GIOChannel to QIOChannel, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 03/49] char: don't assume telnet initialization will not block, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 06/49] qemu-char: avoid leak in qemu_chr_open_pp_fd, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 08/49] scripts/kvm/kvm_stat: Replaced os.listdir with os.walk, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 10/49] scripts/kvm/kvm_stat: Removed unneeded PERF constants, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 05/49] docs: Style the command and its options in the synopsis, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 07/49] scripts/kvm/kvm_stat: Cleanup of multiple imports,
Paolo Bonzini <=
- [Qemu-devel] [PULL 09/49] scripts/kvm/kvm_stat: Make constants uppercase, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 11/49] scripts/kvm/kvm_stat: Mark globals in functions, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 13/49] scripts/kvm/kvm_stat: Cleanup of path variables, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 12/49] scripts/kvm/kvm_stat: Invert dictionaries, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 15/49] scripts/kvm/kvm_stat: Introduce main function, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 17/49] scripts/kvm/kvm_stat: Rename variables that redefine globals, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 18/49] scripts/kvm/kvm_stat: Moved DebugfsProvider, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 14/49] scripts/kvm/kvm_stat: Improve debugfs access checking, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 16/49] scripts/kvm/kvm_stat: Fix spaces around keyword assignments, Paolo Bonzini, 2016/01/26
- [Qemu-devel] [PULL 20/49] scripts/kvm/kvm_stat: Set sensible no. files rlimit, Paolo Bonzini, 2016/01/26