[PATCH 08/15] perf callchain: Add a couple of callchain helpers

From: Namhyung Kim
Date: Thu Sep 13 2012 - 03:29:39 EST


From: Namhyung Kim <namhyung.kim@xxxxxxx>

To accumulate callchain information of a hist entry, following helper
functions are needed.

Cc: Arun Sharma <asharma@xxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/callchain.c | 15 +++++++++++++++
tools/perf/util/callchain.h | 17 +++++++++++++++++
2 files changed, 32 insertions(+)

diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index d3b3f5d82137..255c4a8266be 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -461,3 +461,18 @@ int callchain_cursor_append(struct callchain_cursor *cursor,

return 0;
}
+
+int callchain_cursor_peek_al(struct callchain_cursor *cursor,
+ struct addr_location *al)
+{
+ struct callchain_cursor_node *node = cursor->first;
+
+ if (node == NULL || cursor->nr == 0)
+ return -1;
+
+ al->map = node->map;
+ al->sym = node->sym;
+ al->addr = node->ip;
+
+ return 0;
+}
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 3bdb407f9cd9..46ca2b4360e3 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -4,6 +4,7 @@
#include "../perf.h"
#include <linux/list.h>
#include <linux/rbtree.h>
+#include <string.h>
#include "event.h"
#include "symbol.h"

@@ -143,4 +144,20 @@ static inline void callchain_cursor_advance(struct callchain_cursor *cursor)
cursor->curr = cursor->curr->next;
cursor->pos++;
}
+
+/* NOTE: This function can leak a cursor node. Use with caution. */
+static inline void callchain_cursor_next(struct callchain_cursor *cursor)
+{
+ cursor->first = cursor->first->next;
+ cursor->nr--;
+}
+
+static inline void callchain_cursor_copy(struct callchain_cursor *dest,
+ struct callchain_cursor *src)
+{
+ memcpy(dest, src, sizeof(*src));
+}
+
+int callchain_cursor_peek_al(struct callchain_cursor *cursor,
+ struct addr_location *al);
#endif /* __PERF_CALLCHAIN_H */
--
1.7.11.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/