perf stat: add interval counter printing
v7 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 cyclesThe 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.
In v7, we simply rebased to Arnaldo's perf/core tree.
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.10.4
PATCH v7 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
@@ -659,6 +659,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) {
@@ -674,6 +696,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 ;
@@ -712,6 +736,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
@@ -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.10.4
[tip:perf/core] perf evsel: Add prev_raw_count field
Commit-ID: c7a79c47c683de6979a3e1a96dc723b0606c07ca Gitweb: http://git.kernel.org/tip/c7a79c47c683de6979a3e1a96dc723b0606c07ca Author: Stephane Eranian <[email protected]> AuthorDate: Tue, 29 Jan 2013 12:47:43 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 30 Jan 2013 10:36:38 -0300
perf evsel: Add 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
@@ -659,6 +659,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) {
@@ -674,6 +696,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 ;
@@ -712,6 +736,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
@@ -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;
PATCH v7 2/2 perf stat: add interval printing
In reply to Stephane EranianThis 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 cyclesThe 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
@@ -114,6 +114,10 @@ with it. --append may be used here. Examples: 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
300 lines not on this page · raw message
Signature · 1 line
1.7.10.4
[tip:perf/core] perf stat: Add interval printing
Commit-ID: 13370a9b5bb88f7aa90e5be68972d95096b20a6d Gitweb: http://git.kernel.org/tip/13370a9b5bb88f7aa90e5be68972d95096b20a6d Author: Stephane Eranian <[email protected]> AuthorDate: Tue, 29 Jan 2013 12:47:44 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 30 Jan 2013 10:36:53 -0300
perf stat: Add interval printing
This patch adds a new printing mode for perf stat. It allows interval 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 cyclesThe 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
@@ -114,6 +114,10 @@ with it. --append may be used here. Examples: 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
300 lines not on this page · raw message