Skip to contentSkip to conversation

perf stat: add interval counter printing

PATCH Superseded Stephane Eranian 3 participants 13 messages Jan 22, 2013 – Jan 29, 2013 perf events

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover perf stat: add interval counter printing

This small patchset extends perf stat with the -I option.

The -I option enables interval printing. It expects an interval duration in milliseconds. Minimum is 100ms. Once, activated perf stat prints events deltas since last printout. All modes are supported.

$ perf stat -I 1000 -e cycles noploop 10
noploop for 10 seconds
 #           time             counts events
      1.000109853      2,388,560,546 cycles
      2.000262846      2,393,332,358 cycles
      3.000354131      2,393,176,537 cycles
      4.000439503      2,393,203,790 cycles
      5.000527075      2,393,167,675 cycles
      6.000609052      2,393,203,670 cycles
      7.000691082      2,393,175,678 cycles

The output format makes it easy to feed into a plotting program such as gnuplot when the -I option is used in combination with the -x option:

$ perf stat -x, -I 1000 -e cycles noploop 10
noploop for 10 seconds
1.000084113,2378775498,cycles
2.000245798,2391056897,cycles
3.000354445,2392089414,cycles
4.000459115,2390936603,cycles
5.000565341,2392108173,cycles

The first patch adds the code to keep previous counts. The second is the actual extension of perf stat.

In v2, we changed the option from -T to -I based on feedback from Andi Kleen (who is using -T in an upcoming patch).

In v3, added compute_deltas() to evsel.c to factorize deltas computation based on Jiri's comments.

In v4, we made sure that counts are printed in case the run is interrupted by CTRL-C based on Andi Kleen's feedback.

In v5, we added the column headings printed every 25 lines. Cleaned up the code some more based on Namhyung's comments.

In v6, we simplify print_stat() by dropping the useless check for interval as noted by Namhyung Kim. We also rebase to 3.8.0-rc4.

Stephane Eranian (2):
perf tools: add evsel prev_raw_count field
perf stat: add interval printing

 tools/perf/Documentation/perf-stat.txt |    4 +
 tools/perf/builtin-stat.c              |  157 +++++++++++++++++++++++++++++---
 tools/perf/util/evsel.c                |   26 ++++++
 tools/perf/util/evsel.h                |    1 +
 4 files changed, 173 insertions(+), 15 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v6 1/2 perf tools: add evsel prev_raw_count field

This field will be used by commands which print
counter deltas on regular timer intervals,
such as perf stat -I.

---
 tools/perf/util/evsel.c |   26 ++++++++++++++++++++++++++
 tools/perf/util/evsel.h |    1 +
 2 files changed, 27 insertions(+)
tools/perf/util/evsel.c +26 -0
index 1b16dd1..371e93d 100644
@@ -631,6 +631,28 @@ void perf_evsel__delete(struct perf_evsel *evsel)
 	free(evsel);
 }
 
