From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 05/10] trace-cmd library: New API to inherit parameters from an existing trace file
Date: Thu, 11 Nov 2021 17:07:05 +0200 [thread overview]
Message-ID: <20211111150705.86248-1-tz.stoyanov@gmail.com> (raw)
The new API initializes previously allocated output handler with
parameters from an input handler to a trace file.
tracecmd_output_set_from_input()
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
.../include/private/trace-cmd-private.h | 1 +
lib/trace-cmd/trace-output.c | 33 +++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 23e86107..41876195 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -274,6 +274,7 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler,
struct tracecmd_msg_handle *msg_handle);
int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir);
int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms);
+int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle);
struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus);
struct tracecmd_output *
tracecmd_create_init_file_glob(const char *output_file,
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index c654561a..7db3729b 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -996,6 +996,39 @@ int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *ka
return 0;
}
+/**
+ * tracecmd_output_set_from_input - Inherit parameters from an existing trace file
+ * @handle: output handler to a trace file.
+ * @ihandle: input handler to an existing trace file.
+ *
+ * This API copies parameters from input handler @ihandle, associated with an existing trace file,
+ * to the output handler @handle, associated with file that is going to be created.
+ * These parameters are copied:
+ * - tep handler
+ * - page size
+ * - file endian
+ * - file version
+ * - file compression protocol
+ * This API must be called before tracecmd_output_write_init().
+ *
+ * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state.
+ */
+int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle)
+{
+ if (!handler || !ihandle || handler->file_state != TRACECMD_FILE_ALLOCATED)
+ return -1;
+
+ /* get endian, page size, file version and compression */
+ /* Use the pevent of the ihandle for later writes */
+ handler->pevent = tracecmd_get_tep(ihandle);
+ tep_ref(handler->pevent);
+ handler->page_size = tracecmd_page_size(ihandle);
+ handler->file_version = tracecmd_get_in_file_version(ihandle);
+ handler->big_endian = tep_is_file_bigendian(handler->pevent);
+
+ return 0;
+}
+
static int select_file_version(struct tracecmd_output *handle,
struct tracecmd_input *ihandle)
{
--
2.33.1
reply other threads:[~2021-11-11 15:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20211111150705.86248-1-tz.stoyanov@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).