]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
perf record: Fix period option handling
authorJiri Olsa <jolsa@kernel.org>
Thu, 1 Feb 2018 08:38:11 +0000 (09:38 +0100)
committerKhalid Elmously <khalid.elmously@canonical.com>
Wed, 6 Jun 2018 17:44:25 +0000 (13:44 -0400)
BugLink: http://bugs.launchpad.net/bugs/1774063
[ Upstream commit f290aa1ffa45ed7e37599840878b4dae68269ee1 ]

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 <eranian@google.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Stephane Eranian <eranian@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180201083812.11359-3-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
tools/perf/builtin-record.c
tools/perf/perf.h
tools/perf/util/evsel.c

index 36b6213884b5a5c3ffdd4b11c13c91377606946a..5c016e534e4a35ecad923c1f59921ba329ee1de3 100644 (file)
@@ -1533,7 +1533,8 @@ static struct option __record_options[] = {
        OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time,
                        &record.opts.sample_time_set,
                        "Record the sample timestamps"),
-       OPT_BOOLEAN('P', "period", &record.opts.period, "Record the sample period"),
+       OPT_BOOLEAN_SET('P', "period", &record.opts.period, &record.opts.period_set,
+                       "Record the sample period"),
        OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples,
                    "don't sample"),
        OPT_BOOLEAN_SET('N', "no-buildid-cache", &record.no_buildid_cache,
index 2357f4ccc9c79d22d4f9d3ad152a2ec2e63482fe..cfe46236a5e5b7d641523e3eb25a3d0acc11eaa4 100644 (file)
@@ -50,6 +50,7 @@ struct record_opts {
        bool         sample_time_set;
        bool         sample_cpu;
        bool         period;
+       bool         period_set;
        bool         running_time;
        bool         full_auxtrace;
        bool         auxtrace_snapshot_mode;
index 37ee1aebbf8a41fafe5fea0d4e7a066d384abc12..3f78f00579e4936823ed34865f80d5a4e1ab9a7b 100644 (file)
@@ -949,9 +949,6 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
        if (target__has_cpu(&opts->target) || opts->sample_cpu)
                perf_evsel__set_sample_bit(evsel, CPU);
 
-       if (opts->period)
-               perf_evsel__set_sample_bit(evsel, PERIOD);
-
        /*
         * When the user explicitly disabled time don't force it here.
         */
@@ -1053,6 +1050,14 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
        apply_config_terms(evsel, opts);
 
        evsel->ignore_missing_thread = opts->ignore_missing_thread;
+
+       /* The --period option takes the precedence. */
+       if (opts->period_set) {
+               if (opts->period)
+                       perf_evsel__set_sample_bit(evsel, PERIOD);
+               else
+                       perf_evsel__reset_sample_bit(evsel, PERIOD);
+       }
 }
 
 static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)