Skip to contentSkip to conversation

perf stat: add interval counter printing

PATCH Superseded Stephane Eranian 2 participants 5 messages Jan 17, 2013 – Jan 18, 2013 perf events

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover perf stat: add interval counter printing

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

The -T 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 -T 1000 -e cycles noploop 10
noploop for 10 seconds
1.000086918         2385155642 cycles                    #    0.000 GHz
2.000267937         2392279774 cycles                    #    0.000 GHz
3.000385400         2390971450 cycles                    #    0.000 GHz
4.000504408         2390996752 cycles                    #    0.000 GHz
5.000626878         2390853097 cycles                    #    0.000 GHz

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

$ perf stat -x, -T 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.

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

 tools/perf/Documentation/perf-stat.txt |    3 +
 tools/perf/builtin-stat.c              |  156 ++++++++++++++++++++++++++++----
 tools/perf/util/evsel.c                |   21 +++++
 tools/perf/util/evsel.h                |    1 +
 4 files changed, 165 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 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 -T.

---
 tools/perf/util/evsel.c |   21 +++++++++++++++++++++
 tools/perf/util/evsel.h |    1 +
 2 files changed, 22 insertions(+)
tools/perf/util/evsel.c +21 -0
index 1b16dd1..132da7c 100644
@@ -646,6 +646,17 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 	if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)
 		return -errno;
 
+	if (evsel->prev_raw_counts) {
+		struct perf_counts_values tmp;
+
+		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;
+	}
+
 	if (scale) {
 		if (count.run == 0)
 			count.val = 0;
@@ -684,6 +695,16 @@ int __perf_evsel__read(struct perf_evsel *evsel,
 		}
 	}
 
+	if (evsel->prev_raw_counts) {
+		struct perf_counts_values tmp = evsel->prev_raw_counts->aggr;
+
+		evsel->prev_raw_counts->aggr = *aggr;
+
+		aggr->val = aggr->val - tmp.val;
+		aggr->ena = aggr->ena - tmp.ena;
+		aggr->run = aggr->run - tmp.run;
+	}
+
 	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 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 -T 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 -T 1000 -e cycles noploop 10
noploop for 10 seconds
1.000086918         2385155642 cycles                    #    0.000 GHz
2.000267937         2392279774 cycles                    #    0.000 GHz
3.000385400         2390971450 cycles                    #    0.000 GHz
4.000504408         2390996752 cycles                    #    0.000 GHz
5.000626878         2390853097 cycles                    #    0.000 GHz

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

$ perf stat -x, -T 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 |    3 +
 tools/perf/builtin-stat.c              |  157 ++++++++++++++++++++++++++++----
 2 files changed, 144 insertions(+), 16 deletions(-)
tools/perf/Documentation/perf-stat.txt +3 -0
index cf0c310..e00e286 100644
@@ -114,6 +114,9 @@ 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
 
+-T::
+--print-interval msec::
+	print count deltas every N milliseconds (minimu: 100ms)
 
 EXAMPLES
 --------
tools/perf/builtin-stat.c +141 -16

306 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw
In reply to Stephane Eranian
Quoted 1 line · Stephane Eranian

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

I already use that option for my haswell patchkit for transactional monitoring. Sorry, please use something else.

I agree it's a useful feature, although it can be simulated today.

-Andi

#4 lore raw
Quoted 6 lines · Andi Kleen
Quoted 1 line · Stephane Eranian

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

I already use that option for my haswell patchkit for transactional monitoring. Sorry, please use something else.

Fine. I'll find another single letter option.

Quoted 2 lines

I agree it's a useful feature, although it can be simulated today.

You an simulate in system-wide, not clear for per-thread mode.

Quoted 1 line

-Andi