perf tools: Fix compilation errors on gcc8
Jiri Olsa
reviewerPATCH 1/2 perf tools: Fix compilation errors on gcc8
We are getting following warnings on gcc8 that break compilation:
$ make
CC jvmti/jvmti_agent.o
jvmti/jvmti_agent.c: In function ‘jvmti_open’:
jvmti/jvmti_agent.c:252:35: error: ‘/jit-’ directive output may be truncated \
writing 5 bytes into a region of size between 1 and 4096 [-Werror=format-truncation=]
snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());There's no point in checking the result of snprintf call in jvmti_open, the following open call will fail in case the name is mangled or too long.
Using tool's function scnprintf that touches the return value from the snprintf calls and thus get rid of those warnings.
$ make DEBUG=1
CC arch/x86/util/perf_regs.o
arch/x86/util/perf_regs.c: In function ‘arch_sdt_arg_parse_op’:
arch/x86/util/perf_regs.c:229:4: error: ‘strncpy’ output truncated before terminating nul
copying 2 bytes from a string of the same length [-Werror=stringop-truncation]
strncpy(prefix, "+0", 2);
^~~~~~~~~~~~~~~~~~~~~~~~Using scnprintf instead of the strncpy (which we know is safe in here) to get rid of that warning.
--- tools/perf/arch/x86/util/perf_regs.c | 2 +- tools/perf/jvmti/jvmti_agent.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/arch/x86/util/perf_regs.c +1 -1
@@ -226,7 +226,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)else if (rm[2 ].rm_so != rm[2 ].rm_eo) prefix[0 ] ='+' ;else -strncpy (prefix,"+0" ,2 ); +scnprintf (prefix,sizeof (prefix),"+0" ); }/* Rename register */
tools/perf/jvmti/jvmti_agent.c +2 -1
@@ -35,6 +35,7 @@#include <sys/mman.h> #include <syscall.h> /* for gettid() */ #include <err.h> +#include <linux/kernel.h> #include "jvmti_agent.h" #include "../util/jitdump.h"
@@ -249,7 +250,7 @@ void *jvmti_open(void)/* * jitdump file name */ -snprintf (dump_path,PATH_MAX ,"%s/jit-%i.dump" , jit_path,getpid ()); +scnprintf (dump_path,PATH_MAX ,"%s/jit-%i.dump" , jit_path,getpid ()); fd =open (dump_path,O_CREAT |O_TRUNC |O_RDWR ,0666 );if (fd ==-1 )
Signature · 1 line
2.17.1
Jiri Olsa
reviewerPATCH 2/2 perf stat: Fix --interval_clear option
Currently we display extra header line, like:
# perf stat -I 1000 -a --interval-clear
# time counts unit events
insn per cycle branch-misses of all branches
2.964917103 3855.349912 cpu-clock (msec) # 3.855 CPUs utilized
2.964917103 23,993 context-switches # 0.006 M/sec
2.964917103 1,301 cpu-migrations # 0.329 K/sec
...Fixing the condition and getting proper:
# perf stat -I 1000 -a --interval-clear
# time counts unit events
2.359048938 1432.492228 cpu-clock (msec) # 1.432 CPUs utilized
2.359048938 7,613 context-switches # 0.002 M/sec
2.359048938 419 cpu-migrations # 0.133 K/sec
...--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -1742,7 +1742,7 @@ static void print_interval(char *prefix, struct timespec *ts) } } -if ((num_print_interval ==0 && metric_only) || interval_clear) +if ((num_print_interval ==0 || interval_clear) && metric_only)print_metric_headers (" " , true);if (++num_print_interval ==25 ) num_print_interval =0 ;
Signature · 1 line
2.17.1
tip-bot for Jiri Olsa
merge bot[tip:perf/urgent] perf stat: Fix --interval_clear option
perf stat: Fix --interval_clear option
Commit-ID: c818cc063089e78bc31845d1eb6a1f0bedee1eae Gitweb: https://git.kernel.org/tip/c818cc063089e78bc31845d1eb6a1f0bedee1eae Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 2 Jul 2018 15:42:02 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 09:43:03 -0400
perf stat: Fix --interval_clear option
Currently we display extra header line, like:
# perf stat -I 1000 -a --interval-clear
# time counts unit events
insn per cycle branch-misses of all branches
2.964917103 3855.349912 cpu-clock (msec) # 3.855 CPUs utilized
2.964917103 23,993 context-switches # 0.006 M/sec
2.964917103 1,301 cpu-migrations # 0.329 K/sec
...Fixing the condition and getting proper:
# perf stat -I 1000 -a --interval-clear
# time counts unit events
2.359048938 1432.492228 cpu-clock (msec) # 1.432 CPUs utilized
2.359048938 7,613 context-switches # 0.002 M/sec
2.359048938 419 cpu-migrations # 0.133 K/sec
...--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -1742,7 +1742,7 @@ static void print_interval(char *prefix, struct timespec *ts) } } -if ((num_print_interval ==0 && metric_only) || interval_clear) +if ((num_print_interval ==0 || interval_clear) && metric_only)print_metric_headers (" " , true);if (++num_print_interval ==25 ) num_print_interval =0 ;
tip-bot for Jiri Olsa
merge botperf tools: Fix compilation errors on gcc8
Commit-ID: a09603f851045b031e990d2d663958ccb49db525 Gitweb: https://git.kernel.org/tip/a09603f851045b031e990d2d663958ccb49db525 Author: Jiri Olsa <[email protected]> AuthorDate: Mon, 2 Jul 2018 15:42:01 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 11 Jul 2018 09:39:57 -0400
perf tools: Fix compilation errors on gcc8
We are getting following warnings on gcc8 that break compilation:
$ make
CC jvmti/jvmti_agent.o
jvmti/jvmti_agent.c: In function ‘jvmti_open’:
jvmti/jvmti_agent.c:252:35: error: ‘/jit-’ directive output may be truncated \
writing 5 bytes into a region of size between 1 and 4096 [-Werror=format-truncation=]
snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());There's no point in checking the result of snprintf call in jvmti_open, the following open call will fail in case the name is mangled or too long.
Using tools/lib/ function scnprintf that touches the return value from the snprintf() calls and thus get rid of those warnings.
$ make DEBUG=1
CC arch/x86/util/perf_regs.o
arch/x86/util/perf_regs.c: In function ‘arch_sdt_arg_parse_op’:
arch/x86/util/perf_regs.c:229:4: error: ‘strncpy’ output truncated before terminating nul
copying 2 bytes from a string of the same length [-Werror=stringop-truncation]
strncpy(prefix, "+0", 2);
^~~~~~~~~~~~~~~~~~~~~~~~Using scnprintf instead of the strncpy (which we know is safe in here) to get rid of that warning.
--- tools/perf/arch/x86/util/perf_regs.c | 2 +- tools/perf/jvmti/jvmti_agent.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
tools/perf/arch/x86/util/perf_regs.c +1 -1
@@ -226,7 +226,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)else if (rm[2 ].rm_so != rm[2 ].rm_eo) prefix[0 ] ='+' ;else -strncpy (prefix,"+0" ,2 ); +scnprintf (prefix,sizeof (prefix),"+0" ); }/* Rename register */
tools/perf/jvmti/jvmti_agent.c +2 -1
@@ -35,6 +35,7 @@#include <sys/mman.h> #include <syscall.h> /* for gettid() */ #include <err.h> +#include <linux/kernel.h> #include "jvmti_agent.h" #include "../util/jitdump.h"
@@ -249,7 +250,7 @@ void *jvmti_open(void)/* * jitdump file name */ -snprintf (dump_path,PATH_MAX ,"%s/jit-%i.dump" , jit_path,getpid ()); +scnprintf (dump_path,PATH_MAX ,"%s/jit-%i.dump" , jit_path,getpid ()); fd =open (dump_path,O_CREAT |O_TRUNC |O_RDWR ,0666 );if (fd ==-1 )