Skip to content

Commit aa0a324

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf tool fixes from Ingo Molnar: "Misc tooling fixes: python3 related fixes, gcc8 fix, bashism fixes and some other smaller fixes" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf tools: Use python-config --includes rather than --cflags perf script python: Fix dict reference counting perf stat: Fix --interval_clear option perf tools: Fix compilation errors on gcc8 perf test shell: Prevent temporary editor files from being considered test scripts perf llvm-utils: Remove bashism from kernel include fetch script perf test shell: Make perf's inet_pton test more portable perf test shell: Replace '|&' with '2>&1 |' to work with more shells perf scripts python: Add Python 3 support to EventClass.py perf scripts python: Add Python 3 support to sched-migration.py perf scripts python: Add Python 3 support to Util.py perf scripts python: Add Python 3 support to SchedGui.py perf scripts python: Add Python 3 support to Core.py perf tools: Generate a Python script compatible with Python 2 and 3
2 parents 75adbd1 + 6e1d33b commit aa0a324

File tree

14 files changed

+84
-81
lines changed

14 files changed

+84
-81
lines changed

tools/perf/Makefile.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ ifdef PYTHON_CONFIG
207207
PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
208208
PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
209209
PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
210-
PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
211-
PYTHON_EMBED_CCOPTS := $(filter-out -specs=%,$(PYTHON_EMBED_CCOPTS))
210+
PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
212211
FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
213212
endif
214213

tools/perf/arch/x86/util/perf_regs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
226226
else if (rm[2].rm_so != rm[2].rm_eo)
227227
prefix[0] = '+';
228228
else
229-
strncpy(prefix, "+0", 2);
229+
scnprintf(prefix, sizeof(prefix), "+0");
230230
}
231231

232232
/* Rename register */

tools/perf/builtin-stat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ static void print_interval(char *prefix, struct timespec *ts)
17421742
}
17431743
}
17441744

1745-
if ((num_print_interval == 0 && metric_only) || interval_clear)
1745+
if ((num_print_interval == 0 || interval_clear) && metric_only)
17461746
print_metric_headers(" ", true);
17471747
if (++num_print_interval == 25)
17481748
num_print_interval = 0;

tools/perf/jvmti/jvmti_agent.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <sys/mman.h>
3636
#include <syscall.h> /* for gettid() */
3737
#include <err.h>
38+
#include <linux/kernel.h>
3839

3940
#include "jvmti_agent.h"
4041
#include "../util/jitdump.h"
@@ -249,7 +250,7 @@ void *jvmti_open(void)
249250
/*
250251
* jitdump file name
251252
*/
252-
snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
253+
scnprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
253254

254255
fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666);
255256
if (fd == -1)

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ def flag_str(event_name, field_name, value):
3131
string = ""
3232

3333
if flag_fields[event_name][field_name]:
34-
print_delim = 0
35-
keys = flag_fields[event_name][field_name]['values'].keys()
36-
keys.sort()
37-
for idx in keys:
34+
print_delim = 0
35+
for idx in sorted(flag_fields[event_name][field_name]['values']):
3836
if not value and not idx:
3937
string += flag_fields[event_name][field_name]['values'][idx]
4038
break
@@ -51,14 +49,12 @@ def symbol_str(event_name, field_name, value):
5149
string = ""
5250

5351
if symbolic_fields[event_name][field_name]:
54-
keys = symbolic_fields[event_name][field_name]['values'].keys()
55-
keys.sort()
56-
for idx in keys:
52+
for idx in sorted(symbolic_fields[event_name][field_name]['values']):
5753
if not value and not idx:
58-
string = symbolic_fields[event_name][field_name]['values'][idx]
54+
string = symbolic_fields[event_name][field_name]['values'][idx]
5955
break
60-
if (value == idx):
61-
string = symbolic_fields[event_name][field_name]['values'][idx]
56+
if (value == idx):
57+
string = symbolic_fields[event_name][field_name]['values'][idx]
6258
break
6359

6460
return string
@@ -74,19 +70,17 @@ def trace_flag_str(value):
7470
string = ""
7571
print_delim = 0
7672

77-
keys = trace_flags.keys()
78-
79-
for idx in keys:
80-
if not value and not idx:
81-
string += "NONE"
82-
break
83-
84-
if idx and (value & idx) == idx:
85-
if print_delim:
86-
string += " | ";
87-
string += trace_flags[idx]
88-
print_delim = 1
89-
value &= ~idx
73+
for idx in trace_flags:
74+
if not value and not idx:
75+
string += "NONE"
76+
break
77+
78+
if idx and (value & idx) == idx:
79+
if print_delim:
80+
string += " | ";
81+
string += trace_flags[idx]
82+
print_delim = 1
83+
value &= ~idx
9084

