linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf: Correctly identify anon_hugepage when generating map
@ 2015-10-08  0:31 Yannick Brosseau
  2015-10-13 14:54 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: Yannick Brosseau @ 2015-10-08  0:31 UTC (permalink / raw)
  To: acme, linux-kernel, kernel-team; +Cc: zhu.wen-jie, ak, Yannick Brosseau

When parsing /proc/xxx/maps, the sscanf in perf_event__synthesize_mmap_events
truncate the map name at the space in "/anon_hugepage (deleted)".
is_anon_memory then only receive the string "/anon_hugepage" and do not detect it.
We change is_anon_memory to only compare the first part of the string
effectively ignoring if the (deleted) part is there or not.

Signed-off-by: Yannick Brosseau <scientist@fb.com>
---
 tools/perf/util/map.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index b1c475d..9f7face 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -26,8 +26,8 @@ const char *map_type__name[MAP__NR_TYPES] = {
 static inline int is_anon_memory(const char *filename)
 {
 	return !strcmp(filename, "//anon") ||
-	       !strcmp(filename, "/dev/zero (deleted)") ||
-	       !strcmp(filename, "/anon_hugepage (deleted)");
+	       !strncmp(filename, "/dev/zero", sizeof("/dev/zero")) ||
+	       !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage"));
 }
 
 static inline int is_no_dso_memory(const char *filename)
-- 
2.6.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf: Correctly identify anon_hugepage when generating map
  2015-10-08  0:31 [PATCH] perf: Correctly identify anon_hugepage when generating map Yannick Brosseau
@ 2015-10-13 14:54 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-10-13 14:54 UTC (permalink / raw)
  To: Yannick Brosseau; +Cc: linux-kernel, kernel-team, zhu.wen-jie, ak

Em Wed, Oct 07, 2015 at 05:31:46PM -0700, Yannick Brosseau escreveu:
> When parsing /proc/xxx/maps, the sscanf in perf_event__synthesize_mmap_events
> truncate the map name at the space in "/anon_hugepage (deleted)".
> is_anon_memory then only receive the string "/anon_hugepage" and do not detect it.
> We change is_anon_memory to only compare the first part of the string
> effectively ignoring if the (deleted) part is there or not.
> 
> +++ b/tools/perf/util/map.c
> @@ -26,8 +26,8 @@ const char *map_type__name[MAP__NR_TYPES] = {
>  static inline int is_anon_memory(const char *filename)
>  {
>  	return !strcmp(filename, "//anon") ||
> -	       !strcmp(filename, "/dev/zero (deleted)") ||
> -	       !strcmp(filename, "/anon_hugepage (deleted)");
> +	       !strncmp(filename, "/dev/zero", sizeof("/dev/zero")) ||
> +	       !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage"));

Have you tested this?

[acme@zoo ~]$ cat strncmp_sizeof.c
#include <string.h>
#include <stdio.h>

int main(void)
{
#define pattern "/anon_hugepage"
	size_t sz = sizeof(pattern);

	return printf("sizeof=%zd\nstrncmp(sz    )=%d\nstrncmp(sz - 1)=%d\n", sz,
			strncmp("/anon_hugepage (deleted)", pattern, sz),
			strncmp("/anon_hugepage (deleted)", pattern, sz - 1));
}
[acme@zoo ~]$ make strncmp_sizeof
cc     strncmp_sizeof.c   -o strncmp_sizeof
[acme@zoo ~]$ ./strncmp_sizeof
sizeof=15
strncmp(sz    )=32
strncmp(sz - 1)=0
[acme@zoo ~]$

Hint, you're not considering the '\0'.

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-13 14:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-08  0:31 [PATCH] perf: Correctly identify anon_hugepage when generating map Yannick Brosseau
2015-10-13 14:54 ` Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).