From patchwork Mon Apr 15 23:00:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10901687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0941C14DB for ; Mon, 15 Apr 2019 23:00:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E551928553 for ; Mon, 15 Apr 2019 23:00:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D85FD286F6; Mon, 15 Apr 2019 23:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4383128553 for ; Mon, 15 Apr 2019 23:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbfDOXA1 (ORCPT ); Mon, 15 Apr 2019 19:00:27 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37020 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbfDOXA0 (ORCPT ); Mon, 15 Apr 2019 19:00:26 -0400 Received: by mail-wm1-f65.google.com with SMTP id v14so22505157wmf.2 for ; Mon, 15 Apr 2019 16:00:25 -0700 (PDT) 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=CHU5lSZgpQFpIBBPX7Gv5pNWwyUFiIyTWV+HcHDTf04=; b=oQqPO+ApW18nbOlCqOeTObVX/90gINLjEf67vxz5sU7zHhleGjTxD8wrCQZwfLhYG4 Rkrjf+J8ZxJI1NdRqu3xKudnPdwZsQ44yzHtW9sIipoSPxMgVP0Kly5es4F4Jud9M00m RFojipk7ZKV9aAwtTnlFtdXv6wSJpLtnhgm4IcyZHU2jPqN5Bo77BgFhL6iiPlDjip+K dkPoG6eCJf6B/nAOy6flJc7keRvi4DAIU1vAL5I5r4kE5dk33+4e7EwluMdNwwFnIR75 RDNylrWOpPAyuKtrbRPINvEpPxsu4CYZohm6g/ZZaa/ioEfVX89QpNt2KnAzcrvrwSM+ AMsA== X-Gm-Message-State: APjAAAW33K48kHZRpfWbqsT0jt4LGjbv9Obymebr8uCoYpVuyp1X0yH7 CkP3WCtB5OQkIPjglDUSNw== X-Google-Smtp-Source: APXvYqxdFSBXJYRiksanBb6I68c1yF8clgsGvO7kmwEB7tig4RMyJxtNWlYWnxtyx8e0NQHZhB12Xw== X-Received: by 2002:a1c:3982:: with SMTP id g124mr23659734wma.25.1555369224559; Mon, 15 Apr 2019 16:00:24 -0700 (PDT) Received: from localhost.localdomain ([151.251.250.145]) by smtp.gmail.com with ESMTPSA id v184sm36426455wma.6.2019.04.15.16.00.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 16:00:23 -0700 (PDT) From: Slavomir Kaslev To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, pauld@redhat.com, ykaradzhov@vmware.com, jbacik@fb.com, tstoyanov@vmware.com, slavomir.kaslev@gmail.com Subject: [PATCH v3 1/2] trace-cmd: Optimize how pid filters are expressed Date: Tue, 16 Apr 2019 02:00:15 +0300 Message-Id: <20190415230016.13932-2-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190415230016.13932-1-kaslevs@vmware.com> References: <20190415230016.13932-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Express pid filters as allowed/disallowed filter ranges (pid>=100&&pid<=103) instead of specifying them per pid (pid==100||pid==101||pid==102||pid==103) This makes the size of the resulting filter smaller (and faster) and avoids overflowing the filter size limit of one page which we can hit on bigger machines (say >160 CPUs). Signed-off-by: Slavomir Kaslev Reported-by: Phil Auld Suggested-by: Steven Rostedt (VMware) --- tracecmd/trace-record.c | 117 +++++++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 37 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 76ca92d..dae0396 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -950,10 +950,63 @@ static void update_ftrace_pids(int reset) static void update_event_filters(struct buffer_instance *instance); static void update_pid_event_filters(struct buffer_instance *instance); +static void append_filter_pid_range(char **filter, int *curr_len, + const char *field, + int start_pid, int end_pid, bool exclude) +{ + const char *op = "", *op1, *op2, *op3; + int len; + + if (*filter && **filter) + op = exclude ? "&&" : "||"; + + /* Handle thus case explicitly so that we get `pid==3` instead of + * `pid>=3&&pid<=3` for singleton ranges + */ + if (start_pid == end_pid) { +#define FMT "%s(%s%s%d)" + len = snprintf(NULL, 0, FMT, op, + field, exclude ? "!=" : "==", start_pid); + *filter = realloc(*filter, *curr_len + len + 1); + if (!*filter) + die("realloc"); + + len = snprintf(*filter + *curr_len, len + 1, FMT, op, + field, exclude ? "!=" : "==", start_pid); + *curr_len += len; + + return; +#undef FMT + } + + if (exclude) { + op1 = "<"; + op2 = "||"; + op3 = ">"; + } else { + op1 = ">="; + op2 = "&&"; + op3 = "<="; + } + +#define FMT "%s(%s%s%d%s%s%s%d)" + len = snprintf(NULL, 0, FMT, op, + field, op1, start_pid, op2, + field, op3, end_pid); + *filter = realloc(*filter, *curr_len + len + 1); + if (!*filter) + die("realloc"); + + len = snprintf(*filter + *curr_len, len + 1, FMT, op, + field, op1, start_pid, op2, + field, op3, end_pid); + *curr_len += len; +} + /** * make_pid_filter - create a filter string to all pids against @field * @curr_filter: Append to a previous filter (may realloc). Can be NULL - * @field: The fild to compare the pids against + * @field: The field to compare the pids against * * Creates a new string or appends to an existing one if @curr_filter * is not NULL. The new string will contain a filter with all pids @@ -963,54 +1016,44 @@ static void update_pid_event_filters(struct buffer_instance *instance); */ static char *make_pid_filter(char *curr_filter, const char *field) { + int curr_len = 0, last_exclude = -1; + int start_pid = -1, last_pid = -1; + char *filter = NULL, *save; struct filter_pids *p; - char *filter; - char *orit; - char *match; - char *str; - int curr_len = 0; - int len; /* Use the new method if possible */ if (have_set_event_pid) return NULL; - len = len_filter_pids + (strlen(field) + strlen("(==)||")) * nr_filter_pids; - - if (curr_filter) { - curr_len = strlen(curr_filter); - filter = realloc(curr_filter, curr_len + len + strlen("(&&())")); - if (!filter) - die("realloc"); - memmove(filter+1, curr_filter, curr_len); - filter[0] = '('; - strcat(filter, ")&&("); - curr_len = strlen(filter); - } else - filter = malloc(len); - if (!filter) - die("Failed to allocate pid filter"); - - /* Last '||' that is not used will cover the \0 */ - str = filter + curr_len; + if (!filter_pids) + return curr_filter; for (p = filter_pids; p; p = p->next) { - if (p->exclude) { - match = "!="; - orit = "&&"; - } else { - match = "=="; - orit = "||"; + /* PIDs are inserted in `filter_pids` from the front and that's + * why we expect them in descending order here. + */ + if (p->pid == last_pid - 1 && p->exclude == last_exclude) { + last_pid = p->pid; + continue; } - if (p == filter_pids) - orit = ""; - len = sprintf(str, "%s(%s%s%d)", orit, field, match, p->pid); - str += len; + if (start_pid != -1) + append_filter_pid_range(&filter, &curr_len, field, + last_pid, start_pid, + last_exclude); + + start_pid = last_pid = p->pid; + last_exclude = p->exclude; + } + append_filter_pid_range(&filter, &curr_len, field, + last_pid, start_pid, last_exclude); - if (curr_len) - sprintf(str, ")"); + if (curr_filter) { + save = filter; + asprintf(&filter, "(%s)&&(%s)", curr_filter, filter); + free(save); + } return filter; } From patchwork Mon Apr 15 23:00:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10901689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 912B117E1 for ; Mon, 15 Apr 2019 23:00:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C8F928553 for ; Mon, 15 Apr 2019 23:00:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70C6A286F6; Mon, 15 Apr 2019 23:00:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1514328553 for ; Mon, 15 Apr 2019 23:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726751AbfDOXA1 (ORCPT ); Mon, 15 Apr 2019 19:00:27 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39596 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726939AbfDOXA1 (ORCPT ); Mon, 15 Apr 2019 19:00:27 -0400 Received: by mail-wm1-f66.google.com with SMTP id n25so22505095wmk.4 for ; Mon, 15 Apr 2019 16:00:26 -0700 (PDT) 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=/B6kne7Oor5k7nI87WPMSvdH2yPz3zRd4cAAmlf36j4=; b=Z9cfEEVQEJgbhjkRZk4bCkeprqTV0QNckmqGdPNZgCuHUvACJtgsDxLp4bFLOKEOW4 7dAbDg137Na8FQ6EUyowL3bilLKaGL8xUQ0pRHESpmBxIttO06yZlvjMUH9/cJwmUNbF Q8Lveejm7V3H23ckzS8mIM+IL6X2FJHFHWd7+WyuyB0XV0xud+KrC1/Bzy/8qOFCJE3C Os1co6YBJy98qIQgNQU3cEh0SYu44C7OyLNyH3j0MOQODo+sJJ9bhP7zYcZhfs0nG34z buh+2xJEOmNUYbvcQ/se6pm/6nk0F+Yqg+QsM7fvzwztHZJ+Uh7kk5/i+gkR+RTMnche 3Tjg== X-Gm-Message-State: APjAAAVZxG4dkEJbefnCVTosyS5WUvtZthzxixev8esfOZD+z5Ncbtyb 6O/9ytkUCYT/u2AO1GGWTA== X-Google-Smtp-Source: APXvYqxuAI94D4ZoWznBhTIpFgjRYBEo1jNdj2fp3SHrYt2CYiRNXvUFnr7ZCozgtzWpWehQpj+orw== X-Received: by 2002:a1c:20cf:: with SMTP id g198mr23785016wmg.42.1555369225952; Mon, 15 Apr 2019 16:00:25 -0700 (PDT) Received: from localhost.localdomain ([151.251.250.145]) by smtp.gmail.com with ESMTPSA id v184sm36426455wma.6.2019.04.15.16.00.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 16:00:25 -0700 (PDT) From: Slavomir Kaslev To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, pauld@redhat.com, ykaradzhov@vmware.com, jbacik@fb.com, tstoyanov@vmware.com, slavomir.kaslev@gmail.com Subject: [PATCH v3 2/2] trace-cmd: Add --no-filter option to not filter recording processes Date: Tue, 16 Apr 2019 02:00:16 +0300 Message-Id: <20190415230016.13932-3-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190415230016.13932-1-kaslevs@vmware.com> References: <20190415230016.13932-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add --no-filter option which doesn't install filters for the trace-cmd recording processes pids. Signed-off-by: Slavomir Kaslev Suggested-by: Steven Rostedt (VMware) --- tracecmd/trace-record.c | 14 +++++++++++--- tracecmd/trace-usage.c | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index dae0396..05a313b 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -86,6 +86,7 @@ static int do_ptrace; static int filter_task; static int filter_pid = -1; +static bool no_filter = false; static int local_cpu_count; @@ -1063,6 +1064,9 @@ static void update_task_filter(void) struct buffer_instance *instance; int pid = getpid(); + if (no_filter) + return; + if (filter_task) add_filter_pid(pid, 0); @@ -4377,9 +4381,9 @@ void update_first_instance(struct buffer_instance *instance, int topt) } enum { - - OPT_quiet = 246, - OPT_debug = 247, + OPT_quiet = 245, + OPT_debug = 246, + OPT_no_filter = 247, OPT_max_graph_depth = 248, OPT_tsoffset = 249, OPT_bycomm = 250, @@ -4603,6 +4607,7 @@ static void parse_record_options(int argc, {"by-comm", no_argument, NULL, OPT_bycomm}, {"ts-offset", required_argument, NULL, OPT_tsoffset}, {"max-graph-depth", required_argument, NULL, OPT_max_graph_depth}, + {"no-filter", no_argument, NULL, OPT_no_filter}, {"debug", no_argument, NULL, OPT_debug}, {"quiet", no_argument, NULL, OPT_quiet}, {"help", no_argument, NULL, '?'}, @@ -4877,6 +4882,9 @@ static void parse_record_options(int argc, if (!ctx->max_graph_depth) die("Could not allocate option"); break; + case OPT_no_filter: + no_filter = true; + break; case OPT_debug: debug = 1; break; diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 9ea1906..29a7081 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -56,6 +56,7 @@ static struct usage_help usage_help[] = { " --func-stack perform a stack trace for function tracer\n" " (use with caution)\n" " --max-graph-depth limit function_graph depth\n" + " --no-filter do not set any event filters\n" }, { "start",