Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dump: Handle cycles in graphviz #1977

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmds/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,8 +1258,9 @@ static void print_graph_to_graphviz(struct uftrace_graph_node *node, struct uftr
{
struct uftrace_graph_node *child;
unsigned long n_calls = node->nr_calls;
bool skip = node->skip;

if (n_calls) {
if (n_calls && !skip) {
struct uftrace_graph_node *parent = node->parent;

pr_out(" ");
Expand Down
23 changes: 23 additions & 0 deletions utils/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ static int add_graph_entry(struct uftrace_task_graph *tg, char *name, size_t nod
{
struct uftrace_graph_node *node = NULL;
struct uftrace_graph_node *curr = tg->node;
struct uftrace_graph_node *recursive_src = NULL;
struct uftrace_graph_node *add_calls_tgt = NULL;
struct uftrace_fstack *fstack;
static uint32_t next_id = 1;
static bool skip = false;

if (tg->lost)
return 1; /* ignore kernel functions after LOST */
Expand All @@ -77,6 +80,18 @@ static int add_graph_entry(struct uftrace_task_graph *tg, char *name, size_t nod
if (curr == NULL || fstack == NULL)
return -1;

if (name) {
if (curr && curr->parent) {
skip = !strcmp(name, curr->name) && !strcmp(name, curr->parent->name);
}

while (curr && !strcmp(name, curr->name)) {
recursive_src = curr;
curr = curr->parent;
}
}

curr = tg->node;
list_for_each_entry(node, &curr->head, list) {
if (name && !strcmp(name, node->name))
break;
Expand All @@ -91,6 +106,7 @@ static int add_graph_entry(struct uftrace_task_graph *tg, char *name, size_t nod
node->id = next_id++;
node->addr = fstack->addr;
node->name = xstrdup(name ?: "none");
node->skip = skip;
INIT_LIST_HEAD(&node->head);

node->parent = curr;
Expand Down Expand Up @@ -128,6 +144,13 @@ static int add_graph_entry(struct uftrace_task_graph *tg, char *name, size_t nod

out:
node->nr_calls++;
if (skip) {
list_for_each_entry(add_calls_tgt, &recursive_src->head, list) {
if (name && !strcmp(name, add_calls_tgt->name))
break;
}
add_calls_tgt->nr_calls++;
}
tg->node = node;

if (entry_cb)
Expand Down
1 change: 1 addition & 0 deletions utils/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct uftrace_graph_node {
uint64_t time;
uint64_t child_time;
uint32_t id;
bool skip;
struct list_head head;
struct list_head list;
struct uftrace_graph_node *parent;
Expand Down
Loading