gralloc1: Add additional debug logging

CRs-Fixed: 2018334
Change-Id: I4ef2613ec69ca98818ed9c4f8d2408c4df2d039e
diff --git a/libgralloc1/gr_buf_mgr.cpp b/libgralloc1/gr_buf_mgr.cpp
index 3431c42..e2cfdd4 100644
--- a/libgralloc1/gr_buf_mgr.cpp
+++ b/libgralloc1/gr_buf_mgr.cpp
@@ -17,6 +17,7 @@
  * limitations under the License.
  */
 
+#define DEBUG 0
 #include <iomanip>
 #include <utility>
 #include <vector>
@@ -225,6 +226,7 @@
 
 gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) {
   std::lock_guard<std::mutex> lock(locker_);
+  ALOGD_IF(DEBUG, "Retain buffer handle:%p id: %" PRIu64, hnd, hnd->id);
 
   // find if this handle is already in map
   auto it = handles_map_.find(hnd);
@@ -246,6 +248,7 @@
 
 gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) {
   std::lock_guard<std::mutex> lock(locker_);
+  ALOGD_IF(DEBUG, "Release buffer handle:%p id: %" PRIu64, hnd, hnd->id);
   // find if this handle is already in map
   auto it = handles_map_.find(hnd);
   if (it == handles_map_.end()) {
@@ -458,6 +461,10 @@
   *handle = hnd;
   auto buffer = std::make_shared<Buffer>(hnd, data.ion_handle, e_data.ion_handle);
   handles_map_.emplace(std::make_pair(hnd, buffer));
+  ALOGD_IF(DEBUG, "Allocated buffer handle: %p id: %" PRIu64, hnd, hnd->id);
+  if (DEBUG) {
+    private_handle_t::Dump(hnd);
+  }
   return err;
 }
 
diff --git a/libgralloc1/gr_priv_handle.h b/libgralloc1/gr_priv_handle.h
index 9a7e7b6..27d405b 100644
--- a/libgralloc1/gr_priv_handle.h
+++ b/libgralloc1/gr_priv_handle.h
@@ -23,6 +23,7 @@
 #include <cutils/log.h>
 #include <hardware/gralloc1.h>
 #include <hardware/gralloc.h>
+#include <cinttypes>
 
 #define GRALLOC1_FUNCTION_PERFORM 0x00001000
 
@@ -160,6 +161,14 @@
     return 0;
   }
 
+  static void Dump(const private_handle_t *hnd) {
+    ALOGD("handle id:%" PRIu64 " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x"
+          "prod_usage:0x%" PRIx64" cons_usage:0x%" PRIx64 "format:0x%x",
+          hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
+          hnd->fd, hnd->fd_metadata, hnd->flags, hnd->producer_usage, hnd->consumer_usage,
+          hnd->format);
+  }
+
   int GetUnalignedWidth() const { return unaligned_width; }
 
   int GetUnalignedHeight() const { return unaligned_height; }