From: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH 2/8] trace-cmd: Create API tracecmd_read_pre_headers()
Date: Tue, 2 Mar 2021 06:49:18 +0200 [thread overview]
Message-ID: <CAPpZLN5fdY+rb6s=X6bNykiqrjuTprvZxay9iDSEQxJXHURh3A@mail.gmail.com> (raw)
In-Reply-To: <20210301143856.948525416@goodmis.org>
Hi Steven,
On Mon, Mar 1, 2021 at 4:38 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
>
> The trace-cmd restore operation can create a partial header to read the
> trace event formats and kallsyms and other data into a stand alone header
> before it has access to the cpu data. Then it will also read this header to
> put together a broken trace, and it reads the header that does not have the
> cpu data attached to it.
>
> In order to handle this case, it needs a way to read the headers but stop
> short of reading the CPU information. That requires breaking up
> tracecmd_read_headers() with just stopping short of adding the cpu data.
While looking at these changes, I think it could be more flexible instead of
introducing a new API, to enhance the existing tracecmd_read_headers().
We can add an additional (optional) parameter to point out what headers
to be read, i.e. the desired new state of reading the file. Something like that:
int tracecmd_read_headers(struct tracecmd_input *handle, int state);
It will read the file from its current file_state to the desired state.
The API could be called multiple times, to progress the reading of the
file, header by header if needed, or a bunch of headers.
>
> A new API is added called tracecmd_read_pre_headers() that does exactly that.
>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> .../include/private/trace-cmd-private.h | 1 +
> lib/trace-cmd/trace-input.c | 25 ++++++++++++++++---
> tracecmd/trace-restore.c | 2 +-
> 3 files changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
> index fc968cc9efe1..c7ef3af7c8f7 100644
> --- a/lib/trace-cmd/include/private/trace-cmd-private.h
> +++ b/lib/trace-cmd/include/private/trace-cmd-private.h
> @@ -153,6 +153,7 @@ typedef void (*tracecmd_handle_init_func)(struct tracecmd_input *handle,
> struct tracecmd_input *tracecmd_alloc(const char *file, int flags);
> struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags);
> void tracecmd_ref(struct tracecmd_input *handle);
> +int tracecmd_read_pre_headers(struct tracecmd_input *handle);
> int tracecmd_read_headers(struct tracecmd_input *handle);
> int tracecmd_get_parsing_failures(struct tracecmd_input *handle);
> int tracecmd_long_size(struct tracecmd_input *handle);
> diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
> index 9ef7b9f16951..9e1a44540201 100644
> --- a/lib/trace-cmd/trace-input.c
> +++ b/lib/trace-cmd/trace-input.c
> @@ -772,14 +772,17 @@ static int read_cpus(struct tracecmd_input *handle)
> }
>
> /**
> - * tracecmd_read_headers - read the header information from trace.dat
> + * tracecmd_read_pre_headers - read the header information from trace.dat
> * @handle: input handle for the trace.dat file
> *
> * This reads the trace.dat file for various information. Like the
> * format of the ring buffer, event formats, ftrace formats, kallsyms
> - * and printk.
> + * and printk, but stops before reading cpu and options.
> + *
> + * This is needed by the restore operation where the header does not
> + * have the CPU information yet.
> */
> -int tracecmd_read_headers(struct tracecmd_input *handle)
> +int tracecmd_read_pre_headers(struct tracecmd_input *handle)
> {
> int ret;
>
> @@ -815,6 +818,22 @@ int tracecmd_read_headers(struct tracecmd_input *handle)
> return -1;
> handle->file_state = TRACECMD_FILE_CMD_LINES;
>
> + return 0;
> +}
> +
> +/**
> + * tracecmd_read_headers - read the header information from trace.dat
> + * @handle: input handle for the trace.dat file
> + *
> + * This reads the trace.dat file for various information. Like the
> + * format of the ring buffer, event formats, ftrace formats, kallsyms
> + * and printk.
> + */
> +int tracecmd_read_headers(struct tracecmd_input *handle)
> +{
> + if (tracecmd_read_pre_headers(handle))
> + return -1;
> +
> if (read_cpus(handle) < 0)
> return -1;
> handle->file_state = TRACECMD_FILE_CPU_COUNT;
> diff --git a/tracecmd/trace-restore.c b/tracecmd/trace-restore.c
> index 13f803053582..bf6940991178 100644
> --- a/tracecmd/trace-restore.c
> +++ b/tracecmd/trace-restore.c
> @@ -122,7 +122,7 @@ void trace_restore (int argc, char **argv)
> if (!ihandle)
> die("error reading file %s", input);
> /* make sure headers are ok */
> - if (tracecmd_read_headers(ihandle) < 0)
> + if (tracecmd_read_pre_headers(ihandle) < 0)
> die("error reading file %s headers", input);
>
> handle = tracecmd_copy(ihandle, output);
> --
> 2.30.0
>
>
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
next prev parent reply other threads:[~2021-03-03 0:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 14:37 [PATCH 0/8] trace-cmd: Fixes for trace-cmd restore Steven Rostedt
2021-03-01 14:37 ` [PATCH 1/8] trace-cmd restore: Fix to add saved cmdlines after calling tracecmd_create_init_file_override() Steven Rostedt
2021-03-01 14:37 ` [PATCH 2/8] trace-cmd: Create API tracecmd_read_pre_headers() Steven Rostedt
2021-03-02 4:49 ` Tzvetomir Stoyanov [this message]
2021-03-02 14:13 ` Steven Rostedt
2021-03-01 14:37 ` [PATCH 3/8] trace-cmd: Move tracecmd_write_cmdlines() out of tracecmd_append_cpu_data() Steven Rostedt
2021-03-01 14:37 ` [PATCH 4/8] trace-cmd: Move the output state updates into the functions that change the state Steven Rostedt
2021-03-01 14:37 ` [PATCH 5/8] trace-cmd: Move the input " Steven Rostedt
2021-03-01 14:37 ` [PATCH 6/8] trace-cmd output: Set file_state of output handle after copy of headers Steven Rostedt
2021-03-02 8:10 ` Tzvetomir Stoyanov
2021-03-02 14:19 ` Steven Rostedt
2021-03-02 14:51 ` Tzvetomir Stoyanov
2021-03-02 15:48 ` Steven Rostedt
2021-03-02 17:35 ` Tzvetomir Stoyanov
2021-03-02 19:59 ` Steven Rostedt
2021-03-02 14:22 ` Steven Rostedt
2021-03-01 14:37 ` [PATCH 7/8] trace-cmd input: Validate the input handle when copying from it Steven Rostedt
2021-03-01 14:37 ` [PATCH 8/8] trace-cmd input: Add validation updates to the copy of a handle 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='CAPpZLN5fdY+rb6s=X6bNykiqrjuTprvZxay9iDSEQxJXHURh3A@mail.gmail.com' \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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).