From: Jiri Olsa <olsajiri@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCH bpf-next] selftests/bpf: Add read_trace_pipe_iter function
Date: Tue, 9 Apr 2024 15:50:24 +0200 [thread overview]
Message-ID: <ZhVHoEkQUS0TCbyl@krava> (raw)
In-Reply-To: <20240409123601.1592655-1-jolsa@kernel.org>
On Tue, Apr 09, 2024 at 02:36:01PM +0200, Jiri Olsa wrote:
SNIP
> +int read_trace_pipe_iter(void (*cb)(const char *str, void *data), void *data, int iter)
> +{
> + char *buf = NULL;
> + FILE *fp = NULL;
> + size_t buflen;
> +
> + if (access(TRACEFS_PIPE, F_OK) == 0)
> + fp = fopen(TRACEFS_PIPE, "r");
> + else
> + fp = fopen(DEBUGFS_PIPE, "r");
> + if (!fp)
> + return -1;
> +
> + /* We do not want to wait forever when iter is specified. */
> + if (iter)
> + fcntl(fileno(fp), F_SETFL, O_NONBLOCK);
> +
> + while (getline(&buf, &buflen, fp) >= 0 || errno == EAGAIN) {
> + cb(buf, data);
> + if (iter && !(--iter))
> + break;
> + }
hm, using this in some other changes shows that the original code
is not completely right and we need this change as well:
+ while ((n = getline(&buf, &buflen, fp) >= 0) || errno == EAGAIN) {
+ if (n > 0)
+ cb(buf, data);
I'll send new version
jirka
> +
> + free(buf);
> + if (fp)
> + fclose(fp);
> + return 0;
> +}
> +
> +static void trace_pipe_cb(const char *str, void *data)
> +{
> + printf("%s", str);
> +}
> +
> +void read_trace_pipe(void)
> +{
> + read_trace_pipe_iter(trace_pipe_cb, NULL, 0);
> +}
> diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
> index d1ed71789049..2ce873c9f9aa 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.h
> +++ b/tools/testing/selftests/bpf/trace_helpers.h
> @@ -33,6 +33,8 @@ struct ksym *search_kallsyms_custom_local(struct ksyms *ksyms, const void *p1,
> int kallsyms_find(const char *sym, unsigned long long *addr);
>
> void read_trace_pipe(void);
> +int read_trace_pipe_iter(void (*cb)(const char *str, void *data),
> + void *data, int iter);
>
> ssize_t get_uprobe_offset(const void *addr);
> ssize_t get_rel_offset(uintptr_t addr);
> --
> 2.44.0
>
prev parent reply other threads:[~2024-04-09 13:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-09 12:36 [PATCH bpf-next] selftests/bpf: Add read_trace_pipe_iter function Jiri Olsa
2024-04-09 13:50 ` Jiri Olsa [this message]
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=ZhVHoEkQUS0TCbyl@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.