Skip to content

Commit

Permalink
perf script: Refactor branch stack printing
Browse files Browse the repository at this point in the history
Remove duplicate code so that future changes to flags are always made to
all 3 printing variations.

Signed-off-by: James Clark <james.clark@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20220307171917.2555829-4-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
James Clark authored and Arnaldo Carvalho de Melo committed Mar 7, 2022
1 parent 66fd6c9 commit b2dac68
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,15 @@ mispred_str(struct branch_entry *br)
return br->flags.predicted ? 'P' : 'M';
}

static int print_bstack_flags(FILE *fp, struct branch_entry *br)
{
return fprintf(fp, "/%c/%c/%c/%d ",
mispred_str(br),
br->flags.in_tx ? 'X' : '-',
br->flags.abort ? 'A' : '-',
br->flags.cycles);
}

static int perf_sample__fprintf_brstack(struct perf_sample *sample,
struct thread *thread,
struct perf_event_attr *attr, FILE *fp)
Expand Down Expand Up @@ -895,11 +904,7 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample,
printed += fprintf(fp, ")");
}

printed += fprintf(fp, "/%c/%c/%c/%d ",
mispred_str(entries + i),
entries[i].flags.in_tx ? 'X' : '-',
entries[i].flags.abort ? 'A' : '-',
entries[i].flags.cycles);
printed += print_bstack_flags(fp, entries + i);
}

return printed;
Expand Down Expand Up @@ -941,11 +946,7 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample,
printed += map__fprintf_dsoname(alt.map, fp);
printed += fprintf(fp, ")");
}
printed += fprintf(fp, "/%c/%c/%c/%d ",
mispred_str(entries + i),
entries[i].flags.in_tx ? 'X' : '-',
entries[i].flags.abort ? 'A' : '-',
entries[i].flags.cycles);
printed += print_bstack_flags(fp, entries + i);
}

return printed;
Expand Down Expand Up @@ -991,11 +992,7 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
printed += map__fprintf_dsoname(alt.map, fp);
printed += fprintf(fp, ")");
}
printed += fprintf(fp, "/%c/%c/%c/%d ",
mispred_str(entries + i),
entries[i].flags.in_tx ? 'X' : '-',
entries[i].flags.abort ? 'A' : '-',
entries[i].flags.cycles);
printed += print_bstack_flags(fp, entries + i);
}

return printed;
Expand Down

0 comments on commit b2dac68

Please sign in to comment.