Skip to content

Commit 61d67d5

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes: User visible changes: - Beautify the perf_event_open() syscall in 'perf trace'. (Arnaldo Carvalho de Melo) - Error out unsupported group leader immediately in 'perf stat'. (Kan Liang) - Amend some 'perf record' option summaries (period, etc). (Peter Zijlstra) - Avoid possible race condition in copyfile() in 'perf buildid-cache'. (Milos Vyletel) Infrastructure changes: - Display 0x for hex values when printing the attribute. (Adrian Hunter) - Update MANIFEST per files removed from kernel. (David Ahern) Build fixes: - Fix PRIu64 printf related failure on 32-bit arch. (He Kuang) Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
2 parents 028c63b + c8ad706 commit 61d67d5

File tree

9 files changed

+106
-30
lines changed

9 files changed

+106
-30
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@ OPTIONS
152152

153153
-d::
154154
--data::
155-
Sample addresses.
155+
Record the sample addresses.
156156

157157
-T::
158158
--timestamp::
159-
Sample timestamps. Use it with 'perf report -D' to see the timestamps,
160-
for instance.
159+
Record the sample timestamps. Use it with 'perf report -D' to see the
160+
timestamps, for instance.
161+
162+
-P::
163+
--period::
164+
Record the sample period.
161165

162166
-n::
163167
--no-samples::

tools/perf/MANIFEST

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,20 @@ include/asm-generic/bitops/const_hweight.h
5050
include/asm-generic/bitops/fls64.h
5151
include/asm-generic/bitops/__fls.h
5252
include/asm-generic/bitops/fls.h
53-
include/linux/const.h
5453
include/linux/perf_event.h
5554
include/linux/rbtree.h
5655
include/linux/list.h
5756
include/linux/hash.h
5857
include/linux/stringify.h
59-
lib/find_next_bit.c
6058
lib/hweight.c
6159
lib/rbtree.c
6260
include/linux/swab.h
6361
arch/*/include/asm/unistd*.h
64-
arch/*/include/asm/perf_regs.h
6562
arch/*/include/uapi/asm/unistd*.h
6663
arch/*/include/uapi/asm/perf_regs.h
6764
arch/*/lib/memcpy*.S
6865
arch/*/lib/memset*.S
6966
include/linux/poison.h
70-
include/linux/magic.h
7167
include/linux/hw_breakpoint.h
7268
include/linux/rbtree_augmented.h
7369
include/uapi/linux/perf_event.h

