Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1261244 > unrolled thread
| Started by | Namhyung Kim <namhyung@kernel.org> |
|---|---|
| First post | 2015-11-03 08:30 +0100 |
| Last post | 2015-11-03 11:40 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v3 2/4] perf callchain: Abstract callchain print function Namhyung Kim <namhyung@kernel.org> - 2015-11-03 08:30 +0100
Re: [PATCH v3 2/4] perf callchain: Abstract callchain print function Jiri Olsa <jolsa@redhat.com> - 2015-11-03 09:50 +0100
Re: [PATCH v3 2/4] perf callchain: Abstract callchain print function Namhyung Kim <namhyung@kernel.org> - 2015-11-03 11:40 +0100
| From | Namhyung Kim <namhyung@kernel.org> |
|---|---|
| Date | 2015-11-03 08:30 +0100 |
| Subject | [PATCH v3 2/4] perf callchain: Abstract callchain print function |
| Message-ID | <qqEcy-83d-9@gated-at.bofh.it> |
This is a preparation to support for printing other type of callchain
value like count or period.
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/ui/browsers/hists.c | 8 +++++---
tools/perf/ui/gtk/hists.c | 8 ++------
tools/perf/ui/stdio/hist.c | 35 +++++++++++++++++------------------
tools/perf/util/callchain.c | 25 +++++++++++++++++++++++++
tools/perf/util/callchain.h | 4 ++++
5 files changed, 53 insertions(+), 27 deletions(-)
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index e5afb8936040..a8897aab4c4a 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -592,7 +592,6 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
while (node) {
struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
struct rb_node *next = rb_next(node);
- u64 cumul = callchain_cumul_hits(child);
struct callchain_list *chain;
char folded_sign = ' ';
int first = true;
@@ -619,9 +618,12 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
browser->show_dso);
if (was_first && need_percent) {
- double percent = cumul * 100.0 / total;
+ char buf[64];
- if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0)
+ callchain_node__sprintf_value(child, buf, sizeof(buf),
+ total);
+
+ if (asprintf(&alloc_str, "%s %s", buf, str) < 0)
str = "Not enough memory!";
else
str = alloc_str;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 4b3585eed1e8..d8037b7023e8 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -100,14 +100,10 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,
struct callchain_list *chain;
GtkTreeIter iter, new_parent;
bool need_new_parent;
- double percent;
- u64 hits, child_total;
+ u64 child_total;
node = rb_entry(nd, struct callchain_node, rb_node);
- hits = callchain_cumul_hits(node);
- percent = 100.0 * hits / total;
-
new_parent = *parent;
need_new_parent = !has_single_node && (node->val_nr > 1);
@@ -116,7 +112,7 @@ static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,
gtk_tree_store_append(store, &iter, &new_parent);
- scnprintf(buf, sizeof(buf), "%5.2f%%", percent);
+ callchain_node__sprintf_value(node, buf, sizeof(buf), total);
gtk_tree_store_set(store, &iter, 0, buf, -1);
callchain_list__sym_name(chain, buf, sizeof(buf), false);
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index d04c068f4acf..9b5a0d8a43dc 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -34,10 +34,10 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
return ret;
}
-static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
+static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
+ struct callchain_list *chain,
int depth, int depth_mask, int period,
- u64 total_samples, u64 hits,
- int left_margin)
+ u64 total_samples, int left_margin)
{
int i;
size_t ret = 0;
@@ -50,10 +50,9 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
else
ret += fprintf(fp, " ");
if (!period && i == depth - 1) {
- double percent;
-
- percent = hits * 100.0 / total_samples;
- ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
+ ret += fprintf(fp, "--");
+ ret += callchain_node__fprintf_value(node, fp, total_samples);
+ ret += fprintf(fp, "--");
} else
ret += fprintf(fp, "%s", " ");
}
@@ -120,10 +119,9 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,
left_margin);
i = 0;
list_for_each_entry(chain, &child->val, list) {
- ret += ipchain__fprintf_graph(fp, chain, depth,
+ ret += ipchain__fprintf_graph(fp, child, chain, depth,
new_depth_mask, i++,
total_samples,
- cumul,
left_margin);
}
@@ -143,14 +141,17 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,
if (callchain_param.mode == CHAIN_GRAPH_REL &&
remaining && remaining != total_samples) {
+ struct callchain_node rem_node = {
+ .hit = remaining,
+ };
if (!rem_sq_bracket)
return ret;
new_depth_mask &= ~(1 << (depth - 1));
- ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
+ ret += ipchain__fprintf_graph(fp, &rem_node, &rem_hits, depth,
new_depth_mask, 0, total_samples,
- remaining, left_margin);
+ left_margin);
}
return ret;
@@ -243,12 +244,11 @@ static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *tree,
struct rb_node *rb_node = rb_first(tree);
while (rb_node) {
- double percent;
-
chain = rb_entry(rb_node, struct callchain_node, rb_node);
- percent = chain->hit * 100.0 / total_samples;
- ret = percent_color_fprintf(fp, " %6.2f%%\n", percent);
+ ret += fprintf(fp, " ");
+ ret += callchain_node__fprintf_value(chain, fp, total_samples);
+ ret += fprintf(fp, "\n");
ret += __callchain__fprintf_flat(fp, chain, total_samples);
ret += fprintf(fp, "\n");
if (++entries_printed == callchain_param.print_limit)
@@ -294,12 +294,11 @@ static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
struct rb_node *rb_node = rb_first(tree);
while (rb_node) {
- double percent;
chain = rb_entry(rb_node, struct callchain_node, rb_node);
- percent = chain->hit * 100.0 / total_samples;
- ret += fprintf(fp, "%.2f%% ", percent);
+ ret += callchain_node__fprintf_value(chain, fp, total_samples);
+ ret += fprintf(fp, " ");
ret += __callchain__fprintf_folded(fp, chain);
ret += fprintf(fp, "\n");
if (++entries_printed == callchain_param.print_limit)
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 08cb220ba5ea..44184d198855 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -805,6 +805,31 @@ char *callchain_list__sym_name(struct callchain_list *cl,
return bf;
}
+char *callchain_node__sprintf_value(struct callchain_node *node,
+ char *bf, size_t bfsize, u64 total)
+{
+ double percent = 0.0;
+ u64 cumul = callchain_cumul_hits(node);
+
+ if (total)
+ percent = cumul * 100.0 / total;
+
+ scnprintf(bf, bfsize, "%6.2f%%", percent);
+ return bf;
+}
+
+int callchain_node__fprintf_value(struct callchain_node *node,
+ FILE *fp, u64 total)
+{
+ double percent = 0.0;
+ u64 cumul = callchain_cumul_hits(node);
+
+ if (total)
+ percent = cumul * 100.0 / total;
+
+ return percent_color_fprintf(fp, "%.2f%%", percent);
+}
+
static void free_callchain_node(struct callchain_node *node)
{
struct callchain_list *list, *tmp;
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 2f305384531f..3a90a57f6213 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -230,6 +230,10 @@ static inline int arch_skip_callchain_idx(struct thread *thread __maybe_unused,
char *callchain_list__sym_name(struct callchain_list *cl,
char *bf, size_t bfsize, bool show_dso);
+char *callchain_node__sprintf_value(struct callchain_node *node,
+ char *bf, size_t bfsize, u64 total);
+int callchain_node__fprintf_value(struct callchain_node *node,
+ FILE *fp, u64 total);
void free_callchain(struct callchain_root *root);
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2015-11-03 09:50 +0100 |
| Message-ID | <qqFrY-jV-1@gated-at.bofh.it> |
| In reply to | #1261244 |
On Tue, Nov 03, 2015 at 04:18:29PM +0900, Namhyung Kim wrote:
SNIP
> while (rb_node) {
> - double percent;
> -
> chain = rb_entry(rb_node, struct callchain_node, rb_node);
> - percent = chain->hit * 100.0 / total_samples;
>
> - ret = percent_color_fprintf(fp, " %6.2f%%\n", percent);
> + ret += fprintf(fp, " ");
> + ret += callchain_node__fprintf_value(chain, fp, total_samples);
> + ret += fprintf(fp, "\n");
> ret += __callchain__fprintf_flat(fp, chain, total_samples);
> ret += fprintf(fp, "\n");
> if (++entries_printed == callchain_param.print_limit)
> @@ -294,12 +294,11 @@ static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
> struct rb_node *rb_node = rb_first(tree);
>
> while (rb_node) {
> - double percent;
>
> chain = rb_entry(rb_node, struct callchain_node, rb_node);
> - percent = chain->hit * 100.0 / total_samples;
>
> - ret += fprintf(fp, "%.2f%% ", percent);
> + ret += callchain_node__fprintf_value(chain, fp, total_samples);
> + ret += fprintf(fp, " ");
hum, the callchain_node__fprintf_value gets hits as callchain_cumul_hits(node)
which is 'node->hit + node->children_hit'
while the replaced code took only 'chain->hit'
not sure now which one we actualy want here..
jirka
> ret += __callchain__fprintf_folded(fp, chain);
> ret += fprintf(fp, "\n");
> if (++entries_printed == callchain_param.print_limit)
> diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> index 08cb220ba5ea..44184d198855 100644
> --- a/tools/perf/util/callchain.c
> +++ b/tools/perf/util/callchain.c
> @@ -805,6 +805,31 @@ char *callchain_list__sym_name(struct callchain_list *cl,
> return bf;
> }
>
> +char *callchain_node__sprintf_value(struct callchain_node *node,
> + char *bf, size_t bfsize, u64 total)
> +{
> + double percent = 0.0;
> + u64 cumul = callchain_cumul_hits(node);
> +
> + if (total)
> + percent = cumul * 100.0 / total;
> +
> + scnprintf(bf, bfsize, "%6.2f%%", percent);
> + return bf;
> +}
> +
> +int callchain_node__fprintf_value(struct callchain_node *node,
> + FILE *fp, u64 total)
> +{
> + double percent = 0.0;
> + u64 cumul = callchain_cumul_hits(node);
> +
> + if (total)
> + percent = cumul * 100.0 / total;
> +
> + return percent_color_fprintf(fp, "%.2f%%", percent);
> +}
SNIP
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Namhyung Kim <namhyung@kernel.org> |
|---|---|
| Date | 2015-11-03 11:40 +0100 |
| Message-ID | <qqHap-1vK-1@gated-at.bofh.it> |
| In reply to | #1261298 |
Hi Jiri,
On Tue, Nov 03, 2015 at 09:40:55AM +0100, Jiri Olsa wrote:
> On Tue, Nov 03, 2015 at 04:18:29PM +0900, Namhyung Kim wrote:
>
> SNIP
>
> > while (rb_node) {
> > - double percent;
> > -
> > chain = rb_entry(rb_node, struct callchain_node, rb_node);
> > - percent = chain->hit * 100.0 / total_samples;
> >
> > - ret = percent_color_fprintf(fp, " %6.2f%%\n", percent);
> > + ret += fprintf(fp, " ");
> > + ret += callchain_node__fprintf_value(chain, fp, total_samples);
> > + ret += fprintf(fp, "\n");
> > ret += __callchain__fprintf_flat(fp, chain, total_samples);
> > ret += fprintf(fp, "\n");
> > if (++entries_printed == callchain_param.print_limit)
> > @@ -294,12 +294,11 @@ static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
> > struct rb_node *rb_node = rb_first(tree);
> >
> > while (rb_node) {
> > - double percent;
> >
> > chain = rb_entry(rb_node, struct callchain_node, rb_node);
> > - percent = chain->hit * 100.0 / total_samples;
> >
> > - ret += fprintf(fp, "%.2f%% ", percent);
> > + ret += callchain_node__fprintf_value(chain, fp, total_samples);
> > + ret += fprintf(fp, " ");
>
> hum, the callchain_node__fprintf_value gets hits as callchain_cumul_hits(node)
> which is 'node->hit + node->children_hit'
>
> while the replaced code took only 'chain->hit'
>
> not sure now which one we actualy want here..
Right, this is somewhat confusing..
AFAICS cumul_hits is used for other output mode, but for folded output
we should use hit without children_hit.
I added the check to use count in patch 4/4 but missed to use hit.
Will update.
Thanks,
Namhyung
>
> > ret += __callchain__fprintf_folded(fp, chain);
> > ret += fprintf(fp, "\n");
> > if (++entries_printed == callchain_param.print_limit)
> > diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> > index 08cb220ba5ea..44184d198855 100644
> > --- a/tools/perf/util/callchain.c
> > +++ b/tools/perf/util/callchain.c
> > @@ -805,6 +805,31 @@ char *callchain_list__sym_name(struct callchain_list *cl,
> > return bf;
> > }
> >
> > +char *callchain_node__sprintf_value(struct callchain_node *node,
> > + char *bf, size_t bfsize, u64 total)
> > +{
> > + double percent = 0.0;
> > + u64 cumul = callchain_cumul_hits(node);
> > +
> > + if (total)
> > + percent = cumul * 100.0 / total;
> > +
> > + scnprintf(bf, bfsize, "%6.2f%%", percent);
> > + return bf;
> > +}
> > +
> > +int callchain_node__fprintf_value(struct callchain_node *node,
> > + FILE *fp, u64 total)
> > +{
> > + double percent = 0.0;
> > + u64 cumul = callchain_cumul_hits(node);
> > +
> > + if (total)
> > + percent = cumul * 100.0 / total;
> > +
> > + return percent_color_fprintf(fp, "%.2f%%", percent);
> > +}
>
> SNIP
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web