Skip to content

Commit f290aa1

Browse files
olsajiriacmel
authored andcommitted
perf record: Fix period option handling
Stephan reported we don't unset PERIOD sample type when --no-period is specified. Adding the unset check and reset PERIOD if --no-period is specified. Committer notes: Check the sample_type, it shouldn't have PERF_SAMPLE_PERIOD there when --no-period is used. Before: # perf record --no-period sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.018 MB perf.data (7 samples) ] # perf evlist -v cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|PERIOD, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 # After: [root@jouet ~]# perf record --no-period sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.019 MB perf.data (17 samples) ] [root@jouet ~]# perf evlist -v cycles:ppp: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1, task: 1, precise_ip: 3, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1 [root@jouet ~]# Reported-by: Stephane Eranian <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Tested-by: Stephane Eranian <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: David Ahern <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 49c0ae8 commit f290aa1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

tools/perf/builtin-record.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,8 @@ static struct option __record_options[] = {
15661566
OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
15671567
&record.opts.sample_time_set,
15681568
"Record the sample timestamps"),
1569-
OPT_BOOLEAN('P', "period", &record.opts.period, "Record the sample period"),
1569+
OPT_BOOLEAN_SET('P', "period", &record.opts.period, &record.opts.period_set,
1570+
"Record the sample period"),
15701571
OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples,
15711572
"don't sample"),
15721573
OPT_BOOLEAN_SET('N', "no-buildid-cache", &record.no_buildid_cache,

tools/perf/perf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct record_opts {
5050
bool sample_time_set;
5151
bool sample_cpu;
5252
bool period;
53+
bool period_set;
5354
bool running_time;
5455
bool full_auxtrace;
5556
bool auxtrace_snapshot_mode;

tools/perf/util/evsel.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,6 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
971971
if (target__has_cpu(&opts->target) || opts->sample_cpu)
972972
perf_evsel__set_sample_bit(evsel, CPU);
973973

974-
if (opts->period)
975-
perf_evsel__set_sample_bit(evsel, PERIOD);
976-
977974
/*
978975
* When the user explicitly disabled time don't force it here.
979976
*/
@@ -1075,6 +1072,14 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
10751072
apply_config_terms(evsel, opts, track);
10761073

10771074
evsel->ignore_missing_thread = opts->ignore_missing_thread;
1075+
1076+
/* The --period option takes the precedence. */
1077+
if (opts->period_set) {
1078+
if (opts->period)
1079+
perf_evsel__set_sample_bit(evsel, PERIOD);
1080+
else
1081+
perf_evsel__reset_sample_bit(evsel, PERIOD);
1082+
}
10781083
}
10791084

10801085
static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)

0 commit comments

Comments
 (0)