+static inline void compute_deltas(struct perf_evsel *evsel,
+				  int cpu,
+				  struct perf_counts_values *count)
+{
+	struct perf_counts_values tmp;
+
+	if (!evsel->prev_raw_counts)
+		return;
+
+	if (cpu == -1) {
+		tmp = evsel->prev_raw_counts->aggr;
+		evsel->prev_raw_counts->aggr = *count;
+	} else {
+		tmp = evsel->prev_raw_counts->cpu[cpu];
+		evsel->prev_raw_counts->cpu[cpu] = *count;
+	}
+
+	count->val = count->val - tmp.val;
+	count->ena = count->ena - tmp.ena;
+	count->run = count->run - tmp.run;
+}
+
 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 			      int cpu, int thread, bool scale)
 {
@@ -646,6 +668,8 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 	if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
 		return -errno;
 
+	compute_deltas(evsel, cpu, &count);
+
 	if (scale) {
 		if (count.run == 0)
 			count.val = 0;
@@ -684,6 +708,8 @@ int __perf_evsel__read(struct perf_evsel *evsel,
 		}
 	}
 
+	compute_deltas(evsel, -1, aggr);
+
 	evsel->counts->scaled = 0;
 	if (scale) {
 		if (aggr->run == 0) {
tools/perf/util/evsel.h +1 -0
index 3d2b801..63ea570 100644
@@ -53,6 +53,7 @@ struct perf_evsel {
 	struct xyarray		*sample_id;
 	u64			*id;
 	struct perf_counts	*counts;
+	struct perf_counts	*prev_raw_counts;
 	int			idx;
 	u32			ids;
 	struct hists		hists;
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v6 2/2 perf stat: add interval printing

In reply to Stephane Eranian

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

The -I option enables interval printing. It expects an interval duration in milliseconds. Minimum is 100ms. Once, activated perf stat prints events deltas since last printout. All modes are supported.

$ perf stat -I 1000 -e cycles noploop 10
noploop for 10 seconds
 #           time             counts events
      1.000109853      2,388,560,546 cycles
      2.000262846      2,393,332,358 cycles
      3.000354131      2,393,176,537 cycles
      4.000439503      2,393,203,790 cycles
      5.000527075      2,393,167,675 cycles
      6.000609052      2,393,203,670 cycles
      7.000691082      2,393,175,678 cycles

The output format makes it easy to feed into a plotting program such as gnuplot when the -I option is used in combination with the -x option:

$ perf stat -x, -I 1000 -e cycles noploop 10
noploop for 10 seconds
1.000084113,2378775498,cycles
2.000245798,2391056897,cycles
3.000354445,2392089414,cycles
4.000459115,2390936603,cycles
5.000565341,2392108173,cycles
---
 tools/perf/Documentation/perf-stat.txt |    4 +
 tools/perf/builtin-stat.c              |  157 +++++++++++++++++++++++++++++---
 2 files changed, 146 insertions(+), 15 deletions(-)
tools/perf/Documentation/perf-stat.txt +4 -0
index cf0c310..5289da3 100644
@@ -114,6 +114,10 @@ Log output to fd, instead of stderr.  Complementary to --output, and mutually ex
 
 perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' -- make -s -j64 O=defconfig-build/ bzImage
 
+-I msecs::
+--interval-print msecs::
+	print count deltas every N milliseconds (minimum: 100ms)
+	example: perf stat -I 1000 -e cycles -a sleep 5
 
 EXAMPLES
 --------
tools/perf/builtin-stat.c +142 -15

299 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Quoted 2 lines · Stephane Eranian

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat

s/rnv/rv

Quoted 8 lines

can now print event deltas at regular time interval. This is useful to detect phases in programs.

The -I option enables interval printing. It expects an interval duration in milliseconds. Minimum is 100ms. Once, activated perf stat prints events deltas since last printout. All modes are supported.

Quoted 10 lines
$ perf stat -I 1000 -e cycles noploop 10
noploop for 10 seconds
 #           time             counts events
      1.000109853      2,388,560,546 cycles
      2.000262846      2,393,332,358 cycles
      3.000354131      2,393,176,537 cycles
      4.000439503      2,393,203,790 cycles
      5.000527075      2,393,167,675 cycles
      6.000609052      2,393,203,670 cycles
      7.000691082      2,393,175,678 cycles

Looks useful!

Thanks,

Ingo

#4 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

In reply to Stephane Eranian

Em Tue, Jan 22, 2013 at 02:18:52PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

This patch is not applying to my perf/core branch, does it depend on some other outstanding patchset from you?

Tomorrow probably all I had in this area will be in Ingo's tree, but can you please take a look at my perf/core branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

?

Regards,

- Arnaldo

#5 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Quoted 6 lines · Arnaldo Carvalho de Melo

Em Tue, Jan 22, 2013 at 02:18:52PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

Quoted 8 lines

This patch is not applying to my perf/core branch, does it depend on some other outstanding patchset from you?

Tomorrow probably all I had in this area will be in Ingo's tree, but can you please take a look at my perf/core branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Quoted 5 lines

?

Regards,

- Arnaldo

#6 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 14 lines
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Tue, Jan 22, 2013 at 02:18:52PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

This patch is not applying to my perf/core branch, does it depend on some other outstanding patchset from you?

Tomorrow probably all I had in this area will be in Ingo's tree, but can you please take a look at my perf/core branch at:

Quoted 6 lines
Quoted 2 lines

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

- Arnaldo

#7 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Quoted 17 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 16 lines
Quoted 14 lines · Arnaldo Carvalho de Melo

Em Tue, Jan 22, 2013 at 02:18:52PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

This patch is not applying to my perf/core branch, does it depend on some other outstanding patchset from you?

Tomorrow probably all I had in this area will be in Ingo's tree, but can you please take a look at my perf/core branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

Quoted 9 lines
Quoted 4 lines

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

How's the kernel proper side of your tree sync'd with tip.git? I cannot have the kernel patches for one tree and the perf patches for another. That's a lot of overhead especially when it comes to testing.

#8 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Em Mon, Jan 28, 2013 at 07:26:17PM +0100, Stephane Eranian escreveu:

Quoted 24 lines
Quoted 22 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 20 lines
Quoted 6 lines · Arnaldo Carvalho de Melo

Em Tue, Jan 22, 2013 at 02:18:52PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

Quoted 8 lines

This patch is not applying to my perf/core branch, does it depend on some other outstanding patchset from you?

Tomorrow probably all I had in this area will be in Ingo's tree, but can you please take a look at my perf/core branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Quoted 7 lines
Quoted 4 lines

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

How's the kernel proper side of your tree sync'd with tip.git? I cannot have the kernel patches for one tree and the perf patches for another. That's a lot of overhead especially when it comes to testing.

Normally regularly, right now it seems all is synched.

- Arnaldo

#9 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Quoted 29 lines · Arnaldo Carvalho de Melo

Em Mon, Jan 28, 2013 at 07:26:17PM +0100, Stephane Eranian escreveu:

Quoted 28 lines
Quoted 26 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 14 lines
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Tue, Jan 22, 2013 at 02:18:52PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

This patch adds a new printing mode for perf stat. It allows internval printing. That means perf stat can now print event deltas at regular time interval. This is useful to detect phases in programs.

This patch is not applying to my perf/core branch, does it depend on some other outstanding patchset from you?

Tomorrow probably all I had in this area will be in Ingo's tree, but can you please take a look at my perf/core branch at:

Quoted 6 lines
Quoted 2 lines

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

Quoted 6 lines
Quoted 3 lines

How's the kernel proper side of your tree sync'd with tip.git? I cannot have the kernel patches for one tree and the perf patches for another. That's a lot of overhead especially when it comes to testing.

Normally regularly, right now it seems all is synched.

Ok, will resubmit the series against your tree then.

#10 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Em Mon, Jan 28, 2013 at 11:45:56PM +0100, Stephane Eranian escreveu:

Quoted 15 lines
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Jan 28, 2013 at 07:26:17PM +0100, Stephane Eranian escreveu:

Quoted 11 lines
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

How's the kernel proper side of your tree sync'd with tip.git? I cannot have the kernel patches for one tree and the perf patches for another. That's a lot of overhead especially when it comes to testing.

Normally regularly, right now it seems all is synched.

Ok, will resubmit the series against your tree then.

Also everytime Ingo merges I rebase my tree against tip/perf/core, if you ever need something that is in some other branch that everybody agrees will go upstream, like tip/perf/urgent or Linus's, just let me know and I'll coordinate with Ingo and merge it into acme/perf/core.

Talking about that I need to merge tip/perf/urgent, Jiri needs that precise attribute revert...

- Arnaldo

#11 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Arnaldo,

V7 posted. It's a rebase done against your perf/core, was no big deal. Let me know if it works for you now.

Quoted 33 lines · Arnaldo Carvalho de Melo

Em Mon, Jan 28, 2013 at 11:45:56PM +0100, Stephane Eranian escreveu:

Quoted 15 lines
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Jan 28, 2013 at 07:26:17PM +0100, Stephane Eranian escreveu:

Quoted 11 lines
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

How's the kernel proper side of your tree sync'd with tip.git? I cannot have the kernel patches for one tree and the perf patches for another. That's a lot of overhead especially when it comes to testing.

Normally regularly, right now it seems all is synched.

Ok, will resubmit the series against your tree then.

Also everytime Ingo merges I rebase my tree against tip/perf/core, if you ever need something that is in some other branch that everybody agrees will go upstream, like tip/perf/urgent or Linus's, just let me know and I'll coordinate with Ingo and merge it into acme/perf/core.

Talking about that I need to merge tip/perf/urgent, Jiri needs that precise attribute revert...

- Arnaldo

#12 lore raw

Re: [PATCH v6 2/2] perf stat: add interval printing

Em Tue, Jan 29, 2013 at 12:48:51PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

Arnaldo,

V7 posted. It's a rebase done against your perf/core, was no big deal. Let me know if it works for you now.

Thanks, it is now merged in my perf/core branch,

- Arnaldo

Quoted 36 lines
Quoted 33 lines · Arnaldo Carvalho de Melo

Em Mon, Jan 28, 2013 at 11:45:56PM +0100, Stephane Eranian escreveu:

Quoted 15 lines
Quoted 12 lines · Arnaldo Carvalho de Melo

Em Mon, Jan 28, 2013 at 07:26:17PM +0100, Stephane Eranian escreveu:

Quoted 11 lines
Quoted 9 lines · Arnaldo Carvalho de Melo

Em Fri, Jan 25, 2013 at 04:21:11PM +0100, Stephane Eranian escreveu:

Quoted 4 lines

My patches are always relative to:
git://git.kernel.org/pub/scm/linux/kernel/git/tip.tip.git

Do you still need to rebase against your tree?

Well, userspace code normally is developed on my tree and eventually goes to the one you mentioned. If you make sure that now, that both are synched after some weeks, then probably it'll work with my tree.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

How's the kernel proper side of your tree sync'd with tip.git? I cannot have the kernel patches for one tree and the perf patches for another. That's a lot of overhead especially when it comes to testing.

Normally regularly, right now it seems all is synched.

Ok, will resubmit the series against your tree then.

Also everytime Ingo merges I rebase my tree against tip/perf/core, if you ever need something that is in some other branch that everybody agrees will go upstream, like tip/perf/urgent or Linus's, just let me know and I'll coordinate with Ingo and merge it into acme/perf/core.

Talking about that I need to merge tip/perf/urgent, Jiri needs that precise attribute revert...

- Arnaldo