OSDN Git Service

gralloc: Adds a new inline method map_usage_to_memtrack.
authorRuchi Kandoi <kandoiruchi@google.com>
Wed, 30 Mar 2016 01:23:39 +0000 (18:23 -0700)
committerRuchi Kandoi <kandoiruchi@google.com>
Tue, 10 May 2016 16:57:53 +0000 (16:57 +0000)
map_usage_to_memtrack takes in the gralloc usage flag and returns a
const char pointer containing the memtrack tag.

This function should be used to find the appropriate memtrack tag that
needs to be used after allocating buffers. This will help in-kernel
memtrack module to classify memory into pre-defined buckets.

Bug: 27525688
Change-Id: Ieee868f9b90ab170c16ba80aceedcb3b2e3762df
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
include/hardware/gralloc.h

index ef86f90..779915c 100644 (file)
@@ -379,6 +379,38 @@ static inline int gralloc_close(struct alloc_device_t* device) {
     return device->common.close(&device->common);
 }
 
+/**
+ * map_usage_to_memtrack should be called after allocating a gralloc buffer.
+ *
+ * @param usage - it is the flag used when alloc function is called.
+ *
+ * This function maps the gralloc usage flags to appropriate memtrack bucket.
+ * GrallocHAL implementers and users should make an additional ION_IOCTL_TAG
+ * call using the memtrack tag returned by this function. This will help the
+ * in-kernel memtack to categorize the memory allocated by different processes
+ * according to their usage.
+ *
+ */
+static inline const char* map_usage_to_memtrack(uint32_t usage) {
+    usage &= GRALLOC_USAGE_ALLOC_MASK;
+
+    if ((usage & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) {
+        return "camera";
+    } else if ((usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) != 0 ||
+            (usage & GRALLOC_USAGE_EXTERNAL_DISP) != 0) {
+        return "video";
+    } else if ((usage & GRALLOC_USAGE_HW_RENDER) != 0 ||
+            (usage & GRALLOC_USAGE_HW_TEXTURE) != 0) {
+        return "gl";
+    } else if ((usage & GRALLOC_USAGE_HW_CAMERA_READ) != 0) {
+        return "camera";
+    } else if ((usage & GRALLOC_USAGE_SW_READ_MASK) != 0 ||
+            (usage & GRALLOC_USAGE_SW_WRITE_MASK) != 0) {
+        return "cpu";
+    }
+    return "graphics";
+}
+
 __END_DECLS
 
 #endif  // ANDROID_GRALLOC_INTERFACE_H