diff mbox

[PULL,08/49] scripts/kvm/kvm_stat: Replaced os.listdir with os.walk

Message ID 1453816041-36362-9-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paolo Bonzini Jan. 26, 2016, 1:46 p.m. UTC
From: Janosch Frank <frankja@linux.vnet.ibm.com>

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>
---
 scripts/kvm/kvm_stat | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index 3fadbfb..6323276 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: