Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2029083ybh; Fri, 17 Jul 2020 07:38:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5PTOWNtARvVjgNJ/b9vLbkhMeCnCltVuGHHf7PKOshiOHuXGuCFf7/tY9CNw8awDa2d7E X-Received: by 2002:a17:906:c83c:: with SMTP id dd28mr8749345ejb.420.1594996730485; Fri, 17 Jul 2020 07:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594996730; cv=none; d=google.com; s=arc-20160816; b=ysiHNduMfD3LKqfYETXRPamyfr0NPyglmuvsqxdWcxawcedTWBVPiGy/ZW9ZYqgwBi eKvkk6EIYx3G+ZsNZ4cVnzd+hF6+pPz94/Bjthwtu/T3fpZt90NvfV+IPY5X4WbIcqf6 yz2TCYLaI1FaF6Qq/pAz0EBL0F4jjg11wCe93eEmEVV1xPKipGJC52QhTJn1bGvbl7EW PofVZxIkpiqFSrK9Uyo19P0qofvS0jj7Dog24PB6IfFjkYpF37K7LKGdH2ILJVBdRAp2 xOydl7yvhcMPLtqWsNwCCidLluQp1u7dB4KhLZvqjAYBvj+FnpbB7tbGHyHDJIErBboc Tdqg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MNrpaoZVGEfTNw615GzyXCuvGdypRr0hU2eDJlGIah0=; b=PkzqHwgrRhBPSTp1CA8qdh1L5UvArJr/x+4WjuYBezg2ImTYtlQ2c0LhEx3Q371MXb EW+Jk5yVBUKscqZwO43Xknw7K9ujwjx1y6Jz9AaD6C+mQlwJx5j7sIwotxgAWQoHJnlA 9ROrD/3QDQga6dZAelhA/UgaxRwS7cFWZgBVBbZEAzRppGLG7t9c4s0E6VQBNlwc4yTG mCcA8+lVHu4x+6dxuQGZThzL9GMRoSp+ylT1nqD+oSFj+E3nG7nCRT25aEDdKqzyDhtA 35JF63O6tJLj8H9SzP+4ri6JmOqk6YbyazzqxFbEff6IbPGFvmJBF1lagYifTCOIe7Qw nz6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mgtJLXYc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si5412468ejw.376.2020.07.17.07.38.27; Fri, 17 Jul 2020 07:38:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mgtJLXYc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbgGQOhi (ORCPT + 99 others); Fri, 17 Jul 2020 10:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbgGQOhh (ORCPT ); Fri, 17 Jul 2020 10:37:37 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80608C0619D2 for ; Fri, 17 Jul 2020 07:37:37 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id t6so6765272pgq.1 for ; Fri, 17 Jul 2020 07:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MNrpaoZVGEfTNw615GzyXCuvGdypRr0hU2eDJlGIah0=; b=mgtJLXYcCmIVB0XtjkbhoO1bX5zANd9SM2mx7tWtA3f7j/MBaJ8ZefFHw7cBLJPBb+ NtUSC36dqshjkA9O85NDyweC/nimKOsTzJD2kpXQw10e2U1q2Nw4qMEm5FC2SjyDqxhB BE5CR+pGcuHpHnXcnL3PzF/ynyxmwee5fhR4UrREcBWS+zYO2Q+cBWh39J1KA/LpZHm5 OKn+J+n1N0VEECNmDzdRhj27lVuwHgk9TXqU56xD6O4pyx/UGCMLEz2pwcCPkfUwE+Jn 6ST7WgGm4vQpKt2z1qvSCnlcOcOIl513FbMO30LGqcoYIOn2FEm3W5LOgeP6DJZP2dxg rZqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MNrpaoZVGEfTNw615GzyXCuvGdypRr0hU2eDJlGIah0=; b=Jk/XGqZPwmTp7KO3qS5TPd+ypLOMcMTw33/EPNV+Kq6eGxVXmAVS6/z/3V0qanJOpv sLCcnpgrWZm9341XEAlE8el6cInl9QzaY5zfEUfymwkwr3vY21KIVZhE6S44I0dvhpuv cEwGcyEVqUEt9Lh9ny24bzfhGEalrVe37/hum7iKKYxPxH8YBBs/gy5LjEU5gEthZuKQ B9tp+oYbX+iy5EkzZRAYd3kh5Oqwq3z35P92w58XFLZ+8jeLWSn17Oi1UiWM/Dghh84P raubLncfcOcWa6cU0P3K/Ycf4+7p4IHepD5F7neojewVL501v4vcqpEVXDKgGWUWb7rE /GAg== X-Gm-Message-State: AOAM53060o/GXleAu3HftCp5oItCPKPp5005g3bTmNMcIfnyuriroCWb wGz3+3ufBIAizC6NLG0Jb/c= X-Received: by 2002:aa7:9ec2:: with SMTP id r2mr8372750pfq.265.1594996657069; Fri, 17 Jul 2020 07:37:37 -0700 (PDT) Received: from vultr.guest ([149.248.10.52]) by smtp.gmail.com with ESMTPSA id a68sm3214689pje.35.2020.07.17.07.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 07:37:36 -0700 (PDT) From: Changbin Du To: Jiri Olsa , Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Namhyung Kim , Steven Rostedt , linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH v6 06/17] perf ftrace: add option '--inherit' to trace children processes Date: Fri, 17 Jul 2020 22:36:17 +0800 Message-Id: <20200717143628.47721-7-changbin.du@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717143628.47721-1-changbin.du@gmail.com> References: <20200717143628.47721-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds an option '--inherit' to allow us trace children processes spawned by our target. Signed-off-by: Changbin Du --- v2: option name '--trace-children' -> '--inherit'. --- tools/perf/Documentation/perf-ftrace.txt | 3 ++ tools/perf/builtin-ftrace.c | 38 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt index dcac0d75a0e5..3eee073a7042 100644 --- a/tools/perf/Documentation/perf-ftrace.txt +++ b/tools/perf/Documentation/perf-ftrace.txt @@ -57,6 +57,9 @@ OPTIONS Set the size of per-cpu tracing buffer, is expected to be a number with appended unit character - B/K/M/G. +--inherit:: + Trace children processes spawned by our target. + -T:: --trace-funcs=:: Only trace functions given by the argument. Multiple functions diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 6ce626a2d0d1..765ebd56e05f 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -39,6 +39,7 @@ struct perf_ftrace { struct list_head nograph_funcs; int graph_depth; unsigned long percpu_buffer_size; + bool inherit; }; struct filter_entry { @@ -180,9 +181,27 @@ static int write_tracing_file_int(const char *name, int value) return 0; } +static int write_tracing_option_file(const char *name, const char *val) +{ + char *file; + int ret; + + if (asprintf(&file, "options/%s", name) < 0) + return -1; + + ret = __write_tracing_file(file, val, false); + free(file); + return ret; +} + static int reset_tracing_cpu(void); static void reset_tracing_filters(void); +static void reset_tracing_options(struct perf_ftrace *ftrace __maybe_unused) +{ + write_tracing_option_file("function-fork", "0"); +} + static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused) { if (write_tracing_file("tracing_on", "0") < 0) @@ -201,6 +220,7 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused) return -1; reset_tracing_filters(); + reset_tracing_options(ftrace); return 0; } @@ -339,6 +359,17 @@ static int set_tracing_percpu_buffer_size(struct perf_ftrace *ftrace) return 0; } +static int set_tracing_trace_inherit(struct perf_ftrace *ftrace) +{ + if (!ftrace->inherit) + return 0; + + if (write_tracing_option_file("function-fork", "1") < 0) + return -1; + + return 0; +} + static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) { char *trace_file; @@ -408,6 +439,11 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) goto out_reset; } + if (set_tracing_trace_inherit(ftrace) < 0) { + pr_err("failed to set tracing option function-fork\n"); + goto out_reset; + } + if (write_tracing_file("current_tracer", ftrace->tracer) < 0) { pr_err("failed to set current_tracer to %s\n", ftrace->tracer); goto out_reset; @@ -600,6 +636,8 @@ int cmd_ftrace(int argc, const char **argv) "Max depth for function graph tracer"), OPT_CALLBACK('m', "buffer-size", &ftrace.percpu_buffer_size, "size", "size of per cpu buffer", parse_buffer_size), + OPT_BOOLEAN(0, "inherit", &ftrace.inherit, + "trace children processes"), OPT_END() }; -- 2.25.1