diff options
author | Santhosh Punugu <spunug@codeaurora.org> | 2016-10-28 19:03:03 +0530 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-11-23 23:41:08 -0800 |
commit | 68155923fe216fc4d46442ff73f34c0b31e153b9 (patch) | |
tree | bdd72049610b6c49b99b2affd83b30f10e0e13b9 /libmemtrack | |
parent | 4b9f87fb13a257a4ddf8eb17c86a1f8b83465290 (diff) | |
download | display-68155923fe216fc4d46442ff73f34c0b31e153b9.tar.gz |
libmemtrack: fix ion memory tracking
Use 2 new columns from the kgsl debugfs mem file:
egl_surface_count: # of buffer attachments with usage=egl_surface
egl_image_count: # of buffer attachments with usage=egl_image
If an ion buffer is mapped with usage=egl_surface, the entire size will
be counted towards the egl_surface. The assumption is that the buffer
will be freed if the producer process is killed.
To handle buffers such as the wallpaper and texture atlas which have
no producer and are potentially mapped multiple times, assign each
process where usage=egl_image a size of "size / egl_image_count". This
ensures that the total memory usage is correct, while still assigning
some memory to each process which maps the buffer.
The above replaces the attempts to avoid double counting buffers using
the "is_surfaceflinger" check.
CRs-Fixed: 1087134
Change-Id: I4e001f4a613520585be8799d7269aafe6140d7a6
Signed-off-by: Santhosh Punugu <spunug@codeaurora.org>
Diffstat (limited to 'libmemtrack')
-rw-r--r-- | libmemtrack/kgsl.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/libmemtrack/kgsl.c b/libmemtrack/kgsl.c index 11c7e8a2..9ec69f08 100644 --- a/libmemtrack/kgsl.c +++ b/libmemtrack/kgsl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2013, 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,6 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, FILE *fp; char line[1024]; char tmp[128]; - bool is_surfaceflinger = false; size_t accounted_size = 0; size_t unaccounted_size = 0; @@ -59,16 +58,6 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, return 0; } - snprintf(tmp, sizeof(tmp), "/proc/%d/cmdline", pid); - fp = fopen(tmp, "r"); - if (fp != NULL) { - if (fgets(line, sizeof(line), fp)) { - if (strcmp(line, "/system/bin/surfaceflinger") == 0) - is_surfaceflinger = true; - } - fclose(fp); - } - memcpy(records, record_templates, sizeof(struct memtrack_record) * allocated_records); @@ -87,19 +76,20 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, char line_type[7]; char flags[9]; char line_usage[19]; - int ret; + int ret, egl_surface_count = 0, egl_image_count = 0; if (fgets(line, sizeof(line), fp) == NULL) { break; } /* Format: - * gpuaddr useraddr size id flags type usage sglen mapsize - * 545ba000 545ba000 4096 1 -----pY gpumem arraybuffer 1 4096 + * gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg + * 545ba000 545ba000 4096 1 -----pY gpumem arraybuffer 1 4096 0 0 */ - ret = sscanf(line, "%*x %*x %lu %*d %8s %6s %18s %*d %lu\n", - &size, flags, line_type, line_usage, &mapsize); - if (ret != 5) { + ret = sscanf(line, "%*x %*x %lu %*d %8s %6s %18s %*d %lu %6d %6d\n", + &size, flags, line_type, line_usage, &mapsize, + &egl_surface_count, &egl_image_count); + if (ret != 7) { continue; } @@ -112,9 +102,10 @@ int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, unaccounted_size += size; } else if (type == MEMTRACK_TYPE_GRAPHICS && strcmp(line_type, "ion") == 0) { - if ( !(is_surfaceflinger == false && strcmp(line_usage, "egl_surface") == 0)) { + if (strcmp(line_usage, "egl_surface") == 0) unaccounted_size += size; - } + else if (egl_surface_count == 0) + unaccounted_size += size / (egl_image_count ? egl_image_count : 1); } } |