Add some tracing for release fences

* Fix FenceMonitor to cleanly teardown
* App-side tracing for BBQ release callbacks
* Trace future compleition in TxnCallbackInvoker

Bug: 360932099
Bug: 357762453
Flag: EXEMPT debugging
Test: builds
Test: perfetto
Change-Id: I188c04da1e249b672b428837c328568d9e7a1e66
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
index 3c1971f..94998e5 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -31,6 +31,7 @@
 #include <sys/epoll.h>
 #include <sys/eventfd.h>
 
+#include <gui/FenceMonitor.h>
 #include <gui/FrameRateUtils.h>
 #include <gui/GLConsumer.h>
 #include <gui/IProducerListener.h>
@@ -475,6 +476,16 @@
     ATRACE_CALL();
     BQA_LOGV("releaseBufferCallback %s", id.to_string().c_str());
 
+    if (CC_UNLIKELY(atrace_is_tag_enabled(ATRACE_TAG_GRAPHICS))) {
+        if (!mFenceMonitor) {
+            std::string monitorName = "release :";
+            monitorName.append(mName.c_str());
+            mFenceMonitor.emplace(monitorName.c_str());
+        }
+
+        mFenceMonitor->queueFence(releaseFence);
+    }
+
     // Calculate how many buffers we need to hold before we release them back
     // to the buffer queue. This will prevent higher latency when we are running
     // on a lower refresh rate than the max supported. We only do that for EGL