]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
perf script: Fix --reltime with --time
authorAndi Kleen <ak@linux.intel.com>
Fri, 11 Oct 2019 18:21:39 +0000 (11:21 -0700)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 14 Feb 2020 06:00:53 +0000 (01:00 -0500)
BugLink: https://bugs.launchpad.net/bugs/1862429
[ Upstream commit b3509b6ed7a79ec49f6b64e4f3b780f259a2a468 ]

My earlier patch to just enable --reltime with --time was a little too
optimistic.  The --time parsing would accept absolute time, which is
very confusing to the user.

Support relative time in --time parsing too. This only works with recent
perf record that records the first sample time. Otherwise we error out.

Fixes: 3714437d3fcc ("perf script: Allow --time with --reltime")
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20191011182140.8353-1-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
tools/perf/builtin-script.c
tools/perf/util/time-utils.c
tools/perf/util/time-utils.h

index 5c3975cd4a04854a70e60d3f761fba9bebffe6b6..ceeb057a7f74daad6759175b318ea102003ea0f9 100644 (file)
@@ -3848,10 +3848,11 @@ int cmd_script(int argc, const char **argv)
                goto out_delete;
 
        if (script.time_str) {
-               err = perf_time__parse_for_ranges(script.time_str, session,
+               err = perf_time__parse_for_ranges_reltime(script.time_str, session,
                                                  &script.ptime_range,
                                                  &script.range_size,
-                                                 &script.range_num);
+                                                 &script.range_num,
+                                                 reltime);
                if (err < 0)
                        goto out_delete;
 
index c2abc259b51dc331c4bc673e57614d88f2975347..d7c93e939d81b2916e8e5bdf2e4c38594932471a 100644 (file)
@@ -459,10 +459,11 @@ bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
        return true;
 }
 
-int perf_time__parse_for_ranges(const char *time_str,
+int perf_time__parse_for_ranges_reltime(const char *time_str,
                                struct perf_session *session,
                                struct perf_time_interval **ranges,
-                               int *range_size, int *range_num)
+                               int *range_size, int *range_num,
+                               bool reltime)
 {
        bool has_percent = strchr(time_str, '%');
        struct perf_time_interval *ptime_range;
@@ -472,7 +473,7 @@ int perf_time__parse_for_ranges(const char *time_str,
        if (!ptime_range)
                return -ENOMEM;
 
-       if (has_percent) {
+       if (has_percent || reltime) {
                if (session->evlist->first_sample_time == 0 &&
                    session->evlist->last_sample_time == 0) {
                        pr_err("HINT: no first/last sample time found in perf data.\n"
@@ -480,7 +481,9 @@ int perf_time__parse_for_ranges(const char *time_str,
                               "(if '--buildid-all' is enabled, please set '--timestamp-boundary').\n");
                        goto error;
                }
+       }
 
+       if (has_percent) {
                num = perf_time__percent_parse_str(
                                ptime_range, size,
                                time_str,
@@ -493,6 +496,15 @@ int perf_time__parse_for_ranges(const char *time_str,
        if (num < 0)
                goto error_invalid;
 
+       if (reltime) {
+               int i;
+
+               for (i = 0; i < num; i++) {
+                       ptime_range[i].start += session->evlist->first_sample_time;
+                       ptime_range[i].end += session->evlist->first_sample_time;
+               }
+       }
+
        *range_size = size;
        *range_num = num;
        *ranges = ptime_range;
@@ -505,6 +517,15 @@ error:
        return ret;
 }
 
+int perf_time__parse_for_ranges(const char *time_str,
+                               struct perf_session *session,
+                               struct perf_time_interval **ranges,
+                               int *range_size, int *range_num)
+{
+       return perf_time__parse_for_ranges_reltime(time_str, session, ranges,
+                                       range_size, range_num, false);
+}
+
 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz)
 {
        u64  sec = timestamp / NSEC_PER_SEC;
index 72a42ea1d513af55f54896da02ce66bc6d037a82..e07b698172f54f5df8551f3d2c9779e17b648cd0 100644 (file)
@@ -25,6 +25,11 @@ bool perf_time__ranges_skip_sample(struct perf_time_interval *ptime_buf,
 
 struct perf_session;
 
+int perf_time__parse_for_ranges_reltime(const char *str, struct perf_session *session,
+                               struct perf_time_interval **ranges,
+                               int *range_size, int *range_num,
+                               bool reltime);
+
 int perf_time__parse_for_ranges(const char *str, struct perf_session *session,
                                struct perf_time_interval **ranges,
                                int *range_size, int *range_num);