Skip to contentSkip to conversation

DWARF/unwind support for ORDER_CALLER

PATCH New Constantine Sapuntzakis 1 participant 1 message Dec 4, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DWARF/unwind support for ORDER_CALLER

Prior to this, perf report -G and kin did not respect ORDER_CALLER for DWARF unwinds.

ORDER_CALLER is implemented for fp backtraces by reversing the callchain when pushing onto the cursor. Simulate this behavior by prepending the frames onto the cursor when doing the DWARF unwind.

---
 tools/perf/util/callchain.c | 29 +++++++++++++++++++++++++++++
 tools/perf/util/callchain.h |  3 +++
 tools/perf/util/machine.c   | 17 +++++++++++++++--
 3 files changed, 47 insertions(+), 2 deletions(-)
tools/perf/util/callchain.c +29 -0
index 564377d..b93c760 100644
@@ -742,6 +742,35 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
 	return 0;
 }
 
+int callchain_cursor_prepend(struct callchain_cursor *cursor,
+			     u64 ip, struct map *map, struct symbol *sym)
+{
+	struct callchain_cursor_node *node = *cursor->last;
+
+	if (!node) {
+		node = calloc(1, sizeof(*node));
+		if (!node)
+			return -ENOMEM;
+	} else {
+		/* Pop the first free node off the end of the list */
+		*cursor->last = node->next;
+	}
+
+	node->ip = ip;
+	node->map = map;
+	node->sym = sym;
+
+	node->next = cursor->first;
+	cursor->first = node;
+
+	cursor->nr++;
+	if (cursor->nr == 1) {
+		cursor->last = &node->next;
+	}
+
+	return 0;
+}
+
 int sample__resolve_callchain(struct perf_sample *sample, struct symbol **parent,
 			      struct perf_evsel *evsel, struct addr_location *al,
 			      int max_stack)
tools/perf/util/callchain.h +3 -0
index 8ac8f043..efa90e9 100644
@@ -182,6 +182,9 @@ static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
 
 int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
 			    struct map *map, struct symbol *sym);
+int callchain_cursor_prepend(struct callchain_cursor *cursor, u64 ip,
+			     struct map *map, struct symbol *sym);
+
 
 /* Close a cursor writing session. Initialize for the reader */
 static inline void callchain_cursor_commit(struct callchain_cursor *cursor)
tools/perf/util/machine.c +15 -2
index 95a7f60..05192d3 100644
@@ -1896,7 +1896,7 @@ check_calls:
 	return 0;
 }
 
-static int unwind_entry(struct unwind_entry *entry, void *arg)
+static int unwind_entry_callee(struct unwind_entry *entry, void *arg)
 {
 	struct callchain_cursor *cursor = arg;
 
@@ -1906,6 +1906,16 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
 				       entry->map, entry->sym);
 }
 
+static int unwind_entry_caller(struct unwind_entry *entry, void *arg)
+{
+	struct callchain_cursor *cursor = arg;
+
+	if (symbol_conf.hide_unresolved && entry->sym == NULL)
+		return 0;
+	return callchain_cursor_prepend(cursor, entry->ip,
+					entry->map, entry->sym);
+}
+
 int thread__resolve_callchain(struct thread *thread,
 			      struct perf_evsel *evsel,
 			      struct perf_sample *sample,
@@ -1929,7 +1939,10 @@ int thread__resolve_callchain(struct thread *thread,
 	    (!sample->user_stack.size))
 		return 0;
 
-	return unwind__get_entries(unwind_entry, &callchain_cursor,
+	return unwind__get_entries(callchain_param.order == ORDER_CALLEE ?
+					unwind_entry_callee :
+					unwind_entry_caller,
+				   &callchain_cursor,
 				   thread, sample, max_stack);
 
 }
Signature · 1 line
1.8.4.GIT