make sizes in test_helpers readable
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 5 Feb 2016 10:29:19 +0000 (11:29 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 5 Feb 2016 10:29:19 +0000 (11:29 +0100)
src/test_helpers.py

index f1bbcf2..3772375 100644 (file)
@@ -21,6 +21,9 @@
 Creation motivated by fear of filling disc space during long-running stress
 tests
 
+.. todo:: Find out why NOT_REAL_FILESYSTEMS generate warnings so quickly even
+          if they are still empty
+
 .. codeauthor:: Intra2net
 """
 
@@ -46,7 +49,7 @@ except ImportError:
 from buffers import LogarithmicBuffer
 from file_helpers import get_filesystem_fill_states, FilesystemFillState, \
                          get_mount_info, get_fill_from_statvfs, \
-                         NOT_REAL_FILESYSTEMS
+                         NOT_REAL_FILESYSTEMS, size_str
 from iter_helpers import pairwise
 
 
@@ -115,6 +118,8 @@ class DiscFillChecker:
         """
         if fs_state.name in NOT_REAL_FILESYSTEMS:
             return []
+        if fs_state.size == 0:
+            return []
 
         buf = None
         try:
@@ -393,35 +398,44 @@ def watch_disc_fill(interval=0.1, paths=None):
 
     # start state
     print('{0}: start states are:'.format(dt.now()))
+    first_fills = dict()
     max_vals = dict()
     for state in get_states():
-        print('{0}, {1}B used'.format(state, state.used))
+        print('{0}, {1} used'.format(state, size_str(state.used)))
         max_vals[state.mount_point] = state.used
+        first_fills[state.mount_point] = state.used
 
     try:
-        # infinite loop
+        # loop until user presses Ctrl-C
+        print('checking every {0:.1f}s, press Ctrl-C to stop...'
+              .format(interval))
         while True:
             time.sleep(interval)
             try:
                 for state in get_states():
                     if state.used > max_vals[state.mount_point]:
-                        print('{0}: new max {1}B for {2}'
+                        print('{0}: new max {1:,d}B for {2}'
                               .format(dt.now(), state.used, state))
                         max_vals[state.mount_point] = state.used
             except KeyError:
                 # a new file system was added
                 for state in get_states():
                     if state.mount_point not in max_vals:
-                        print('{0}: new filesystem {1}, {2}B used'
+                        print('{0}: new filesystem {1}, {2:,d}B used'
                               .format(dt.now(), state, state.used))
                         max_vals[state.mount_point] = state.used
+                        first_fills[state.mount_point] = state.used
     except KeyboardInterrupt:
         # end function
         print(' --> caught KeyboardInterrupt')
         print('{0}: end states and maxima:'.format(dt.now()))
         for state in get_states():
-            print('{0}, end fill is {1}B, max fill was {2}B'
-                  .format(state, state.used, max_vals[state.mount_point]))
+            firstf = first_fills[state.mount_point]
+            maxf = max_vals[state.mount_point]
+            print('{0}, start/max/end fill: {1} / {2} ({3}) / {4} ({5})'
+                  .format(state, size_str(firstf), size_str(maxf),
+                          size_str(maxf-firstf, True), size_str(state.used),
+                          size_str(state.used-firstf, True)))
 
 
 def get_perf_counter():