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 #1978

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions utils/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ 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 *search_curr = NULL;
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it needs to be 'static'.


if (tg->lost)
return 1; /* ignore kernel functions after LOST */
Expand All @@ -77,6 +81,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->name && curr->parent && curr->parent->name) {
skip = !strcmp(name, curr->name) && !strcmp(name, curr->parent->name);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for curly brackets on a single line statement.


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

list_for_each_entry(node, &curr->head, list) {
if (name && !strcmp(name, node->name))
break;
Expand All @@ -91,6 +107,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 +145,13 @@ static int add_graph_entry(struct uftrace_task_graph *tg, char *name, size_t nod

out:
node->nr_calls++;
if (skip && recursive_src) {
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