diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-07-02 11:58:19 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-07-02 14:47:14 -0400 |
commit | 14f4654cbd531d48651e005cf05907c14bddb193 (patch) | |
tree | 4b94148c21e90705a188523174ee2c21e81151ca /tools | |
parent | 429764873cf3fc3e73142872a674bb27cda589c1 (diff) |
perf_counter tools: Create new chain_for_each_child() iterator
Iterating through children of a node in the callchain tree
shows something that may be quite confusing at a first glance.
The head is the children field of the parent and the list nodes
are in the brothers field of the children.
This is because the childs are linked to the parent as a list
of "brothers" using the "children" list of the parent as a
head:
---------------
| Parent (head) |-------------------------------------
--------------- |
| |
children |
| |
----------- ----------- |
| 1st child |---brother---| 2nd child |---brother-----
----------- -----------
This makes the following strange pattern often occuring:
list_for_each_entry(child, &parent->children, brothers) {
// do something with children
}
Abstract it to chain_for_each_child() to factorize and simplify
this pattern.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Anton Blanchard <anton@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <1246550301-8954-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/callchain.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 3dceabd9b5ef..3c4a91fea622 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -16,6 +16,9 @@ | |||
16 | 16 | ||
17 | #include "callchain.h" | 17 | #include "callchain.h" |
18 | 18 | ||
19 | #define chain_for_each_child(child, parent) \ | ||
20 | list_for_each_entry(child, &parent->children, brothers) | ||
21 | |||
19 | 22 | ||
20 | static void | 23 | static void |
21 | rb_insert_callchain(struct rb_root *root, struct callchain_node *chain) | 24 | rb_insert_callchain(struct rb_root *root, struct callchain_node *chain) |
@@ -46,7 +49,7 @@ void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node) | |||
46 | { | 49 | { |
47 | struct callchain_node *child; | 50 | struct callchain_node *child; |
48 | 51 | ||
49 | list_for_each_entry(child, &node->children, brothers) | 52 | chain_for_each_child(child, node) |
50 | sort_chain_to_rbtree(rb_root, child); | 53 | sort_chain_to_rbtree(rb_root, child); |
51 | 54 | ||
52 | if (node->hit) | 55 | if (node->hit) |
@@ -77,7 +80,7 @@ create_child(struct callchain_node *parent, bool inherit_children) | |||
77 | list_splice(&parent->children, &new->children); | 80 | list_splice(&parent->children, &new->children); |
78 | INIT_LIST_HEAD(&parent->children); | 81 | INIT_LIST_HEAD(&parent->children); |
79 | 82 | ||
80 | list_for_each_entry(next, &new->children, brothers) | 83 | chain_for_each_child(next, new) |
81 | next->parent = new; | 84 | next->parent = new; |
82 | } | 85 | } |
83 | list_add_tail(&new->brothers, &parent->children); | 86 | list_add_tail(&new->brothers, &parent->children); |
@@ -173,7 +176,7 @@ __append_chain_children(struct callchain_node *root, struct ip_callchain *chain, | |||
173 | struct callchain_node *rnode; | 176 | struct callchain_node *rnode; |
174 | 177 | ||
175 | /* lookup in childrens */ | 178 | /* lookup in childrens */ |
176 | list_for_each_entry(rnode, &root->children, brothers) { | 179 | chain_for_each_child(rnode, root) { |
177 | unsigned int ret = __append_chain(rnode, chain, start, syms); | 180 | unsigned int ret = __append_chain(rnode, chain, start, syms); |
178 | 181 | ||
179 | if (!ret) | 182 | if (!ret) |