Skip to contentSkip to conversation

perf: change samples type to unsigned long long

PATCH In review Yang Shi 4 participants 5 messages Sep 29, 2015 – Oct 3, 2015 perf events

lore
Share & tools
lore

Yang Shi

author
#0 lore raw

PATCH 1/1 perf: change samples type to unsigned long long

When run "perf record -e", the number of samples showed up is wrong on some 32 bit systems, i.e. powerpc and arm.

For example, run the below commands on 32 bit powerpc:

perf probe -x /lib/libc.so.6 malloc
perf record -e probe_libc:malloc -a ls
perf.data
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.036 MB perf.data (13829241621624967218 samples) ]

Actually, "perf script" just shows 21 samples. The number of samples is also absurd since samples is long type, but it is printed as PRIu64.

Build test is run on x86-64, x86, aarch64, arm, mips, ppc and ppc64.

---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
index 142eeb3..e54aa4c 100644
@@ -49,7 +49,7 @@ struct record {
 	int			realtime_prio;
 	bool			no_buildid;
 	bool			no_buildid_cache;
-	long			samples;
+	unsigned long long	samples;
 };
 
 static int record__write(struct record *rec, void *bf, size_t size)
Signature · 1 line
2.0.2
#1 lore raw

Em Tue, Sep 29, 2015 at 02:49:43PM -0700, Yang Shi escreveu:

Quoted 11 lines

When run "perf record -e", the number of samples showed up is wrong on some 32 bit systems, i.e. powerpc and arm.

For example, run the below commands on 32 bit powerpc:

perf probe -x /lib/libc.so.6 malloc
perf record -e probe_libc:malloc -a ls
perf.data
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.036 MB perf.data (13829241621624967218 samples) ]

Quoted 4 lines

Actually, "perf script" just shows 21 samples. The number of samples is also absurd since samples is long type, but it is printed as PRIu64.

Build test is run on x86-64, x86, aarch64, arm, mips, ppc and ppc64.

Sure?

AR /tmp/build/perf/libperf.a
builtin-record.c: In function ‘__cmd_record’:
builtin-record.c:689:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

- Arnaldo

Quoted 20 lines
---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
index 142eeb3..e54aa4c 100644
@@ -49,7 +49,7 @@ struct record {
 	int			realtime_prio;
 	bool			no_buildid;
 	bool			no_buildid_cache;
-	long			samples;
+	unsigned long long	samples;
 };
 
 static int record__write(struct record *rec, void *bf, size_t size)
Signature · 1 line
2.0.2
#2 lore raw

Em Fri, Oct 02, 2015 at 04:08:38PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 15 lines

Em Tue, Sep 29, 2015 at 02:49:43PM -0700, Yang Shi escreveu:

Quoted 14 lines

When run "perf record -e", the number of samples showed up is wrong on some 32 bit systems, i.e. powerpc and arm.

For example, run the below commands on 32 bit powerpc:

perf probe -x /lib/libc.so.6 malloc
perf record -e probe_libc:malloc -a ls
perf.data
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.036 MB perf.data (13829241621624967218 samples) ]

Actually, "perf script" just shows 21 samples. The number of samples is also absurd since samples is long type, but it is printed as PRIu64.

Quoted 8 lines
Quoted 1 line

Build test is run on x86-64, x86, aarch64, arm, mips, ppc and ppc64.

Sure?

AR /tmp/build/perf/libperf.a
builtin-record.c: In function ‘__cmd_record’:
builtin-record.c:689:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

You missed something important, I am fixing this and applying your patch:

tools/perf/builtin-record.c +1 -1
index 974065f8ce80..24ace2f318c1 100644
@@ -667,7 +667,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 	auxtrace_snapshot_enabled = 1;
 	for (;;) {
-		int hits = rec->samples;
+		unsigned long long hits = rec->samples;
 
 		if (record__mmap_read_all(rec) < 0) {
 			auxtrace_snapshot_enabled = 0;
author
#3 lore raw
Quoted 20 lines · Arnaldo Carvalho de Melo

Em Fri, Oct 02, 2015 at 04:08:38PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 19 lines

Em Tue, Sep 29, 2015 at 02:49:43PM -0700, Yang Shi escreveu:

Quoted 11 lines

When run "perf record -e", the number of samples showed up is wrong on some 32 bit systems, i.e. powerpc and arm.

For example, run the below commands on 32 bit powerpc:

perf probe -x /lib/libc.so.6 malloc
perf record -e probe_libc:malloc -a ls
perf.data
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.036 MB perf.data (13829241621624967218 samples) ]

Quoted 4 lines

Actually, "perf script" just shows 21 samples. The number of samples is also absurd since samples is long type, but it is printed as PRIu64.

Build test is run on x86-64, x86, aarch64, arm, mips, ppc and ppc64.

Sure?

Quoted 7 lines
Quoted 4 lines

AR /tmp/build/perf/libperf.a
builtin-record.c: In function ‘__cmd_record’:
builtin-record.c:689:12: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]

You missed something important, I am fixing this and applying your patch:

Thanks a lot. Yes, it was wrong, however, my compiler just throws a warning instead of an error. And, the warning was hidden by my OE build environment.

Regards,
Yang

Quoted 15 lines
tools/perf/builtin-record.c +1 -1
index 974065f8ce80..24ace2f318c1 100644
@@ -667,7 +667,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
  	auxtrace_snapshot_enabled = 1;
  	for (;;) {
-		int hits = rec->samples;
+		unsigned long long hits = rec->samples;
 
  		if (record__mmap_read_all(rec) < 0) {
  			auxtrace_snapshot_enabled = 0;
#4 lore raw

[tip:perf/core] perf record: Change 'record.samples' type to unsigned long long

In reply to Yang Shi
perf record: Change 'record.samples' type to unsigned long long
Commit-ID:  9f065194e2a505bb6fd23946b410a0036e9de2ca
Gitweb:     http://git.kernel.org/tip/9f065194e2a505bb6fd23946b410a0036e9de2ca
Author:     Yang Shi <[email protected]>
AuthorDate: Tue, 29 Sep 2015 14:49:43 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 2 Oct 2015 16:11:08 -0300

perf record: Change 'record.samples' type to unsigned long long

When run "perf record -e", the number of samples showed up is wrong on some 32 bit systems, i.e. powerpc and arm.

For example, run the below commands on 32 bit powerpc:

perf probe -x /lib/libc.so.6 malloc
perf record -e probe_libc:malloc -a ls perf.data
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.036 MB perf.data (13829241621624967218 samples) ]

Actually, "perf script" just shows 21 samples. The number of samples is also absurd since samples is long type, but it is printed as PRIu64.

Build test ran on x86-64, x86, aarch64, arm, mips, ppc and ppc64.

[ Bumped the 'hits' var used together with record.samples to 'unsigned long long' too ]
---
 tools/perf/builtin-record.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-record.c +2 -2
index 5e01c07..24ace2f 100644
@@ -49,7 +49,7 @@ struct record {
 	int			realtime_prio;
 	bool			no_buildid;
 	bool			no_buildid_cache;
-	long			samples;
+	unsigned long long	samples;
 };
 
 static int record__write(struct record *rec, void *bf, size_t size)
@@ -667,7 +667,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 
 	auxtrace_snapshot_enabled = 1;
 	for (;;) {
-		int hits = rec->samples;
+		unsigned long long hits = rec->samples;
 
 		if (record__mmap_read_all(rec) < 0) {
 			auxtrace_snapshot_enabled = 0;