Skip to contentSkip to conversation

perf annotate: Remove hist__account_cycles from callback

PATCH Superseded Jin Yao 2 participants 5 messages Mar 12, 2019 – Mar 15, 2019 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

PATCH 1/1 perf annotate: Remove hist__account_cycles from callback

The hist__account_cycles is executed when the hist_iter__branch_callback is called. But it looks it's not necessary. In hist__account_cycles, it already walks on all branch entries.

This patch moves the hist__account_cycles out of callback, now the data processing is much faster than before.

For example,
perf record -b ...
perf annotate

The before/after output should be no change.

---
 tools/perf/builtin-annotate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-annotate.c +2 -2
index 67f9d9f..77deb3a 100644
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
 	struct perf_evsel *evsel = iter->evsel;
 	int err;
 
-	hist__account_cycles(sample->branch_stack, al, sample, false);
-
 	bi = he->branch_info;
 	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
 
@@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
 	if (a.map != NULL)
 		a.map->dso->hit = 1;
 
+	hist__account_cycles(sample->branch_stack, al, sample, false);
+
 	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
 	return ret;
 }
Signature · 1 line
2.7.4
author
#1 lore raw

Any comments for this patch or any issue is found? In testing, I just feel it accelerates the perf annotate data processing.

Thanks
Jin Yao

Quoted 41 lines · Jin Yao

The hist__account_cycles is executed when the hist_iter__branch_callback is called. But it looks it's not necessary. In hist__account_cycles, it already walks on all branch entries.

This patch moves the hist__account_cycles out of callback, now the data processing is much faster than before.

For example,
perf record -b ...
perf annotate

The before/after output should be no change.

---
  tools/perf/builtin-annotate.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-annotate.c +2 -2
index 67f9d9f..77deb3a 100644
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
  	struct perf_evsel *evsel = iter->evsel;
  	int err;
 
-	hist__account_cycles(sample->branch_stack, al, sample, false);
-
  	bi = he->branch_info;
  	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
 
@@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
  	if (a.map != NULL)
  		a.map->dso->hit = 1;
 
+	hist__account_cycles(sample->branch_stack, al, sample, false);
+
  	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
  	return ret;
  }
#2 lore raw
In reply to Jin Yao
Quoted 4 lines · Jin Yao

The hist__account_cycles is executed when the hist_iter__branch_callback is called. But it looks it's not necessary. In hist__account_cycles, it already walks on all branch entries.

Quoted 8 lines

This patch moves the hist__account_cycles out of callback, now the data processing is much faster than before.

For example,
perf record -b ...
perf annotate

The before/after output should be no change.

so in the old code it was called multiple times per sample, while after your change it's called just once per sample

it increases cycles stats for symbol, so it's strange the behaviour is the same.. could you please exaplin this in more detail?

Quoted 11 lines
---
 tools/perf/builtin-annotate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-annotate.c +0 -0
index 67f9d9f..77deb3a 100644

tools/perf/builtin-annotate.c static int hist_iter__branch_callback(struct hist_entry_iter *iter, · line 163

Quoted 5 lines
tools/perf/builtin-annotate.c +0 -2
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
 	struct perf_evsel *evsel = iter->evsel;
 	int err;
 
-	hist__account_cycles(sample->branch_stack, al, sample, false);
-

there's similar code in perf report, could you please cover that as well?

thanks,
jirka

Quoted 15 lines
tools/perf/builtin-annotate.c +2 -0
 	bi = he->branch_info;
 	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
 
@@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
 	if (a.map != NULL)
 		a.map->dso->hit = 1;
 
+	hist__account_cycles(sample->branch_stack, al, sample, false);
+
 	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
 	return ret;
 }
Signature · 1 line
2.7.4
author
#3 lore raw
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Jin Yao

The hist__account_cycles is executed when the hist_iter__branch_callback is called. But it looks it's not necessary. In hist__account_cycles, it already walks on all branch entries.

This patch moves the hist__account_cycles out of callback, now the data processing is much faster than before.

For example,
perf record -b ...
perf annotate

Quoted 9 lines
Quoted 1 line

The before/after output should be no change.

so in the old code it was called multiple times per sample, while after your change it's called just once per sample

