* [PATCH v2 06/10] trace-cmd library: New API tracecmd_output_write_init
@ 2021-11-11 15:07 Tzvetomir Stoyanov (VMware)
0 siblings, 0 replies; only message in thread
From: Tzvetomir Stoyanov (VMware) @ 2021-11-11 15:07 UTC (permalink / raw)
To: rostedt; +Cc: linux-trace-devel
The API writes initial magic bits in a trace file.
tracecmd_output_write_init()
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
.../include/private/trace-cmd-private.h | 1 +
lib/trace-cmd/trace-output.c | 54 +++++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 41876195..2a5ce996 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -275,6 +275,7 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler,
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);
+int tracecmd_output_write_init(struct tracecmd_output *handler);
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 7db3729b..6e4549f9 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -1029,6 +1029,60 @@ int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct trace
return 0;
}
+/**
+ * tracecmd_output_write_init - Write the initial magics in the trace file
+ * @handle: output handler to a trace file.
+ *
+ * This API must be called after all tracecmd_output_set_...() APIs and before writing anything
+ * to the trace file. This initial information is written in the file:
+ * - initial file magic bytes
+ * - file version
+ * - data endian
+ * - long size
+ * - page size
+ * - compression header
+ *
+ * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state.
+ */
+int tracecmd_output_write_init(struct tracecmd_output *handler)
+{
+ char buf[BUFSIZ];
+ int endian4;
+
+ if (!handler || handler->file_state != TRACECMD_FILE_ALLOCATED)
+ return -1;
+
+ buf[0] = 23;
+ buf[1] = 8;
+ buf[2] = 68;
+ memcpy(buf + 3, "tracing", 7);
+
+ if (do_write_check(handler, buf, 10))
+ return -1;
+
+ sprintf(buf, "%lu", handler->file_version);
+ if (do_write_check(handler, buf, strlen(buf) + 1))
+ return -1;
+
+ if (handler->big_endian)
+ buf[0] = 1;
+ else
+ buf[0] = 0;
+ if (do_write_check(handler, buf, 1))
+ return -1;
+
+ /* save size of long (this may not be what the kernel is) */
+ buf[0] = sizeof(long);
+ if (do_write_check(handler, buf, 1))
+ return -1;
+
+ endian4 = convert_endian_4(handler, handler->page_size);
+ if (do_write_check(handler, &endian4, 4))
+ return -1;
+ handler->file_state = TRACECMD_FILE_INIT;
+ return 0;
+}
+
static int select_file_version(struct tracecmd_output *handle,
struct tracecmd_input *ihandle)
{
--
2.33.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-11 15:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-11 15:07 [PATCH v2 06/10] trace-cmd library: New API tracecmd_output_write_init Tzvetomir Stoyanov (VMware)
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).