From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v8 04/25] trace-cmd library: Add strings section in trace file version 7
Date: Wed, 19 Jan 2022 10:24:46 +0200 [thread overview]
Message-ID: <20220119082507.245600-5-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20220119082507.245600-1-tz.stoyanov@gmail.com>
In the trace file metadata there are various dynamic strings. Collecting
all these strings in a dedicated section in the file simplifies parsing
of the metadata. The string section is added in trace files version 7,
at the end of the file.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
.../include/private/trace-cmd-private.h | 2 +
lib/trace-cmd/trace-output.c | 68 +++++++++++++++++++
tracecmd/trace-record.c | 1 +
3 files changed, 71 insertions(+)
diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 77374000..e1467971 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -143,6 +143,7 @@ enum {
TRACECMD_OPTION_TIME_SHIFT,
TRACECMD_OPTION_GUEST,
TRACECMD_OPTION_TSC2NSEC,
+ TRACECMD_OPTION_STRINGS,
};
enum {
@@ -306,6 +307,7 @@ int tracecmd_write_buffer_info(struct tracecmd_output *handle);
int tracecmd_write_cpus(struct tracecmd_output *handle, int cpus);
int tracecmd_write_cmdlines(struct tracecmd_output *handle);
int tracecmd_write_options(struct tracecmd_output *handle);
+int tracecmd_write_meta_strings(struct tracecmd_output *handle);
int tracecmd_append_options(struct tracecmd_output *handle);
void tracecmd_output_close(struct tracecmd_output *handle);
void tracecmd_output_free(struct tracecmd_output *handle);
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 4d165ac2..d3c73ceb 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -62,6 +62,12 @@ struct tracecmd_output {
bool quiet;
unsigned long file_state;
unsigned long file_version;
+
+ /* size of meta-data strings, not yet stored in the file */
+ unsigned long strings_p;
+ /* current virtual offset of meta-data string */
+ unsigned long strings_offs;
+
size_t options_start;
bool big_endian;
@@ -69,6 +75,9 @@ struct tracecmd_output {
struct list_head buffers;
struct tracecmd_msg_handle *msg_handle;
char *trace_clock;
+
+ /* meta-data strings, not yet stored in the file */
+ char *strings;
};
struct list_event {
@@ -85,6 +94,8 @@ struct list_event_system {
#define HAS_SECTIONS(H) ((H)->file_version >= FILE_VERSION_SECTIONS)
+static int save_string_section(struct tracecmd_output *handle);
+
static stsize_t
do_write_check(struct tracecmd_output *handle, const void *data, tsize_t size)
{
@@ -127,6 +138,22 @@ static unsigned long long convert_endian_8(struct tracecmd_output *handle,
return tep_read_number(handle->pevent, &val, 8);
}
+static long add_string(struct tracecmd_output *handle, const char *string)
+{
+ int size = strlen(string) + 1;
+ int pos = handle->strings_p;
+ char *strings;
+
+ strings = realloc(handle->strings, pos + size);
+ if (!strings)
+ return -1;
+ handle->strings = strings;
+ memcpy(handle->strings + pos, string, size);
+ handle->strings_p += size;
+
+ return handle->strings_offs + pos;
+}
+
/**
* tracecmd_set_quiet - Set if to print output to the screen
* @quiet: If non zero, print no output to the screen
@@ -185,6 +212,7 @@ void tracecmd_output_free(struct tracecmd_output *handle)
free(option);
}
+ free(handle->strings);
free(handle->trace_clock);
free(handle);
}
@@ -194,6 +222,11 @@ void tracecmd_output_close(struct tracecmd_output *handle)
if (!handle)
return;
+ if (HAS_SECTIONS(handle)) {
+ /* write strings section */
+ save_string_section(handle);
+ }
+
if (handle->fd >= 0) {
close(handle->fd);
handle->fd = -1;
@@ -332,6 +365,32 @@ int tracecmd_ftrace_enable(int set)
return ret;
}
+static int save_string_section(struct tracecmd_output *handle)
+{
+ if (!handle->strings || !handle->strings_p)
+ return 0;
+
+ if (!check_out_state(handle, TRACECMD_OPTION_STRINGS)) {
+ tracecmd_warning("Cannot write strings, unexpected state 0x%X",
+ handle->file_state);
+ return -1;
+ }
+
+ if (do_write_check(handle, handle->strings, handle->strings_p))
+ goto error;
+
+ handle->strings_offs += handle->strings_p;
+ free(handle->strings);
+ handle->strings = NULL;
+ handle->strings_p = 0;
+ handle->file_state = TRACECMD_OPTION_STRINGS;
+ return 0;
+
+error:
+ return -1;
+}
+
+
static int read_header_files(struct tracecmd_output *handle)
{
tsize_t size, check_size, endian8;
@@ -1328,6 +1387,15 @@ int tracecmd_write_options(struct tracecmd_output *handle)
return 0;
}
+int tracecmd_write_meta_strings(struct tracecmd_output *handle)
+{
+ if (!HAS_SECTIONS(handle))
+ return 0;
+
+ return save_string_section(handle);
+}
+
+
int tracecmd_append_options(struct tracecmd_output *handle)
{
struct tracecmd_option *options;
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 7b2b59bb..f599610e 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -4093,6 +4093,7 @@ static void setup_agent(struct buffer_instance *instance,
tracecmd_write_cmdlines(network_handle);
tracecmd_write_cpus(network_handle, instance->cpu_count);
tracecmd_write_options(network_handle);
+ tracecmd_write_meta_strings(network_handle);
tracecmd_msg_finish_sending_data(instance->msg_handle);
instance->network_handle = network_handle;
}
--
2.34.1
next prev parent reply other threads:[~2022-01-19 8:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-19 8:24 [PATCH v8 00/25] Trace file version 7 - sections Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 01/25] trace-cmd library: Define trace file version 7 Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 02/25] trace-cmd library: Add cache functionality to network message handler Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 03/25] trace-cmd library: New APIs to get and set version of output handler Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` Tzvetomir Stoyanov (VMware) [this message]
2022-01-19 8:24 ` [PATCH v8 05/25] trace-cmd library: Add internal helper function for writing headers before file sections Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 06/25] trace-cmd library: Write header " Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 07/25] trace-cmd library: Add multiple options sections in trace file version 7 Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 08/25] trace-cmd library: Do not write CPU count section in trace files " Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 09/25] trace-cmd library: Move CPU flyrecord trace metadata into the buffer option, for trace file " Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 10/25] trace-cmd library: Add section header before flyrecord trace data Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 11/25] trace-cmd library: Fit CPU latency trace data in the new trace file version 7 format Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 12/25] trace-cmd library: Add macro to check file state on reading Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 13/25] trace-cmd library: Introduce sections in trace file reading logic Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 14/25] trace-cmd library: Initialize internal sections database on file read Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 15/25] trace-cmd library: Use sections database when reading parts of the trace file Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 16/25] trace-cmd library: Read headers from trace file version 7 Tzvetomir Stoyanov (VMware)
2022-01-19 8:24 ` [PATCH v8 17/25] trace-cmd library: Read strings sections on file load Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 18/25] trace-cmd library: Read extended BUFFER option Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 19/25] trace-cmd library: Handle the extended DONE option Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 20/25] trace-cmd library: Initialize CPU data for reading from version 7 trace files Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 21/25] trace-cmd library: Handle latency trace in version 7 files Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 22/25] trace-cmd library: Handle buffer trace data init for " Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 23/25] trace-cmd report: Use the new latency API to read data Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 24/25] trace-cmd: Write buffers metadata in trace files version 6 Tzvetomir Stoyanov (VMware)
2022-01-19 8:25 ` [PATCH v8 25/25] trace-cmd record: Add new parameter for trace file version 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=20220119082507.245600-5-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).