gralloc1: Add additional tracing

CRs-Fixed: 2045975
Change-Id: I61d6cd91ced127b4f3068a3f920ecefe7824931b
diff --git a/libgralloc1/gr_device_impl.cpp b/libgralloc1/gr_device_impl.cpp
index 98ce595..b955e19 100644
--- a/libgralloc1/gr_device_impl.cpp
+++ b/libgralloc1/gr_device_impl.cpp
@@ -27,7 +27,10 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
 #include <cutils/log.h>
+#include <utils/Trace.h>
+#include <cutils/trace.h>
 #include <sync/sync.h>
 #include <algorithm>
 #include <sstream>
@@ -420,6 +423,7 @@
                                          gralloc1_consumer_usage_t cons_usage,
                                          const gralloc1_rect_t *region, void **out_data,
                                          int32_t acquire_fence) {
+  ATRACE_CALL();
   gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
   if (status != GRALLOC1_ERROR_NONE) {
     CloseFdIfValid(acquire_fence);
@@ -427,7 +431,9 @@
   }
 
   if (acquire_fence > 0) {
+    ATRACE_BEGIN("fence wait");
     int error = sync_wait(acquire_fence, 1000);
+    ATRACE_END();
     CloseFdIfValid(acquire_fence);
     if (error < 0) {
       ALOGE("%s: sync_wait timedout! error = %s", __FUNCTION__, strerror(errno));
diff --git a/libgralloc1/gr_ion_alloc.cpp b/libgralloc1/gr_ion_alloc.cpp
index 72fe995..c8300ab 100644
--- a/libgralloc1/gr_ion_alloc.cpp
+++ b/libgralloc1/gr_ion_alloc.cpp
@@ -36,6 +36,8 @@
 #include <cutils/log.h>
 #include <errno.h>
 #include <utils/Trace.h>
+#include <cutils/trace.h>
+#include <string>
 
 #include "gralloc_priv.h"
 #include "gr_utils.h"
@@ -77,21 +79,29 @@
   ion_alloc_data.heap_id_mask = data->heap_id;
   ion_alloc_data.flags = data->flags;
   ion_alloc_data.flags |= data->uncached ? 0 : ION_FLAG_CACHED;
+  std::string tag_name{};
+  if (ATRACE_ENABLED()) {
+    tag_name = "ION_IOC_ALLOC size: " + std::to_string(data->size);
+  }
 
+  ATRACE_BEGIN(tag_name.c_str());
   if (ioctl(ion_dev_fd_, INT(ION_IOC_ALLOC), &ion_alloc_data)) {
     err = -errno;
     ALOGE("ION_IOC_ALLOC failed with error - %s", strerror(errno));
     return err;
   }
+  ATRACE_END();
 
   fd_data.handle = ion_alloc_data.handle;
   handle_data.handle = ion_alloc_data.handle;
+  ATRACE_BEGIN("ION_IOC_MAP");
   if (ioctl(ion_dev_fd_, INT(ION_IOC_MAP), &fd_data)) {
     err = -errno;
     ALOGE("%s: ION_IOC_MAP failed with error - %s", __FUNCTION__, strerror(errno));
     ioctl(ion_dev_fd_, INT(ION_IOC_FREE), &handle_data);
     return err;
   }
+  ATRACE_END();
 
   data->fd = fd_data.fd;
   data->ion_handle = handle_data.handle;