public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: Correctly identify anon_hugepage when generating map (v2)
@ 2015-11-26 11:42 Yannick Brosseau
  2015-11-26 17:12 ` Arnaldo Carvalho de Melo
  2015-11-27  7:44 ` [tip:perf/core] perf tools: " tip-bot for Yannick Brosseau
  0 siblings, 2 replies; 3+ messages in thread
From: Yannick Brosseau @ 2015-11-26 11:42 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 afc6b56..97e11a7 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")-1) ||
+	       !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage")-1);
 }
 
 static inline int is_no_dso_memory(const char *filename)
-- 
2.6.2


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

* Re: [PATCH] perf: Correctly identify anon_hugepage when generating map (v2)
  2015-11-26 11:42 [PATCH] perf: Correctly identify anon_hugepage when generating map (v2) Yannick Brosseau
@ 2015-11-26 17:12 ` Arnaldo Carvalho de Melo
  2015-11-27  7:44 ` [tip:perf/core] perf tools: " tip-bot for Yannick Brosseau
  1 sibling, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-11-26 17:12 UTC (permalink / raw)
  To: Yannick Brosseau; +Cc: linux-kernel, kernel-team, zhu.wen-jie, ak

Em Thu, Nov 26, 2015 at 03:42:32AM -0800, 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.

Thanks, applied, tested with:

[acme@zoo c]$ cat scanf_proc_smaps.c 
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>

typedef unsigned int u32;
typedef unsigned long long u64;

struct mmap2_event {
	u32 pid, tid;
	u64 start;
	u64 len;
	u64 pgoff;
	u32 maj;
	u32 min;
	u64 ino;
	u64 ino_generation;
	u32 prot;
	u32 flags;
	char filename[PATH_MAX];
};

union perf_event {
	struct mmap2_event mmap2;
};

static inline int is_anon_memory(const char *filename)
{
	return !strcmp(filename, "//anon") ||
	       !strncmp(filename, "/dev/zero", sizeof("/dev/zero") - 1) ||
	       !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage") - 1);
}

int main(void)
{
	union perf_event event;
	unsigned int ino;
	char prot[5];
	char bf[] = "7f939395e000-7f939395f000 rw-s 00000000 00:05 98715                      /dev/zero (deleted)";
	int n = sscanf(bf, "%"PRIx64"-%"PRIx64" %s %"PRIx64" %x:%x %u %s\n",
                       &event.mmap2.start, &event.mmap2.len, prot,
                       &event.mmap2.pgoff, &event.mmap2.maj,
                       &event.mmap2.min,
                       &ino, event.mmap2.filename);

	printf("event.filename=\"%s\"\n", event.mmap2.filename);
	if (is_anon_memory(event.mmap2.filename))
		printf("This is anonymous memory\n");
	return 0;
}
[acme@zoo c]$ ./scanf_proc_smaps 
event.filename="/dev/zero"
This is anonymous memory
[acme@zoo c]$
 
> 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 afc6b56..97e11a7 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")-1) ||
> +	       !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage")-1);
>  }
>  
>  static inline int is_no_dso_memory(const char *filename)
> -- 
> 2.6.2

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

* [tip:perf/core] perf tools: Correctly identify anon_hugepage when generating map (v2)
  2015-11-26 11:42 [PATCH] perf: Correctly identify anon_hugepage when generating map (v2) Yannick Brosseau
  2015-11-26 17:12 ` Arnaldo Carvalho de Melo
@ 2015-11-27  7:44 ` tip-bot for Yannick Brosseau
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Yannick Brosseau @ 2015-11-27  7:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, ak, mingo, hpa, acme, scientist, linux-kernel, zhu.wen-jie

Commit-ID:  b2be5451f660e0ee230969cc24121d9e210a91de
Gitweb:     http://git.kernel.org/tip/b2be5451f660e0ee230969cc24121d9e210a91de
Author:     Yannick Brosseau <scientist@fb.com>
AuthorDate: Thu, 26 Nov 2015 03:42:32 -0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 26 Nov 2015 14:08:17 -0300

perf tools: Correctly identify anon_hugepage when generating map (v2)

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 receives the string "/anon_hugepage" and does
not detect it.  We change is_anon_memory() to only compare the first
part of the string, effectively ignoring if " (deleted)" is there.

Signed-off-by: Yannick Brosseau <scientist@fb.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Joshua Zhu <zhu.wen-jie@hp.com>
Cc: kernel-team@fb.com
Link: http://lkml.kernel.org/r/1448538152-2898-1-git-send-email-scientist@fb.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.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 afc6b56..93d9f1c 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") - 1) ||
+	       !strncmp(filename, "/anon_hugepage", sizeof("/anon_hugepage") - 1);
 }
 
 static inline int is_no_dso_memory(const char *filename)

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

end of thread, other threads:[~2015-11-27  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 11:42 [PATCH] perf: Correctly identify anon_hugepage when generating map (v2) Yannick Brosseau
2015-11-26 17:12 ` Arnaldo Carvalho de Melo
2015-11-27  7:44 ` [tip:perf/core] perf tools: " tip-bot for Yannick Brosseau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox