summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanosch Frank2016-01-11 16:17:32 +0100
committerPaolo Bonzini2016-01-26 15:58:11 +0100
commit6590045e5dd2fb0b1d7cdc047ae0c52fd4bb5276 (patch)
treea93ee6e6b0d735c1c8bab1d0fdb7f31cc861e77c
parentscripts/kvm/kvm_stat: Cleanup of multiple imports (diff)
downloadqemu-6590045e5dd2fb0b1d7cdc047ae0c52fd4bb5276.tar.gz
qemu-6590045e5dd2fb0b1d7cdc047ae0c52fd4bb5276.tar.xz
qemu-6590045e5dd2fb0b1d7cdc047ae0c52fd4bb5276.zip
scripts/kvm/kvm_stat: Replaced os.listdir with os.walk
Os.walk gives back lists of directories and files, no need to filter directories from the list that listdir gives back. To make it better understandable a wrapper with docstring was introduced. Signed-off-by: Janosch Frank <frankja@linux.vnet.ibm.com> Message-Id: <1452525484-32309-3-git-send-email-frankja@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rwxr-xr-xscripts/kvm/kvm_stat15
1 files changed, 11 insertions, 4 deletions
diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 3fadbfba93..63232767f3 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -26,7 +26,7 @@ from collections import defaultdict
class DebugfsProvider(object):
def __init__(self):
self.base = '/sys/kernel/debug/kvm'
- self._fields = os.listdir(self.base)
+ self._fields = walkdir(self.base)[2]
def fields(self):
return self._fields
def select(self, fields):
@@ -285,6 +285,15 @@ def detect_platform():
detect_platform()
+
+def walkdir(path):
+ """Returns os.walk() data for specified directory.
+
+ As it is only a wrapper it returns the same 3-tuple of (dirpath,
+ dirnames, filenames).
+ """
+ return next(os.walk(path))
+
def invert(d):
return dict((x[1], x[0]) for x in d.iteritems())
@@ -394,9 +403,7 @@ class Event(object):
class TracepointProvider(object):
def __init__(self):
path = os.path.join(sys_tracing, 'events', 'kvm')
- fields = [f
- for f in os.listdir(path)
- if os.path.isdir(os.path.join(path, f))]
+ fields = walkdir(path)[1]
extra = []
for f in fields:
if f in filters: