From 2d13b5c9431eba134993f7e9bc74d79c482d9604 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 27 Jun 2017 15:22:38 +0200 Subject: [PATCH] proc: Enhance bcc_mapping_is_file_backed Cleanup the `strncmp` code and add a few more ignored map names --- src/cc/bcc_proc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cc/bcc_proc.c b/src/cc/bcc_proc.c index b6c613226dd0..4fb73b438bdc 100644 --- a/src/cc/bcc_proc.c +++ b/src/cc/bcc_proc.c @@ -61,14 +61,18 @@ char *bcc_procutils_which(const char *binpath) { return 0; } +#define STARTS_WITH(mapname, prefix) (!strncmp(mapname, prefix, sizeof(prefix)-1)) + int bcc_mapping_is_file_backed(const char *mapname) { - return mapname[0] && - strncmp(mapname, "//anon", sizeof("//anon") - 1) && - strncmp(mapname, "/dev/zero", sizeof("/dev/zero") - 1) && - strncmp(mapname, "/anon_hugepage", sizeof("/anon_hugepage") - 1) && - strncmp(mapname, "[stack", sizeof("[stack") - 1) && - strncmp(mapname, "/SYSV", sizeof("/SYSV") - 1) && - strncmp(mapname, "[heap]", sizeof("[heap]") - 1); + return mapname[0] && !( + STARTS_WITH(mapname, "//anon") || + STARTS_WITH(mapname, "/dev/zero") || + STARTS_WITH(mapname, "/anon_hugepage") || + STARTS_WITH(mapname, "[stack") || + STARTS_WITH(mapname, "/SYSV") || + STARTS_WITH(mapname, "[heap]") || + STARTS_WITH(mapname, "[vsyscall]") || + STARTS_WITH(mapname, "[vdso]")); } int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback,