Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp3559405imc; Sun, 24 Feb 2019 07:39:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IahXS60CjmSXxMOXJKRwSaF/348BsJ7UYJbz6CEzYv47nyr9x2Xg210XsyBUhYThFiAwvg3 X-Received: by 2002:a17:902:e409:: with SMTP id ci9mr14515095plb.221.1551022740903; Sun, 24 Feb 2019 07:39:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551022740; cv=none; d=google.com; s=arc-20160816; b=wrd5cgcIbMHlwnvOK2aVqUbpc6EbIlO6Q57VaX8f/oWynEl3Kpt4wYcr0wsUvEEbtS kkH4ftOq34pNYfL44AVLb6Z2v7qKGYJ6xzqPSA2wGAWwm17rLrmOAKnVln1HgEthc87W UjW6AZsAq0T08lcHzRJ0FBD6Hzhs13K6k788JFyDQHDxM3514CgPC7qaIv2CgggsWHyN GNxCjk+9Lb9d9vNd8Cx92R5pTvudwDCADI5D2H5C0FDEyJ9eyrsXCddziJh2sX4QFrLG T+6DRx0sgxGGWRgyT6gqgiCJEXlNGp8VbsdVPfFG7dVb/p71HQDVU/yeKT6pitXZ96AH hs8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KHhqM1o7c7svwU/9AiUbL9/3t+k6yveTdWY+OvoLoHU=; b=hLewlEaWdqU4UrlR0db2a9Tjqo4yaDkkIU5aoM7Bjo3oTyz8vuJq9FB9wtppeGot7C 4jk/QFh2cEQet7jowS1B3/M7xZkGUvwuEnphpAH3pO5cyo4oIri/sOBKG9vSbNRoi5DA fQUpzX3iITMLRmb50HXBA9/QAu/9I8I+CIk0kXywAk/efVycz6TA0AiuFPEM1Upi7E9Q twa1YY7H7ZUlHdG/Wfb9KEnKiKpGkpTksIMS4txVbxuTn9ZOkwYap8k2jMUkmZfbYvFo hazYKPlZI2pYFioNPWVR4u7GXfPhEleHiB/WPCtw58wMiniJ5QhO8dpCXAuDIBC6pKu6 e+Rw== 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 34si6708166pgs.553.2019.02.24.07.38.45; Sun, 24 Feb 2019 07:39:00 -0800 (PST) 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 S1728493AbfBXPhd (ORCPT + 99 others); Sun, 24 Feb 2019 10:37:33 -0500 Received: from mga01.intel.com ([192.55.52.88]:4459 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728475AbfBXPhd (ORCPT ); Sun, 24 Feb 2019 10:37:33 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP; 24 Feb 2019 07:37:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,407,1544515200"; d="scan'208";a="120396835" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by orsmga008.jf.intel.com with ESMTP; 24 Feb 2019 07:37:30 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id B04B13011D4; Sun, 24 Feb 2019 07:37:30 -0800 (PST) From: Andi Kleen To: acme@kernel.org, linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jolsa@kernel.org, namhyung@kernel.org, eranian@google.com, Andi Kleen Subject: [PATCH 07/11] perf tools report: Support running scripts for current time range Date: Sun, 24 Feb 2019 07:37:18 -0800 Message-Id: <20190224153722.27020-8-andi@firstfloor.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190224153722.27020-1-andi@firstfloor.org> References: <20190224153722.27020-1-andi@firstfloor.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen When using the time sort key, add new context menus to run scripts for only the currently selected time range. Compute the correct range for the selection add pass it as the --time option to perf script. Signed-off-by: Andi Kleen --- tools/perf/ui/browsers/hists.c | 82 +++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index aef800d97ea1..2a4f363f8cc7 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -30,6 +30,7 @@ #include "srcline.h" #include "string2.h" #include "units.h" +#include "time-utils.h" #include "sane_ctype.h" @@ -2338,6 +2339,7 @@ static int switch_data_file(void) } struct popup_action { + unsigned long time; struct thread *thread; struct map_symbol ms; int socket; @@ -2527,36 +2529,64 @@ static int do_run_script(struct hist_browser *browser __maybe_unused, struct popup_action *act) { - char script_opt[64]; - memset(script_opt, 0, sizeof(script_opt)); + char *script_opt; + int len; + int n = 0; + + len = 100; + if (act->thread) + len += strlen(thread__comm_str(act->thread)); + else if (act->ms.sym) + len += strlen(act->ms.sym->name); + script_opt = malloc(len); + if (!script_opt) + return -1; + script_opt[0] = 0; if (act->thread) { - scnprintf(script_opt, sizeof(script_opt), " -c %s ", + n = scnprintf(script_opt, len, " -c %s ", thread__comm_str(act->thread)); } else if (act->ms.sym) { - scnprintf(script_opt, sizeof(script_opt), " -S %s ", + n = scnprintf(script_opt, len, " -S %s ", act->ms.sym->name); } + if (act->time) { + char start[64], end[64]; + unsigned long starttime = act->time; + unsigned long endtime = act->time + time_quantum; + + if (starttime == endtime) { /* Display 1ms as fallback */ + starttime -= 1*1000000; + endtime += 1*1000000; + } + timestamp__scnprintf_usec(starttime, start, sizeof start); + timestamp__scnprintf_usec(endtime, end, sizeof end); + n += snprintf(script_opt + n, len - n, " --time %s,%s", start, end); + } + script_browse(script_opt); + free(script_opt); return 0; } static int -add_script_opt(struct hist_browser *browser __maybe_unused, +add_script_opt_2(struct hist_browser *browser __maybe_unused, struct popup_action *act, char **optstr, - struct thread *thread, struct symbol *sym) + struct thread *thread, struct symbol *sym, + const char *tstr) { + if (thread) { - if (asprintf(optstr, "Run scripts for samples of thread [%s]", - thread__comm_str(thread)) < 0) + if (asprintf(optstr, "Run scripts for samples of thread [%s]%s", + thread__comm_str(thread), tstr) < 0) return 0; } else if (sym) { - if (asprintf(optstr, "Run scripts for samples of symbol [%s]", - sym->name) < 0) + if (asprintf(optstr, "Run scripts for samples of symbol [%s]%s", + sym->name, tstr) < 0) return 0; } else { - if (asprintf(optstr, "Run scripts for all samples") < 0) + if (asprintf(optstr, "Run scripts for all samples%s", tstr) < 0) return 0; } @@ -2566,6 +2596,36 @@ add_script_opt(struct hist_browser *browser __maybe_unused, return 1; } +static int +add_script_opt(struct hist_browser *browser, + struct popup_action *act, char **optstr, + struct thread *thread, struct symbol *sym) +{ + int n, j; + struct hist_entry *he; + + n = add_script_opt_2(browser, act, optstr, thread, sym, ""); + + he = hist_browser__selected_entry(browser); + if (sort_order && strstr(sort_order, "time")) { + char tstr[128]; + + optstr++; + act++; + j = sprintf(tstr, " in "); + j += timestamp__scnprintf_usec(he->time, tstr + j, + sizeof tstr - j); + j += sprintf(tstr + j, "-"); + timestamp__scnprintf_usec(he->time + time_quantum, + tstr + j, + sizeof tstr - j); + n += add_script_opt_2(browser, act, optstr, thread, sym, + tstr); + act->time = he->time; + } + return n; +} + static int do_switch_data(struct hist_browser *browser __maybe_unused, struct popup_action *act __maybe_unused) -- 2.17.2