From: Steven Rostedt <rostedt@goodmis.org>
To: Slavomir Kaslev <kaslevs@vmware.com>
Cc: linux-trace-devel@vger.kernel.org, pauld@redhat.com,
ykaradzhov@vmware.com, jbacik@fb.com, tstoyanov@vmware.com,
slavomir.kaslev@gmail.com
Subject: Re: [PATCH v3 1/2] trace-cmd: Optimize how pid filters are expressed
Date: Tue, 16 Apr 2019 17:48:10 -0400 [thread overview]
Message-ID: <20190416174810.50d8a88d@gandalf.local.home> (raw)
In-Reply-To: <20190415230016.13932-2-kaslevs@vmware.com>
On Tue, 16 Apr 2019 02:00:15 +0300
Slavomir Kaslev <kaslevs@vmware.com> wrote:
> static char *make_pid_filter(char *curr_filter, const char *field)
> {
> + int curr_len = 0, last_exclude = -1;
Small nit. Usually when adding multiple variables on one line like
this, the variables should be related. Because curr_len and
last_exclude are not related, it is best to keep them separate.
> + int start_pid = -1, last_pid = -1;
start_pid and last_pid are fine on the same line or separate.
> + char *filter = NULL, *save;
Note, It's better to keep variables separate. It makes it easier to see
them and also when code changes and you get the "variable x is not
used" warnings from gcc, it's easier to remove them. In emacs it brings
you to the warning and places the cursor on the problem line. Then a
simple "delete line" works well.
save could also be moved below.
> 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
Comment notation should be:
/*
* PIDs are inserted in ...
Only the Networking folks are allowed to do it that way in the
kernel ;-)
> + * 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) {
As save is only used here, we could have:
char *save = filter;
> + save = filter;
> + asprintf(&filter, "(%s)&&(%s)", curr_filter, filter);
> + free(save);
> + }
>
> return filter;
> }
-- Steve
next prev parent reply other threads:[~2019-04-16 21:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 23:00 [PATCH v3 0/2] Optimize pid filters and add --no-filter option Slavomir Kaslev
2019-04-15 23:00 ` [PATCH v3 1/2] trace-cmd: Optimize how pid filters are expressed Slavomir Kaslev
2019-04-16 21:48 ` Steven Rostedt [this message]
2019-04-17 13:44 ` Slavomir Kaslev
2019-04-15 23:00 ` [PATCH v3 2/2] trace-cmd: Add --no-filter option to not filter recording processes Slavomir Kaslev
2019-04-16 21:49 ` Steven Rostedt
2019-04-16 13:22 ` [PATCH v3 0/2] Optimize pid filters and add --no-filter option Phil Auld
2019-04-16 21:39 ` Steven Rostedt
2019-04-17 0:29 ` Phil Auld
2019-04-17 12:49 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190416174810.50d8a88d@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=jbacik@fb.com \
--cc=kaslevs@vmware.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=pauld@redhat.com \
--cc=slavomir.kaslev@gmail.com \
--cc=tstoyanov@vmware.com \
--cc=ykaradzhov@vmware.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).