9185
return string
9286

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# PerfEvent is the base class for all perf event sample, PebsEvent
99
# is a HW base Intel x86 PEBS event, and user could add more SW/HW
1010
# event classes based on requirements.
11+
from __future__ import print_function
1112

1213
import struct
1314

@@ -44,7 +45,8 @@ def __init__(self, name, comm, dso, symbol, raw_buf, ev_type=EVTYPE_GENERIC):
4445
PerfEvent.event_num += 1
4546

4647
def show(self):
47-
print "PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % (self.name, self.symbol, self.comm, self.dso)
48+
print("PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" %
49+
(self.name, self.symbol, self.comm, self.dso))
4850

4951
#
5052
# Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
try:
1212
import wx
1313
except ImportError:
14-
raise ImportError, "You need to install the wxpython lib for this script"
14+
raise ImportError("You need to install the wxpython lib for this script")
1515

1616

1717
class RootFrame(wx.Frame):

tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# This software may be distributed under the terms of the GNU General
66
# Public License ("GPL") version 2 as published by the Free Software
77
# Foundation.
8+
from __future__ import print_function
89

910
import errno, os
1011

@@ -33,7 +34,7 @@ def nsecs_str(nsecs):
3334
return str
3435

3536
def add_stats(dict, key, value):
36-
if not dict.has_key(key):
37+
if key not in dict:
3738
dict[key] = (value, value, value, 1)
3839
else:
3940
min, max, avg, count = dict[key]
@@ -72,10 +73,10 @@ def clear_term():
7273
except:
7374
if not audit_package_warned:
7475
audit_package_warned = True
75-
print "Install the audit-libs-python package to get syscall names.\n" \
76-
"For example:\n # apt-get install python-audit (Ubuntu)" \
77-
"\n # yum install audit-libs-python (Fedora)" \
78-
"\n etc.\n"
76+
print("Install the audit-libs-python package to get syscall names.\n"
77+
"For example:\n # apt-get install python-audit (Ubuntu)"
78+
"\n # yum install audit-libs-python (Fedora)"
79+
"\n etc.\n")
7980

8081
def syscall_name(id):
8182
try:

tools/perf/scripts/python/sched-migration.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
# This software is distributed under the terms of the GNU General
1010
# Public License ("GPL") version 2 as published by the Free Software
1111
# Foundation.
12-
12+
from __future__ import print_function
1313

1414
import os
1515
import sys
1616

1717
from collections import defaultdict
18-
from UserList import UserList
18+
try:
19+
from UserList import UserList
20+
except ImportError:
21+
# Python 3: UserList moved to the collections package
22+
from collections import UserList
1923

2024
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
2125
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
@@ -300,7 +304,7 @@ def fill_zone(self, start, end):
300304
if i == -1:
301305
return
302306

