Skip to content

Commit baa2f6c

Browse files
committed
perf record: Add option to disable collecting build-ids
Collecting build-ids for long running sessions may take a long time because it needs to traverse the whole just collected perf.data stream of events, marking the DSOs that had hits and then looking for the .note.gnu.build-id ELF section. For things like the 'trace' tool that records and right away consumes the data on systems where its unlikely that the DSOs being monitored will change while 'trace' runs, it is desirable to remove build id collection, so add a -B/--no-buildid option to perf record to allow such use case. Longer term we'll avoid all this if we, at DSO load time, in the kernel, take advantage of this slow code path to collect the build-id and stash it somewhere, so that we can insert it in the PERF_RECORD_MMAP event. Reported-by: Thomas Gleixner <tglx@linutronix.de> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent af86da5 commit baa2f6c

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎tools/perf/builtin-record.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static bool inherit_stat = false;
6161
static bool no_samples = false;
6262
static bool sample_address = false;
6363
static bool no_buildid = false;
64+
static bool no_buildid_cache = false;
6465

6566
static long samples = 0;
6667
static u64 bytes_written = 0;
@@ -437,7 +438,8 @@ static void atexit_header(void)
437438
if (!pipe_output) {
438439
session->header.data_size += bytes_written;
439440

440-
process_buildids();
441+
if (!no_buildid)
442+
process_buildids();
441443
perf_header__write(&session->header, output, true);
442444
perf_session__delete(session);
443445
symbol__exit();
@@ -557,6 +559,9 @@ static int __cmd_record(int argc, const char **argv)
557559
return -1;
558560
}
559561

562+
if (!no_buildid)
563+
perf_header__set_feat(&session->header, HEADER_BUILD_ID);
564+
560565
if (!file_new) {
561566
err = perf_header__read(session, output);
562567
if (err < 0)
@@ -831,8 +836,10 @@ const struct option record_options[] = {
831836
"Sample addresses"),
832837
OPT_BOOLEAN('n', "no-samples", &no_samples,
833838
"don't sample"),
834-
OPT_BOOLEAN('N', "no-buildid-cache", &no_buildid,
839+
OPT_BOOLEAN('N', "no-buildid-cache", &no_buildid_cache,
835840
"do not update the buildid cache"),
841+
OPT_BOOLEAN('B', "no-buildid", &no_buildid,
842+
"do not collect buildids in perf.data"),
836843
OPT_END()
837844
};
838845

@@ -857,7 +864,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
857864
}
858865

859866
symbol__init();
860-
if (no_buildid)
867+
868+
if (no_buildid_cache || no_buildid)
861869
disable_buildid_cache();
862870

863871
if (!nr_counters) {

‎tools/perf/util/header.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ void perf_header__set_feat(struct perf_header *self, int feat)
152152
set_bit(feat, self->adds_features);
153153
}
154154

155+
void perf_header__clear_feat(struct perf_header *self, int feat)
156+
{
157+
clear_bit(feat, self->adds_features);
158+
}
159+
155160
bool perf_header__has_feat(const struct perf_header *self, int feat)
156161
{
157162
return test_bit(feat, self->adds_features);
@@ -431,8 +436,10 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
431436
int idx = 0, err;
432437

433438
session = container_of(self, struct perf_session, header);
434-
if (perf_session__read_build_ids(session, true))
435-
perf_header__set_feat(self, HEADER_BUILD_ID);
439+
440+
if (perf_header__has_feat(self, HEADER_BUILD_ID &&
441+
!perf_session__read_build_ids(session, true)))
442+
perf_header__clear_feat(self, HEADER_BUILD_ID);
436443

437444
nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
438445
if (!nr_sections)

‎tools/perf/util/header.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ u64 perf_header__sample_type(struct perf_header *header);
8484
struct perf_event_attr *
8585
perf_header__find_attr(u64 id, struct perf_header *header);
8686
void perf_header__set_feat(struct perf_header *self, int feat);
87+
void perf_header__clear_feat(struct perf_header *self, int feat);
8788
bool perf_header__has_feat(const struct perf_header *self, int feat);
8889

8990
int perf_header__process_sections(struct perf_header *self, int fd,

‎tools/perf/util/include/linux/bitops.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ static inline void set_bit(int nr, unsigned long *addr)
1313
addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
1414
}
1515

16+
static inline void clear_bit(int nr, unsigned long *addr)
17+
{
18+
addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
19+
}
20+
1621
static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
1722
{
1823
return ((1UL << (nr % BITS_PER_LONG)) &

0 commit comments

Comments
 (0)