From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 01/10] trace-cmd library: New API for allocating an output handler
Date: Fri,  8 Oct 2021 07:13:12 +0300	[thread overview]
Message-ID: <20211008041321.973755-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com>
The API only allocates a handler and performs minimal initialization.
No data is written in the file.
  tracecmd_output_allocate()
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 .../include/private/trace-cmd-private.h       |  4 ++-
 lib/trace-cmd/trace-output.c                  | 36 +++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index c58b09e9..b4cee0f6 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -102,7 +102,8 @@ static inline int tracecmd_host_bigendian(void)
 /* --- Opening and Reading the trace.dat file --- */
 
 enum tracecmd_file_states {
-	TRACECMD_FILE_INIT = 1,
+	TRACECMD_FILE_ALLOCATED = 0,
+	TRACECMD_FILE_INIT,
 	TRACECMD_FILE_HEADERS,
 	TRACECMD_FILE_FTRACE_EVENTS,
 	TRACECMD_FILE_ALL_EVENTS,
@@ -268,6 +269,7 @@ struct tracecmd_event_list {
 struct tracecmd_option;
 struct tracecmd_msg_handle;
 
+struct tracecmd_output *tracecmd_output_allocate(int fd);
 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 fe1d1aaa..3878b963 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -59,6 +59,7 @@ struct tracecmd_output {
 	unsigned long		file_state;
 	unsigned long		file_version;
 	size_t			options_start;
+	bool			big_endian;
 
 	struct list_head	options;
 	struct tracecmd_msg_handle *msg_handle;
@@ -883,6 +884,41 @@ out_free:
 	return ret;
 }
 
+/**
+ * tracecmd_output_allocate - allocate new output handler to a trace file
+ * @handle: file descriptor to an empty file, it can be -1 if the handler
+ *	    will not write to a file
+ *
+ * This API only allocates a handler and performs minimal initialization.
+ * No data is written in the file.
+ *
+ * Returns pointer to a newly allocated file descriptor, that can be used
+ * with other library APIs. In case of an error, NULL is returned. The returned
+ * handler must be freed with tracecmd_output_close() or tracecmd_output_free()
+ */
+struct tracecmd_output *tracecmd_output_allocate(int fd)
+{
+	struct tracecmd_output *handle;
+
+	handle = calloc(1, sizeof(*handle));
+	if (!handle)
+		return NULL;
+
+	handle->fd = fd;
+
+	handle->file_version = FILE_VERSION;
+
+	handle->page_size = getpagesize();
+	handle->big_endian = tracecmd_host_bigendian();
+
+	list_head_init(&handle->options);
+
+	handle->file_state = TRACECMD_FILE_ALLOCATED;
+
+	return handle;
+}
+
+
 static int select_file_version(struct tracecmd_output *handle,
 				struct tracecmd_input *ihandle)
 {
-- 
2.31.1
next prev parent reply	other threads:[~2021-10-08  4:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-08  4:13 [PATCH 00/10] Refactor APIs for creating output handler Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` Tzvetomir Stoyanov (VMware) [this message]
2021-10-08  4:13 ` [PATCH 02/10] trace-cmd library: New API for setting a message context to an " Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 03/10] trace-cmd library: New API for setting a custom trace directory " Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 04/10] trace-cmd library: New API for setting a custom kallsyms " Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 05/10] trace-cmd library: New API to inherit parameters from an existing trace file Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 06/10] trace-cmd library: New API tracecmd_output_write_init Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 07/10] trace-cmd library: New API to write headers of a trace file Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 08/10] trace-cmd library: Use the new flow when creating output handler Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 09/10] trace-cmd: " Tzvetomir Stoyanov (VMware)
2021-10-08  4:13 ` [PATCH 10/10] trace-cmd library: Remove deprecated APIs for creating an " Tzvetomir Stoyanov (VMware)
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=20211008041321.973755-2-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).