seb-m / pyinotify

Monitoring filesystems events with inotify on Linux.
http://github.com/seb-m/pyinotify/wiki
MIT License
2.29k stars 379 forks source link

Provide statistics on how many events were in the queue #190

Open yellowpattern opened 4 years ago

yellowpattern commented 4 years ago

The read_events() method interacts with the inotify kernel interface but does not provide any indication of how much was in the queue. It would be useful if read_events() provided a summary of how much was in the queue, how many events and how big the buffer it created from the queue was.

yellowpattern commented 4 years ago
diff --git a/python2/pyinotify.py b/python2/pyinotify.py
index d2f0816..47e2038 100755
--- a/python2/pyinotify.py
+++ b/python2/pyinotify.py
@@ -1244,6 +1244,7 @@ class Notifier:
             raise NotifierError(msg)
         log.debug('Event queue size: %d', queue_size)
         rsum = 0  # counter
+        events = 0  # counter
         while rsum < queue_size:
             s_size = 16
             # Retrieve wd, mask, cookie and fname_len
@@ -1262,6 +1263,8 @@ class Notifier:
             else:
                 self._eventq.append(rawevent)
             rsum += s_size + fname_len
+            events += 1
+        return [events, rsum, queue_size]

     def process_events(self):
         """
diff --git a/python3/pyinotify.py b/python3/pyinotify.py
index bc24313..fd5ea82 100755
--- a/python3/pyinotify.py
+++ b/python3/pyinotify.py
@@ -1227,6 +1227,7 @@ class Notifier:
             raise NotifierError(msg)
         log.debug('Event queue size: %d', queue_size)
         rsum = 0  # counter
+        events = 0  # counter
         while rsum < queue_size:
             s_size = 16
             # Retrieve wd, mask, cookie and fname_len
@@ -1247,6 +1248,8 @@ class Notifier:
             else:
                 self._eventq.append(rawevent)
             rsum += s_size + fname_len
+            events += 1
+        return [events, rsum, queue_size]

     def process_events(self):
         """

inotify.txt

yellowpattern commented 4 years ago

This also requires a documentation update (ugh!) but adding in returning the array should not impact any existing code - the returned array will just be ignored.