it increases cycles stats for symbol, so it's strange the behaviour is the same.. could you please exaplin this in more detail?

In __symbol__account_cycles,
ch[offset].num_aggr++;
ch[offset].cycles_aggr += cycles;

In annotation__compute_ipc,
al = notes->offsets[offset];
al->cycles = ch->cycles_aggr / ch->num_aggr;

So the num_aggr and cycles_aggr are both increased n times, then the final result is the same.

Quoted 14 lines
Quoted 14 lines
---
  tools/perf/builtin-annotate.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-annotate.c +0 -0
index 67f9d9f..77deb3a 100644
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct hist_entry_iter *iter,
  	struct perf_evsel *evsel = iter->evsel;
  	int err;
 
Quoted 6 lines

tools/perf/builtin-annotate.c static int hist_iter__branch_callback(struct hist_entry_iter *iter, · line 163

Quoted 2 lines
tools/perf/builtin-annotate.c +0 -2
-	hist__account_cycles(sample->branch_stack, al, sample, false);
-

there's similar code in perf report, could you please cover that as well?

Sure, let me have a try.

Thanks
Jin Yao

Quoted 18 lines

thanks,
jirka

Quoted 15 lines
tools/perf/builtin-annotate.c +2 -0
  	bi = he->branch_info;
  	err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
 
@@ -199,6 +197,8 @@ static int process_branch_callback(struct perf_evsel *evsel,
  	if (a.map != NULL)
  		a.map->dso->hit = 1;
 
+	hist__account_cycles(sample->branch_stack, al, sample, false);
+
  	ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
  	return ret;
  }
Signature · 1 line
2.7.4
author
#4 lore raw
Quoted 29 lines · Yao
Quoted 12 lines · Jiri Olsa
Quoted 11 lines · Jin Yao

The hist__account_cycles is executed when the hist_iter__branch_callback is called. But it looks it's not necessary. In hist__account_cycles, it already walks on all branch entries.

This patch moves the hist__account_cycles out of callback, now the data processing is much faster than before.

For example,
perf record -b ...
perf annotate

Quoted 9 lines
Quoted 1 line

The before/after output should be no change.

so in the old code it was called multiple times per sample, while after your change it's called just once per sample

it increases cycles stats for symbol, so it's strange the behaviour is the same.. could you please exaplin this in more detail?

In __symbol__account_cycles,
ch[offset].num_aggr++;
ch[offset].cycles_aggr += cycles;

Quoted 6 lines

In annotation__compute_ipc,
al = notes->offsets[offset];
al->cycles = ch->cycles_aggr / ch->num_aggr;

So the num_aggr and cycles_aggr are both increased n times, then the final result is the same.

There might be another potential issue in annotation__count_and_fill.

/* Hide data when there are too many overlaps. */ if (ch->reset >= 0x7fff || ch->reset >= ch->num / 2)

	return;

When ch->reset is 0 and ch->num is 1, it returns directly. But for this case, the data doesn't need to be hidden since there is no overlap happening.

I will post v2 and add this fix.

Thanks
Jin Yao

Quoted 43 lines
Quoted 6 lines
Quoted 6 lines

---
  tools/perf/builtin-annotate.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines

tools/perf/builtin-annotate.c static int hist_iter__branch_callback(struct · line 163

Quoted 10 lines
tools/perf/builtin-annotate.c +0 -2
index 67f9d9f..77deb3a 100644
@@ -159,8 +159,6 @@ static int hist_iter__branch_callback(struct 
 hist_entry_iter *iter,
       struct perf_evsel *evsel = iter->evsel;
       int err;
-    hist__account_cycles(sample->branch_stack, al, sample, false);
-

there's similar code in perf report, could you please cover that as well?

Sure, let me have a try.

Thanks
Jin Yao

Quoted 17 lines

thanks,
jirka

Quoted 14 lines
tools/perf/builtin-annotate.c +2 -0
       bi = he->branch_info;
       err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
@@ -199,6 +197,8 @@ static int process_branch_callback(struct 
 perf_evsel *evsel,
       if (a.map != NULL)
           a.map->dso->hit = 1;
+    hist__account_cycles(sample->branch_stack, al, sample, false);
+
       ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
       return ret;
   }
Signature · 1 line
2.7.4