Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4922229ybg; Mon, 21 Oct 2019 17:08:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIBuwmXC1i1hNnHtTkp1J3k9cly+nIlPBAZEqqFelV76vLojqw+c0An1KI5c4/Q+qG64Im X-Received: by 2002:a50:ab10:: with SMTP id s16mr27730071edc.118.1571702888899; Mon, 21 Oct 2019 17:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571702888; cv=none; d=google.com; s=arc-20160816; b=nIGE0jzWWhGkMOFmytHfiCaXfUDeXqGK8KJgTZf4xuO2d87LTe/V4EXHY9dG7yB844 9t3/YXBd1eECD7eBqkfCOfEHbyWFegk2KX4TQF6+ilSMcvXjCZRKgoRw6W0nHXNfYT1+ NLF0YZn7ktukxxtQFlac2uPvY9byHNEfntspZyEp9SaOMueaM7ZTif+OoTfgLQSgCa5R HEse0UYDAdZZgSN9U+ClLCS3ZbnFZyZM1R2SxS6gKaDLs2iacPy3l2PN+tFbJQyw9Wwe L5UDkTKW7BIkkMtqztgCtwWcq99G7LonlrbQ/OITe8TFXPUDat6WEDy6a092q6efpJuh c9Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=p8JTPufQOBN5uosP6bCGuhJ8qup6flmAyUoxZN6DpUc=; b=wLYhzIAqZL5Ef9Dy0/cUH0ScrBUSfqDV8HzZ1jEmhMHVAFP6PALW4X6mK+TXIQP3a4 5e57OXNbUdzOnZ2W171B+E6mNbaZNj3biV8ZstIdL6xUpkcsMe4tbg6zJIRsoKtFz8fU KJI2mhJTI/qnlMOvyzmZZE23wadmNyftxE+Sy9GEwS/Zp1+QhgL2f0W/H+aSJ9AjJMTb YF3h+cDjygrY3M68ltmgM9Q1rO/26RklUW25NLLYqsbyT8LxLjL5LMK+Wu7ps7RAe1Jb T+yZb8a3ZVGC2scNVoVupOvreYdydstMfX/6ZcFFU6eSPVZWNg5Dy9WW3IuzVLG/JImG W02w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p39si11544254eda.416.2019.10.21.17.07.45; Mon, 21 Oct 2019 17:08:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730589AbfJVADt (ORCPT + 99 others); Mon, 21 Oct 2019 20:03:49 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:38895 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730548AbfJVADo (ORCPT ); Mon, 21 Oct 2019 20:03:44 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iMgxU-0004Ho-Gy; Tue, 22 Oct 2019 01:19:29 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id BF2601C04D3; Tue, 22 Oct 2019 01:19:20 +0200 (CEST) Date: Mon, 21 Oct 2019 23:19:20 -0000 From: "tip-bot2 for Andi Kleen" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf script: Fix --reltime with --time Cc: Andi Kleen , Jiri Olsa , Arnaldo Carvalho de Melo , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191011182140.8353-1-andi@firstfloor.org> References: <20191011182140.8353-1-andi@firstfloor.org> MIME-Version: 1.0 Message-ID: <157169996037.29376.11389091155150315603.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: b3509b6ed7a79ec49f6b64e4f3b780f259a2a468 Gitweb: https://git.kernel.org/tip/b3509b6ed7a79ec49f6b64e4f3b780f259a2a468 Author: Andi Kleen AuthorDate: Fri, 11 Oct 2019 11:21:39 -07:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Tue, 15 Oct 2019 08:36:22 -03:00 perf script: Fix --reltime with --time 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 Cc: Jiri Olsa Link: http://lore.kernel.org/lkml/20191011182140.8353-1-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 5 +++-- tools/perf/util/time-utils.c | 27 ++++++++++++++++++++++++--- tools/perf/util/time-utils.h | 5 +++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 1c797a9..f86c5cc 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3864,10 +3864,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; diff --git a/tools/perf/util/time-utils.c b/tools/perf/util/time-utils.c index 9796a2e..3024439 100644 --- a/tools/perf/util/time-utils.c +++ b/tools/perf/util/time-utils.c @@ -458,10 +458,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; @@ -471,7 +472,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" @@ -479,7 +480,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, @@ -492,6 +495,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; @@ -504,6 +516,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; diff --git a/tools/perf/util/time-utils.h b/tools/perf/util/time-utils.h index 4f42988..1142b0b 100644 --- a/tools/perf/util/time-utils.h +++ b/tools/perf/util/time-utils.h @@ -26,6 +26,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);