diff options
author | Christopher Ferris <cferris@google.com> | 2015-03-26 19:18:36 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2015-03-31 10:51:44 -0700 |
commit | 2c43cff01d1271be451671567955158629b23670 (patch) | |
tree | b08d199b9cc4d0b665d7dc844cadedf883d0590c /libbacktrace/GetPss.cpp | |
parent | e29744d94df787fa83307572d90a954b1592f69b (diff) | |
download | system_core-2c43cff01d1271be451671567955158629b23670.zip system_core-2c43cff01d1271be451671567955158629b23670.tar.gz system_core-2c43cff01d1271be451671567955158629b23670.tar.bz2 |
Refactor the code.
The object hierarchy was confusing and convoluted. This removes
a lot of unnecessary code, and consolidates the BacktraceCurrent
and BacktraceThread code into BacktraceCurrent.
Change-Id: I01c8407d493712a48169df49dd3ff46db4a7c3ae
Diffstat (limited to 'libbacktrace/GetPss.cpp')
-rw-r--r-- | libbacktrace/GetPss.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/libbacktrace/GetPss.cpp b/libbacktrace/GetPss.cpp index 442383b..09a721d 100644 --- a/libbacktrace/GetPss.cpp +++ b/libbacktrace/GetPss.cpp @@ -14,11 +14,10 @@ * limitations under the License. */ -#include <assert.h> #include <inttypes.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> @@ -46,13 +45,22 @@ static bool ReadData(int fd, unsigned long place, uint64_t *data) { size_t GetPssBytes() { FILE* maps = fopen("/proc/self/maps", "r"); - assert(maps != NULL); + if (maps == nullptr) { + return 0; + } int pagecount_fd = open("/proc/kpagecount", O_RDONLY); - assert(pagecount_fd >= 0); + if (pagecount_fd == -1) { + fclose(maps); + return 0; + } int pagemap_fd = open("/proc/self/pagemap", O_RDONLY); - assert(pagemap_fd >= 0); + if (pagemap_fd == -1) { + fclose(maps); + close(pagecount_fd); + return 0; + } char line[4096]; size_t total_pss = 0; |