tools/perf/builtin-record.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,10 +1027,9 @@ struct option __record_options[] = {
10271027
OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"),
10281028
OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat,
10291029
"per thread counts"),
1030-
OPT_BOOLEAN('d', "data", &record.opts.sample_address,
1031-
"Sample addresses"),
1032-
OPT_BOOLEAN('T', "timestamp", &record.opts.sample_time, "Sample timestamps"),
1033-
OPT_BOOLEAN('P', "period", &record.opts.period, "Sample period"),
1030+
OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),
1031+
OPT_BOOLEAN('T', "timestamp", &record.opts.sample_time, "Record the sample timestamps"),
1032+
OPT_BOOLEAN('P', "period", &record.opts.period, "Record the sample period"),
10341033
OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples,
10351034
"don't sample"),
10361035
OPT_BOOLEAN('N', "no-buildid-cache", &record.no_buildid_cache,

tools/perf/builtin-report.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
320320
{
321321
struct perf_evsel *pos;
322322

323-
fprintf(stdout, "#\n# Total Lost Samples: %lu\n#\n", evlist->stats.total_lost_samples);
323+
fprintf(stdout, "#\n# Total Lost Samples: %" PRIu64 "\n#\n", evlist->stats.total_lost_samples);
324324
evlist__for_each(evlist, pos) {
325325
struct hists *hists = evsel__hists(pos);
326326
const char *evname = perf_evsel__name(pos);

tools/perf/builtin-stat.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,10 @@ static int __run_perf_stat(int argc, const char **argv)
549549
ui__warning("%s event is not supported by the kernel.\n",
550550
perf_evsel__name(counter));
551551
counter->supported = false;
552-
continue;
552+
553+
if ((counter->leader != counter) ||
554+
!(counter->leader->nr_members > 1))
555+
continue;
553556
}
554557

555558
perf_evsel__open_strerror(counter, &target,

tools/perf/builtin-trace.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@
6868
# define MSG_CMSG_CLOEXEC 0x40000000
6969
#endif
7070

71+
#ifndef PERF_FLAG_FD_NO_GROUP
72+
# define PERF_FLAG_FD_NO_GROUP (1UL << 0)
73+
#endif
74+
75+
#ifndef PERF_FLAG_FD_OUTPUT
76+
# define PERF_FLAG_FD_OUTPUT (1UL << 1)
77+
#endif
78+
79+
#ifndef PERF_FLAG_PID_CGROUP
80+
# define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup id, per-cpu mode only */
81+
#endif
82+
83+
#ifndef PERF_FLAG_FD_CLOEXEC
84+
# define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */
85+
#endif
86+
87+
7188
struct tp_field {
7289
int offset;
7390
union {
@@ -358,6 +375,14 @@ static size_t syscall_arg__scnprintf_hex(char *bf, size_t size,
358375

359376
#define SCA_HEX syscall_arg__scnprintf_hex
360377

378+
static size_t syscall_arg__scnprintf_int(char *bf, size_t size,
379+
struct syscall_arg *arg)
380+
{
381+
return scnprintf(bf, size, "%d", arg->val);
382+
}
383+
384+
#define SCA_INT syscall_arg__scnprintf_int
385+
361386
static size_t syscall_arg__scnprintf_mmap_prot(char *bf, size_t size,
362387
struct syscall_arg *arg)
363388
{
@@ -810,6 +835,34 @@ static size_t syscall_arg__scnprintf_open_flags(char *bf, size_t size,
810835

811836
#define SCA_OPEN_FLAGS syscall_arg__scnprintf_open_flags
812837

838+
static size_t syscall_arg__scnprintf_perf_flags(char *bf, size_t size,
839+
struct syscall_arg *arg)
840+
{
841+
int printed = 0, flags = arg->val;
842+
843+
if (flags == 0)
844+
return 0;
845+
846+
#define P_FLAG(n) \
847+
if (flags & PERF_FLAG_##n) { \
848+
printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
849+
flags &= ~PERF_FLAG_##n; \
850+
}
851+
852+
P_FLAG(FD_NO_GROUP);
853+
P_FLAG(FD_OUTPUT);
854+
P_FLAG(PID_CGROUP);
855+
P_FLAG(FD_CLOEXEC);
856+
#undef P_FLAG
857+
858+
if (flags)
859+
printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
860+
861+
return printed;
862+
}
863+
864+
#define SCA_PERF_FLAGS syscall_arg__scnprintf_perf_flags
865+
813866
static size_t syscall_arg__scnprintf_eventfd_flags(char *bf, size_t size,
814867
struct syscall_arg *arg)
815868
{
@@ -1077,6 +1130,11 @@ static struct syscall_fmt {
10771130
{ .name = "openat", .errmsg = true,
10781131
.arg_scnprintf = { [0] = SCA_FDAT, /* dfd */
10791132
[2] = SCA_OPEN_FLAGS, /* flags */ }, },
1133+
{ .name = "perf_event_open", .errmsg = true,
1134+
.arg_scnprintf = { [1] = SCA_INT, /* pid */
1135+
[2] = SCA_INT, /* cpu */
1136+
[3] = SCA_FD, /* group_fd */
1137+
[4] = SCA_PERF_FLAGS, /* flags */ }, },
10801138
{ .name = "pipe2", .errmsg = true,
10811139
.arg_scnprintf = { [1] = SCA_PIPE_FLAGS, /* flags */ }, },
10821140
{ .name = "poll", .errmsg = true, .timeout = true, },

tools/perf/util/evsel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ static void __p_read_format(char *buf, size_t size, u64 value)
10581058

10591059
#define BUF_SIZE 1024
10601060

1061-
#define p_hex(val) snprintf(buf, BUF_SIZE, "%"PRIx64, (uint64_t)(val))
1061+
#define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val))
10621062
#define p_unsigned(val) snprintf(buf, BUF_SIZE, "%"PRIu64, (uint64_t)(val))
10631063
#define p_signed(val) snprintf(buf, BUF_SIZE, "%"PRId64, (int64_t)(val))
10641064
#define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val)

tools/perf/util/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ static void perf_session__warn_about_errors(const struct perf_session *session)
12991299
drop_rate = (double)stats->total_lost_samples /
13001300
(double) (stats->nr_events[PERF_RECORD_SAMPLE] + stats->total_lost_samples);
13011301
if (drop_rate > 0.05) {
1302-
ui__warning("Processed %lu samples and lost %3.2f%% samples!\n\n",
1302+
ui__warning("Processed %" PRIu64 " samples and lost %3.2f%% samples!\n\n",
13031303
stats->nr_events[PERF_RECORD_SAMPLE] + stats->total_lost_samples,
13041304
drop_rate * 100.0);
13051305
}

tools/perf/util/util.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,17 @@ int rm_rf(char *path)
115115
return rmdir(path);
116116
}
117117

118-
static int slow_copyfile(const char *from, const char *to, mode_t mode)
118+
static int slow_copyfile(const char *from, const char *to)
119119
{
120120
int err = -1;
121121
char *line = NULL;
122122
size_t n;
123123
FILE *from_fp = fopen(from, "r"), *to_fp;
124-
mode_t old_umask;
125124

126125
if (from_fp == NULL)
127126
goto out;
128127

129-
old_umask = umask(mode ^ 0777);
130128
to_fp = fopen(to, "w");
131-
umask(old_umask);
132129
if (to_fp == NULL)
133130
goto out_fclose_from;
134131

@@ -178,29 +175,48 @@ int copyfile_mode(const char *from, const char *to, mode_t mode)
178175
int fromfd, tofd;
179176
struct stat st;
180177
int err = -1;
178+
char *tmp = NULL, *ptr = NULL;
181179

182180
if (stat(from, &st))
183181
goto out;
184182

185-
if (st.st_size == 0) /* /proc? do it slowly... */
186-
return slow_copyfile(from, to, mode);
187-
188-
fromfd = open(from, O_RDONLY);
189-
if (fromfd < 0)
183+
/* extra 'x' at the end is to reserve space for '.' */
184+
if (asprintf(&tmp, "%s.XXXXXXx", to) < 0) {
185+
tmp = NULL;
190186
goto out;
187+
}
188+
ptr = strrchr(tmp, '/');
189+
if (!ptr)
190+
goto out;
191+
ptr = memmove(ptr + 1, ptr, strlen(ptr) - 1);
192+
*ptr = '.';
191193

192-
tofd = creat(to, mode);
194+
tofd = mkstemp(tmp);
193195
if (tofd < 0)
194-
goto out_close_from;
196+
goto out;
197+
198+
if (fchmod(tofd, mode))
199+
goto out_close_to;
200+
201+
if (st.st_size == 0) { /* /proc? do it slowly... */
202+
err = slow_copyfile(from, tmp);
203+
goto out_close_to;
204+
}
205+
206+
fromfd = open(from, O_RDONLY);
207+
if (fromfd < 0)
208+
goto out_close_to;
195209

196210
err = copyfile_offset(fromfd, 0, tofd, 0, st.st_size);
197211

198-
close(tofd);
199-
if (err)
200-
unlink(to);
201-
out_close_from:
202212
close(fromfd);
213+
out_close_to:
214+
close(tofd);
215+
if (!err)
216+
err = link(tmp, to);
217+
unlink(tmp);
203218
out:
219+
free(tmp);
204220
return err;
205221
}
206222

0 commit comments

Comments
 (0)