303-
for i in xrange(i, len(self.data)):
307+
for i in range(i, len(self.data)):
304308
timeslice = self.data[i]
305309
if timeslice.start > end:
306310
return
@@ -336,8 +340,8 @@ def sched_switch(self, headers, prev_comm, prev_pid, prev_prio, prev_state,
336340
on_cpu_task = self.current_tsk[headers.cpu]
337341

338342
if on_cpu_task != -1 and on_cpu_task != prev_pid:
339-
print "Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \
340-
(headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid)
343+
print("Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \
344+
headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid)
341345

342346
threads[prev_pid] = prev_comm
343347
threads[next_pid] = next_comm

tools/perf/tests/builtin-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static const char *shell_test__description(char *description, size_t size,
422422

423423
#define for_each_shell_test(dir, base, ent) \
424424
while ((ent = readdir(dir)) != NULL) \
425-
if (!is_directory(base, ent))
425+
if (!is_directory(base, ent) && ent->d_name[0] != '.')
426426

427427
static const char *shell_tests__dir(char *path, size_t size)
428428
{

tools/perf/tests/shell/record+probe_libc_inet_pton.sh

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,40 @@ libc=$(grep -w libc /proc/self/maps | head -1 | sed -r 's/.*[[:space:]](\/.*)/\1
1414
nm -Dg $libc 2>/dev/null | fgrep -q inet_pton || exit 254
1515

1616
trace_libc_inet_pton_backtrace() {
17-
idx=0
18-
expected[0]="ping[][0-9 \.:]+probe_libc:inet_pton: \([[:xdigit:]]+\)"
19-
expected[1]=".*inet_pton\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$"
17+
18+
expected=`mktemp -u /tmp/expected.XXX`
19+
20+
echo "ping[][0-9 \.:]+probe_libc:inet_pton: \([[:xdigit:]]+\)" > $expected
21+
echo ".*inet_pton\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
2022
case "$(uname -m)" in
2123
s390x)
2224
eventattr='call-graph=dwarf,max-stack=4'
23-
expected[2]="gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$"
24-
expected[3]="(__GI_)?getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$"
25-
expected[4]="main\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$"
25+
echo "gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
26+
echo "(__GI_)?getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
27+
echo "main\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" >> $expected
2628
;;
2729
*)
2830
eventattr='max-stack=3'
29-
expected[2]="getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$"
30-
expected[3]=".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$"
31+
echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
32+
echo ".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" >> $expected
3133
;;
3234
esac
3335

34-
file=`mktemp -u /tmp/perf.data.XXX`
36+
perf_data=`mktemp -u /tmp/perf.data.XXX`
37+
perf_script=`mktemp -u /tmp/perf.script.XXX`
38+
perf record -e probe_libc:inet_pton/$eventattr/ -o $perf_data ping -6 -c 1 ::1 > /dev/null 2>&1
39+
perf script -i $perf_data > $perf_script
3540

36-
perf record -e probe_libc:inet_pton/$eventattr/ -o $file ping -6 -c 1 ::1 > /dev/null 2>&1
37-
perf script -i $file | while read line ; do
41+
exec 3<$perf_script
42+
exec 4<$expected
43+
while read line <&3 && read -r pattern <&4; do
44+
[ -z "$pattern" ] && break
3845
echo $line
39-
echo "$line" | egrep -q "${expected[$idx]}"
46+
echo "$line" | egrep -q "$pattern"
4047
if [ $? -ne 0 ] ; then
41-
printf "FAIL: expected backtrace entry %d \"%s\" got \"%s\"\n" $idx "${expected[$idx]}" "$line"
48+
printf "FAIL: expected backtrace entry \"%s\" got \"%s\"\n" "$pattern" "$line"
4249
exit 1
4350
fi
44-
let idx+=1
45-
[ -z "${expected[$idx]}" ] && break
4651
done
4752

4853
# If any statements are executed from this point onwards,
@@ -58,6 +63,6 @@ skip_if_no_perf_probe && \
5863
perf probe -q $libc inet_pton && \
5964
trace_libc_inet_pton_backtrace
6065
err=$?
61-
rm -f ${file}
66+
rm -f ${perf_data} ${perf_script} ${expected}
6267
perf probe -q -d probe_libc:inet_pton
6368
exit $err

tools/perf/tests/shell/trace+probe_vfs_getname.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ skip_if_no_perf_probe || exit 2
1717
file=$(mktemp /tmp/temporary_file.XXXXX)
1818

1919
trace_open_vfs_getname() {
20-
evts=$(echo $(perf list syscalls:sys_enter_open* |& egrep 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/')
20+
evts=$(echo $(perf list syscalls:sys_enter_open* 2>&1 | egrep 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/')
2121
perf trace -e $evts touch $file 2>&1 | \
2222
egrep " +[0-9]+\.[0-9]+ +\( +[0-9]+\.[0-9]+ ms\): +touch\/[0-9]+ open(at)?\((dfd: +CWD, +)?filename: +${file}, +flags: CREAT\|NOCTTY\|NONBLOCK\|WRONLY, +mode: +IRUGO\|IWUGO\) += +[0-9]+$"
2323
}

tools/perf/util/llvm-utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,16 @@ static const char *kinc_fetch_script =
266266
"#!/usr/bin/env sh\n"
267267
"if ! test -d \"$KBUILD_DIR\"\n"
268268
"then\n"
269-
" exit -1\n"
269+
" exit 1\n"
270270
"fi\n"
271271
"if ! test -f \"$KBUILD_DIR/include/generated/autoconf.h\"\n"
272272
"then\n"
273-
" exit -1\n"
273+
" exit 1\n"
274274
"fi\n"
275275
"TMPDIR=`mktemp -d`\n"
276276
"if test -z \"$TMPDIR\"\n"
277277
"then\n"
278-
" exit -1\n"
278+
" exit 1\n"
279279
"fi\n"
280280
"cat << EOF > $TMPDIR/Makefile\n"
281281
"obj-y := dummy.o\n"

0 commit comments

Comments
 (0)