[gnome-music/wip/mschraal/file-exists-async: 28/30] asyncqueue: Add debug logging




commit e3944d6bb136cbac836c8c642eed4437c5581b0e
Author: Marinus Schraal <mschraal gnome org>
Date:   Tue Aug 17 10:10:29 2021 +0200

    asyncqueue: Add debug logging
    
    Report number of active/total tasks and time taken for task completion.

 gnomemusic/albumart.py                        |  2 +-
 gnomemusic/artistart.py                       |  2 +-
 gnomemusic/asyncqueue.py                      | 22 ++++++++++++++++++++--
 gnomemusic/grilowrappers/grltrackerwrapper.py |  2 +-
 gnomemusic/songart.py                         |  2 +-
 gnomemusic/widgets/artstack.py                |  2 +-
 6 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/gnomemusic/albumart.py b/gnomemusic/albumart.py
index 1ca207374..7a8f6a12a 100644
--- a/gnomemusic/albumart.py
+++ b/gnomemusic/albumart.py
@@ -35,7 +35,7 @@ class AlbumArt(GObject.GObject):
     """AlbumArt retrieval object
     """
 
-    _async_queue = AsyncQueue()
+    _async_queue = AsyncQueue("AlbumArt")
 
     def __init__(self, application, corealbum):
         """Initialize AlbumArt
diff --git a/gnomemusic/artistart.py b/gnomemusic/artistart.py
index cc01e4c4a..04d913c76 100644
--- a/gnomemusic/artistart.py
+++ b/gnomemusic/artistart.py
@@ -34,7 +34,7 @@ class ArtistArt(GObject.GObject):
     """Artist art retrieval object
     """
 
-    _async_queue = AsyncQueue()
+    _async_queue = AsyncQueue("ArtistArt")
 
     def __init__(self, application, coreartist):
         """Initialize.
diff --git a/gnomemusic/asyncqueue.py b/gnomemusic/asyncqueue.py
index 35c756319..125b2145f 100644
--- a/gnomemusic/asyncqueue.py
+++ b/gnomemusic/asyncqueue.py
@@ -22,10 +22,13 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
-from typing import Any, Dict, Tuple
+from typing import Any, Dict, Optional, Tuple
+import time
 
 from gi.repository import GObject
 
+from gnomemusic.musiclogger import MusicLogger
+
 
 class AsyncQueue(GObject.GObject):
     """Queue async classes
@@ -43,14 +46,19 @@ class AsyncQueue(GObject.GObject):
     may have an arbitrary number of arguments following.
     """
 
-    def __init__(self) -> None:
+    def __init__(self, queue_name: Optional[str] = None) -> None:
         """Initialize AsyncQueue
+
+        :param str queue_name: The user facing name of this queue or
+            None for the generic class identifier
         """
         super().__init__()
 
         self._async_pool: Dict[int, Tuple] = {}
         self._async_active_pool: Dict[int, Tuple] = {}
+        self._log = MusicLogger()
         self._max_async = 4
+        self._queue_name = queue_name if queue_name else self
 
     def queue(self, *args: Any) -> None:
         """Queue an async call
@@ -70,7 +78,17 @@ class AsyncQueue(GObject.GObject):
         else:
             return
 
+        tick = time.time()
+
         def on_async_finished(obj, *signal_args):
+            t = (time.time() - tick) * 1000
+            self._log.debug(f"{self._queue_name}: {t:.2f} ms task")
+
+            a = len(self._async_active_pool)
+            self._log.debug(
+                f"{self._queue_name}: "
+                f"{a} active task(s) of {len(self._async_pool) + a}")
+
             obj.disconnect(result_id)
             self._async_active_pool.pop(id(obj))
 
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index c78a7cd04..c0ccaceb1 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -104,7 +104,7 @@ class GrlTrackerWrapper(GObject.GObject):
         """
         super().__init__()
 
-        self._async_queue = AsyncQueue()
+        self._async_queue = AsyncQueue("GrlTrackerWrapper")
         self._application: Application = application
         cm: CoreModel = application.props.coremodel
         self._log: MusicLogger = application.props.log
diff --git a/gnomemusic/songart.py b/gnomemusic/songart.py
index cbd5bc164..94bf46c90 100644
--- a/gnomemusic/songart.py
+++ b/gnomemusic/songart.py
@@ -35,7 +35,7 @@ class SongArt(GObject.GObject):
     """SongArt retrieval object
     """
 
-    _async_queue = AsyncQueue()
+    _async_queue = AsyncQueue("SongArt")
 
     def __init__(self, application, coresong):
         """Initialize SongArt
diff --git a/gnomemusic/widgets/artstack.py b/gnomemusic/widgets/artstack.py
index bba487901..0c0b9d379 100644
--- a/gnomemusic/widgets/artstack.py
+++ b/gnomemusic/widgets/artstack.py
@@ -40,7 +40,7 @@ class ArtStack(Gtk.Stack):
 
     __gtype_name__ = "ArtStack"
 
-    _async_queue = AsyncQueue()
+    _async_queue = AsyncQueue("ArtStack")
 
     def __init__(self, size: ArtSize = ArtSize.MEDIUM) -> None:
         """Initialize the ArtStack


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]