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




commit adfeaf39bbed3d834af0988677de706a61ddb2cf
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                      | 19 +++++++++++++++++--
 gnomemusic/grilowrappers/grltrackerwrapper.py |  2 +-
 gnomemusic/songart.py                         |  2 +-
 gnomemusic/widgets/artstack.py                |  2 +-
 6 files changed, 22 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 53357274a..1941a9a7b 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,16 @@ 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
         """
         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 +75,17 @@ class AsyncQueue(GObject.GObject):
         else:
             return
 
+        tick = time.time()
+
         def on_async_finished(*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 tasks of {len(self._async_pool) + a}")
+
             async_obj = args[0]
             async_obj.disconnect(result_id)
             self._async_active_pool.pop(id(async_obj))
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 677b9be63..6d9203981 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]