perf tools: Synthesize anon MMAP records on the heap
PATCH 1/1 perf tools: Synthesize anon MMAP records on the heap
Anon records usually do not have the 'execname' entry. However if they are on the heap, the execname shows up as '[heap]'. The fix considers any executable entries in the map that do not have a name or are on the heap as anon records and sets the name to '//anon'.
This fixes JIT profiling for records on the heap.
--- tools/perf/util/event.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/event.c +2 -3
@@ -224,10 +224,9 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,continue ; event->header.misc |=PERF_RECORD_MISC_MMAP_DATA ; - } - -if (!strcmp (execname,"" )) + }if (!strcmp (execname,"" ) || !strcmp (execname,"[heap]" )) {strcpy (execname, anonstr); + } size =strlen (execname) +1 ;memcpy (event->mmap.filename, execname, size);
Signature · 1 line
1.8.1
Hi Gaurav,
Quoted 6 lines · Gaurav Jain
Anon records usually do not have the 'execname' entry. However if they are on the heap, the execname shows up as '[heap]'. The fix considers any executable entries in the map that do not have a name or are on the heap as anon records and sets the name to '//anon'.
This fixes JIT profiling for records on the heap.
Thanks,
Namhyung
Quoted 6 lines · Gaurav Jain
Anon records usually do not have the 'execname' entry. However if they are on the heap, the execname shows up as '[heap]'. The fix considers any executable entries in the map that do not have a name or are on the heap as anon records and sets the name to '//anon'.
This fixes JIT profiling for records on the heap.
I guess I don't understand the need for this fix. It seems breaking out //anon vs. [heap] would be useful. Your patch is saying otherwise. Can give a description of the problem you are trying to solve?
Also style issue below..
Quoted 17 lines
Signed-off-by Gaurav Jain <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Don Zickus <[email protected]>Cc Arun Sharma <[email protected]>--- tools/perf/util/event.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)tools/perf/util/event.c +0
-0
tools/perf/util/event.c static int perf_event__synthesize_mmap_events(struct perf_tool *tool, · line 227
Quoted 7 lines
tools/perf/util/event.c +1
-3@@ -224,10 +224,9 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,continue ; event->header.misc |=PERF_RECORD_MISC_MMAP_DATA ; - } - -if (!strcmp (execname,"" )) + }if (!strcmp (execname,"" ) || !strcmp (execname,"[heap]" )) {
The '} if' part should seperate the 'if' on to its own line (unless you meant an 'else' in there).
Cheers,
Don
Quoted 9 lines · Don Zickus
Quoted 8 lines · Gaurav Jain
Anon records usually do not have the 'execname' entry. However if they are on
the heap, the execname shows up as '[heap]'. The fix considers any executable
entries in the map that do not have a name or are on the heap as anon records
and sets the name to '//anon'.
Quoted 5 lines
Quoted 1 line
This fixes JIT profiling for records on the heap.
I guess I don't understand the need for this fix. It seems breaking out //anon vs. [heap] would be useful. Your patch is saying otherwise. Can give a description of the problem you are trying to solve?
Thank you for looking at the patch.
We generate a perf map file which includes certain JIT¹ed functions that show up as [heap] entries. As a result, I included the executable heap entries as anon pages so that it would be handled in util/map.c:map__new(). The alternative would be to handle heap entries in map__new() directly, however I wasn¹t sure if this would break something as it seems that heap and stack entries are expected to fail all map__find_* functions. Thus I considered executable heap entries as //anon, but perhaps there is a better way.
Quoted 22 lines
Also style issue below..
Quoted 20 lines
Signed-off-by Gaurav Jain <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Don Zickus <[email protected]>Cc Arun Sharma <[email protected]>--- tools/perf/util/event.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)tools/perf/util/event.c +0
-0@@ -224,10 +224,9 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool, continue;
Quoted 8 lines
tools/perf/util/event.c static int perf_event__synthesize_mmap_events(struct perf_tool *tool, · line 227
Quoted 5 lines
tools/perf/util/event.c +1
-3event->header.misc |=PERF_RECORD_MISC_MMAP_DATA ; - } - -if (!strcmp (execname,"" )) + }if (!strcmp (execname,"" ) || !strcmp (execname,"[heap]" )) {The '} if' part should seperate the 'if' on to its own line (unless you meant an 'else' in there).
Bah yes, I intended 'else if'. I apologize for that. Does the fact that I filtered anon entries to only those marked as executable break the existing behavior?
Thanks,
Gaurav
Namhyung Kim
maintainerHi Gaurav,
I'd like to take my ack back - it seems I missed some points.
Quoted 19 lines · Gaurav Jain
Quoted 9 lines · Don Zickus
Quoted 8 lines · Gaurav Jain
Anon records usually do not have the 'execname' entry. However if they are on
the heap, the execname shows up as '[heap]'. The fix considers any executable
entries in the map that do not have a name or are on the heap as anon records
and sets the name to '//anon'.Quoted 5 lines
Quoted 1 line
This fixes JIT profiling for records on the heap.
I guess I don't understand the need for this fix. It seems breaking out //anon vs. [heap] would be useful. Your patch is saying otherwise. Can give a description of the problem you are trying to solve?
Thank you for looking at the patch.
Quoted 8 lines
We generate a perf map file which includes certain JIT¹ed functions that show up as [heap] entries. As a result, I included the executable heap entries as anon pages so that it would be handled in util/map.c:map__new(). The alternative would be to handle heap entries in
map__new()directly, however I wasn¹t sure if this would break something as it seems that heap and stack entries are expected to fail all map__find_* functions. Thus I considered executable heap entries as //anon, but perhaps there is a better way.
Hmm.. so the point is that an executable heap mapping should have /tmp/perf-XXX.map as a file name, right? If so, does something like below work well for you?
Thanks,
Namhyung
tools/perf/util/map.c +2 -2
@@ -69,7 +69,7 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, map->ino = ino; map->ino_generation = ino_gen; -if (anon) { +if (anon || (no_dso && type ==MAP__FUNCTION )) {snprintf (newfilename,sizeof (newfilename),"/tmp/perf-%d.map" , pid); filename = newfilename; }
@@ -93,7 +93,7 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,* functions still return NULL, and we avoid the * unnecessary map__load warning. */ -if (no_dso) +if (no_dso && type !=MAP__FUNCTION )dso__set_loaded (dso, map->type); } }
Hi Namhyung,
Quoted 1 line · Namhyung Kim
I'd like to take my ack back - it seems I missed some points.
No worries, looks like the patch wasn’t well thought out.
Quoted 30 lines · Gaurav Jain
Quoted 19 lines · Don Zickus
Quoted 10 lines · Gaurav Jain
Quoted 8 lines
Anon records usually do not have the 'execname' entry. However if they are on
the heap, the execname shows up as '[heap]'. The fix considers any executable
entries in the map that do not have a name or are on the heap as anon records
and sets the name to '//anon'.Quoted 5 lines
Quoted 1 line
This fixes JIT profiling for records on the heap.
I guess I don't understand the need for this fix. It seems breaking out //anon vs. [heap] would be useful. Your patch is saying otherwise. Can give a description of the problem you are trying to solve?
Thank you for looking at the patch.
Quoted 9 lines
We generate a perf map file which includes certain JIT¹ed functions that show up as [heap] entries. As a result, I included the executable heap entries as anon pages so that it would be handled in util/map.c:map__new(). The alternative would be to handle heap entries in
map__new()directly, however I wasn¹t sure if this would break something as it seems that heap and stack entries are expected to fail all map__find_* functions. Thus I considered executable heap entries as //anon, but perhaps there is a better way.
Quoted 3 lines
Hmm.. so the point is that an executable heap mapping should have
/tmp/perf-XXX.mapas a file name, right? If so, does something like below work well for you?
Just gave it a try and it fixed the issue perfectly! Thanks for the help. This looks like a much better solution than treating the heap mapping as an anon record.
Gaurav
Quoted 23 lines
tools/perf/util/map.c +1
-1@@ -69,7 +69,7 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, map->ino = ino; map->ino_generation = ino_gen; -if (anon) { +if (anon || (no_dso && type ==MAP__FUNCTION )) {snprintf (newfilename,sizeof (newfilename),"/tmp/perf-%d.map" , pid); filename = newfilename;}tools/perf/util/map.c +1
-1@@ -93,7 +93,7 @@ struct map *map__new(struct list_head *dsos__list, u64start, u64 len, * functions still return NULL, and we avoid the * unnecessary map__load warning. */ -if (no_dso) +if (no_dso && type !=MAP__FUNCTION )dso__set_loaded (dso, map->type); }
Quoted 1 line
}
�淸�{.n�+돴윯돪�+%듚�깁負쪐w��{.n�+돴쪐{깸G쳺��{ay����,j�f"톒쉹��묎�z_溫(�쉸듶줷"얎�m����G쳺�◀?솳鈺�&x�~뤳턨O뺞촾퇉v�^�m����띠�◀?뻀�
Namhyung Kim
maintainerHi Gaurav,
Quoted 11 lines · Gaurav Jain
Hi Namhyung,
Quoted 3 lines · Namhyung Kim
Hmm.. so the point is that an executable heap mapping should have
/tmp/perf-XXX.mapas a file name, right? If so, does something like below work well for you?Just gave it a try and it fixed the issue perfectly! Thanks for the help. This looks like a much better solution than treating the heap mapping as an anon record.
Thanks for testing! It's good to hear it solved your problem. :)
Quoted 12 lines
Gaurav
Quoted 9 lines
tools/perf/util/map.c +0
-0@@ -69,7 +69,7 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, map->ino = ino; map->ino_generation = ino_gen;
Quoted 2 lines
tools/perf/util/map.c struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, · line 72
Quoted 2 lines
tools/perf/util/map.c +1
-1-if (anon) { +if (anon || (no_dso && type ==MAP__FUNCTION )) {
Hmm.. I think it should check type of anon mapping too (assuming JIT interface only provides function symbols, no?):
if ((anon || no_dso) && type == MAP__FUNCTION)) {Quoted 10 lines
tools/perf/util/map.c struct map *map__new(struct list_head *dsos__list, u64 · line 97
Quoted 10 lines
tools/perf/util/map.c +0
-0snprintf (newfilename,sizeof (newfilename),"/tmp/perf-%d.map" , pid); filename = newfilename;}tools/perf/util/map.c +1
-1@@ -93,7 +93,7 @@ struct map *map__new(struct list_head *dsos__list, u64start, u64 len, * functions still return NULL, and we avoid the * unnecessary map__load warning. */ -if (no_dso) +if (no_dso && type !=MAP__FUNCTION )
And it should be simply:
if (type != MAP__FUNCTION)
Quoted 3 lines
Quoted 3 lines
tools/perf/util/map.c +0
-0dso__set_loaded (dso, map->type); }}
I'll update this and send a formal patch soon. Could you please test it with the new patch then?
Thanks,
Namhyung
Hi Namhyung,
Quoted 18 lines · Namhyung Kim
Hi Gaurav,
Quoted 14 lines · Gaurav Jain
Hi Namhyung,
Quoted 10 lines · Namhyung Kim
tools/perf/util/map.c +0
-0@@ -69,7 +69,7 @@ struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, map->ino = ino; map->ino_generation = ino_gen;
Quoted 7 lines
Quoted 2 lines
tools/perf/util/map.c struct map *map__new(struct list_head *dsos__list, u64 start, u64 len, · line 72
Quoted 2 lines
tools/perf/util/map.c +1
-1-if (anon) { +if (anon || (no_dso && type ==MAP__FUNCTION )) {Hmm.. I think it should check type of anon mapping too (assuming JIT interface only provides function symbols, no?):
if ((anon || no_dso) && type == MAP__FUNCTION)) {
In that case, shouldn't we filter out all mappings that are not executable as I had intended to do in my original patch?
Quoted 16 lines
Quoted 10 lines
tools/perf/util/map.c struct map *map__new(struct list_head *dsos__list, u64 · line 97
Quoted 10 lines
tools/perf/util/map.c +0
-0snprintf (newfilename,sizeof (newfilename),"/tmp/perf-%d.map" , pid); filename = newfilename;}tools/perf/util/map.c +1
-1@@ -93,7 +93,7 @@ struct map *map__new(struct list_head *dsos__list, u64start, u64 len, * functions still return NULL, and we avoid the * unnecessary map__load warning. */ -if (no_dso) +if (no_dso && type !=MAP__FUNCTION )And it should be simply:
if (type != MAP__FUNCTION)
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
tools/perf/util/map.c +0
-0dso__set_loaded (dso, map->type); }}I'll update this and send a formal patch soon. Could you please test it with the new patch then?
Sure I'll test the new patch, though please note my previous suggestion.
Gaurav
Quoted 19 lines · Gaurav Jain
Quoted 9 lines · Don Zickus
Quoted 8 lines · Gaurav Jain
Anon records usually do not have the 'execname' entry. However if they are on
the heap, the execname shows up as '[heap]'. The fix considers any executable
entries in the map that do not have a name or are on the heap as anon records
and sets the name to '//anon'.Quoted 5 lines
Quoted 1 line
This fixes JIT profiling for records on the heap.
I guess I don't understand the need for this fix. It seems breaking out //anon vs. [heap] would be useful. Your patch is saying otherwise. Can give a description of the problem you are trying to solve?
Thank you for looking at the patch.
Quoted 8 lines
We generate a perf map file which includes certain JIT¹ed functions that show up as [heap] entries. As a result, I included the executable heap entries as anon pages so that it would be handled in util/map.c:map__new(). The alternative would be to handle heap entries in
map__new()directly, however I wasn¹t sure if this would break something as it seems that heap and stack entries are expected to fail all map__find_* functions. Thus I considered executable heap entries as //anon, but perhaps there is a better way.
Thanks for the improved problem description. I see it led to a better
patch. :-) That is why it is generally a good idea to describe the problem you are trying to solve to see if others have a better solution.
Cheers,
Don
Quoted 40 lines
Quoted 23 lines
Also style issue below..
Quoted 20 lines
Signed-off-by Gaurav Jain <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Don Zickus <[email protected]>Cc Arun Sharma <[email protected]>--- tools/perf/util/event.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)tools/perf/util/event.c +0
-0@@ -224,10 +224,9 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool, continue;Quoted 8 lines
tools/perf/util/event.c static int perf_event__synthesize_mmap_events(struct perf_tool *tool, · line 227
Quoted 5 lines
tools/perf/util/event.c +1
-3event->header.misc |=PERF_RECORD_MISC_MMAP_DATA ; - } - -if (!strcmp (execname,"" )) + }if (!strcmp (execname,"" ) || !strcmp (execname,"[heap]" )) {The '} if' part should seperate the 'if' on to its own line (unless you meant an 'else' in there).
Bah yes, I intended 'else if'. I apologize for that. Does the fact that I filtered anon entries to only those marked as executable break the existing behavior?
Thanks,
Gaurav
Namhyung Kim
maintainerHi Don,
Quoted 29 lines · Don Zickus
Quoted 19 lines · Gaurav Jain
Quoted 9 lines · Don Zickus
Quoted 8 lines · Gaurav Jain
Anon records usually do not have the 'execname' entry. However if they are on
the heap, the execname shows up as '[heap]'. The fix considers any executable
entries in the map that do not have a name or are on the heap as anon records
and sets the name to '//anon'.Quoted 5 lines
Quoted 1 line
This fixes JIT profiling for records on the heap.
I guess I don't understand the need for this fix. It seems breaking out //anon vs. [heap] would be useful. Your patch is saying otherwise. Can give a description of the problem you are trying to solve?
Thank you for looking at the patch.
Quoted 8 lines
We generate a perf map file which includes certain JIT¹ed functions that show up as [heap] entries. As a result, I included the executable heap entries as anon pages so that it would be handled in util/map.c:map__new(). The alternative would be to handle heap entries in
map__new()directly, however I wasn¹t sure if this would break something as it seems that heap and stack entries are expected to fail all map__find_* functions. Thus I considered executable heap entries as //anon, but perhaps there is a better way.
Quoted 3 lines
Thanks for the improved problem description. I see it led to a better
patch. :-) That is why it is generally a good idea to describe the problem you are trying to solve to see if others have a better solution.
Yes, thank you very much for pointing it out and helping to resolve this issue!
Thanks,
Namhyung