From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 07/20] trace-cmd library: Compress part of the trace file
Date: Mon, 13 Sep 2021 15:41:50 +0300 [thread overview]
Message-ID: <20210913124203.3677760-8-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210913124203.3677760-1-tz.stoyanov@gmail.com>
Compress part of the trace.dat file metadata. If there is compression
support, compress these parts of the file:
- ftrace events format
- format of recorded events
- information of the mapping of function addresses to the function names
- trace_printk() format strings
- information of the mapping a PID to a process name
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-output.c | 81 +++++++++++++++++++++++++++++-------
1 file changed, 67 insertions(+), 14 deletions(-)
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index c979a6ed..1c6e9728 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -394,6 +394,8 @@ out_write_section_header(struct tracecmd_output *handle, unsigned short header_i
return -1;
if (!HAS_SECTIONS(handle))
return 0;
+ if (!handle->compress)
+ flags &= ~TRACECMD_SEC_FL_COMPRESS;
offset = do_lseek(handle, 0, SEEK_CUR);
if (option) {
endian8 = convert_endian_8(handle, offset);
@@ -449,7 +451,7 @@ __hidden int out_update_section_header(struct tracecmd_output *handle, unsigned
return 0;
}
-static int read_header_files(struct tracecmd_output *handle)
+static int read_header_files(struct tracecmd_output *handle, bool compress)
{
enum tracecmd_section_flags flags = 0;
tsize_t size, check_size, endian8;
@@ -469,11 +471,14 @@ static int read_header_files(struct tracecmd_output *handle)
if (!path)
return -1;
+ if (compress)
+ flags |= TRACECMD_SEC_FL_COMPRESS;
offset = out_write_section_header(handle, TRACECMD_OPTION_HEADER_INFO,
"headers", flags, true);
if (offset == (off64_t)-1)
return -1;
+ out_compression_start(handle, compress);
ret = stat(path, &st);
if (ret < 0) {
/* old style did not show this info, just add zero */
@@ -487,6 +492,8 @@ static int read_header_files(struct tracecmd_output *handle)
goto out_close;
if (do_write_check(handle, &size, 8))
goto out_close;
+ if (out_compression_end(handle, compress))
+ goto out_close;
if (out_update_section_header(handle, offset))
goto out_close;
return 0;
@@ -539,6 +546,8 @@ static int read_header_files(struct tracecmd_output *handle)
goto out_close;
}
put_tracing_file(path);
+ if (out_compression_end(handle, compress))
+ goto out_close;
if (out_update_section_header(handle, offset))
goto out_close;
handle->file_state = TRACECMD_FILE_HEADERS;
@@ -546,6 +555,7 @@ static int read_header_files(struct tracecmd_output *handle)
return 0;
out_close:
+ out_compression_reset(handle, compress);
if (fd >= 0)
close(fd);
return -1;
@@ -774,7 +784,7 @@ create_event_list_item(struct tracecmd_output *handle,
tracecmd_warning("Insufficient memory");
}
-static int read_ftrace_files(struct tracecmd_output *handle)
+static int read_ftrace_files(struct tracecmd_output *handle, bool compress)
{
enum tracecmd_section_flags flags = 0;
struct list_event_system *systems = NULL;
@@ -788,15 +798,20 @@ static int read_ftrace_files(struct tracecmd_output *handle)
return -1;
}
+ if (compress)
+ flags |= TRACECMD_SEC_FL_COMPRESS;
offset = out_write_section_header(handle, TRACECMD_OPTION_FTRACE_EVENTS,
"ftrace events", flags, true);
if (offset == (off64_t)-1)
return -1;
create_event_list_item(handle, &systems, &list);
-
+ out_compression_start(handle, compress);
ret = copy_event_system(handle, systems);
-
+ if (!ret)
+ ret = out_compression_end(handle, compress);
+ else
+ out_compression_reset(handle, compress);
free_list_events(systems);
if (ret)
return ret;
@@ -822,7 +837,7 @@ create_event_list(struct tracecmd_output *handle,
}
static int read_event_files(struct tracecmd_output *handle,
- struct tracecmd_event_list *event_list)
+ struct tracecmd_event_list *event_list, bool compress)
{
enum tracecmd_section_flags flags = 0;
struct list_event_system *systems;
@@ -840,6 +855,8 @@ static int read_event_files(struct tracecmd_output *handle,
return -1;
}
+ if (compress)
+ flags |= TRACECMD_SEC_FL_COMPRESS;
offset = out_write_section_header(handle, TRACECMD_OPTION_EVENT_FORMATS,
"events format", flags, true);
if (offset == (off64_t)-1)
@@ -860,7 +877,7 @@ static int read_event_files(struct tracecmd_output *handle,
for (slist = systems; slist; slist = slist->next)
count++;
-
+ out_compression_start(handle, compress);
ret = -1;
endian4 = convert_endian_4(handle, count);
if (do_write_check(handle, &endian4, 4))
@@ -875,6 +892,9 @@ static int read_event_files(struct tracecmd_output *handle,
}
ret = copy_event_system(handle, slist);
}
+ if (ret)
+ goto out_free;
+ ret = out_compression_end(handle, compress);
if (ret)
goto out_free;
ret = out_update_section_header(handle, offset);
@@ -882,6 +902,8 @@ static int read_event_files(struct tracecmd_output *handle,
out_free:
if (!ret)
handle->file_state = TRACECMD_FILE_ALL_EVENTS;
+ else
+ out_compression_reset(handle, compress);
free_list_events(systems);
@@ -928,7 +950,7 @@ err:
tracecmd_warning("can't set kptr_restrict");
}
-static int read_proc_kallsyms(struct tracecmd_output *handle)
+static int read_proc_kallsyms(struct tracecmd_output *handle, bool compress)
{
enum tracecmd_section_flags flags = 0;
unsigned int size, check_size, endian4;
@@ -946,11 +968,14 @@ static int read_proc_kallsyms(struct tracecmd_output *handle)
if (handle->kallsyms)
path = handle->kallsyms;
+ if (compress)
+ flags |= TRACECMD_SEC_FL_COMPRESS;
offset = out_write_section_header(handle, TRACECMD_OPTION_KALLSYMS,
"kallsyms", flags, true);
if (offset == (off64_t)-1)
return -1;
+ out_compression_start(handle, compress);
ret = stat(path, &st);
if (ret < 0) {
/* not found */
@@ -976,14 +1001,19 @@ static int read_proc_kallsyms(struct tracecmd_output *handle)
}
set_proc_kptr_restrict(1);
+ ret = out_compression_end(handle, compress);
+ if (ret)
+ goto out;
ret = out_update_section_header(handle, offset);
out:
if (!ret)
handle->file_state = TRACECMD_FILE_KALLSYMS;
+ else
+ out_compression_reset(handle, compress);
return ret;
}
-static int read_ftrace_printk(struct tracecmd_output *handle)
+static int read_ftrace_printk(struct tracecmd_output *handle, bool compress)
{
enum tracecmd_section_flags flags = 0;
unsigned int size, check_size, endian4;
@@ -1002,10 +1032,13 @@ static int read_ftrace_printk(struct tracecmd_output *handle)
if (!path)
return -1;
+ if (compress)
+ flags |= TRACECMD_SEC_FL_COMPRESS;
offset = out_write_section_header(handle, TRACECMD_OPTION_PRINTK, "printk", flags, true);
if (offset == (off64_t)-1)
return -1;
+ out_compression_start(handle, compress);
ret = stat(path, &st);
if (ret < 0) {
/* not found */
@@ -1028,12 +1061,15 @@ static int read_ftrace_printk(struct tracecmd_output *handle)
out:
put_tracing_file(path);
+ if (out_compression_end(handle, compress))
+ return -1;
if (out_update_section_header(handle, offset))
return -1;
handle->file_state = TRACECMD_FILE_PRINTK;
return 0;
fail:
put_tracing_file(path);
+ out_compression_reset(handle, compress);
return -1;
}
@@ -1414,21 +1450,25 @@ int tracecmd_output_write_init(struct tracecmd_output *handler)
int tracecmd_output_write_headers(struct tracecmd_output *handler,
struct tracecmd_event_list *list)
{
+ bool compress = false;
+
if (!handler || handler->file_state < TRACECMD_FILE_ALLOCATED)
return -1;
/* Write init data, if not written yet */
if (handler->file_state < TRACECMD_FILE_INIT && tracecmd_output_write_init(handler))
return -1;
- if (read_header_files(handler))
+ if (handler->compress)
+ compress = true;
+ if (read_header_files(handler, compress))
return -1;
- if (read_ftrace_files(handler))
+ if (read_ftrace_files(handler, compress))
return -1;
- if (read_event_files(handler, list))
+ if (read_event_files(handler, list, compress))
return -1;
- if (read_proc_kallsyms(handler))
+ if (read_proc_kallsyms(handler, compress))
return -1;
- if (read_ftrace_printk(handler))
+ if (read_ftrace_printk(handler, compress))
return -1;
return 0;
}
@@ -1799,6 +1839,7 @@ static tsize_t get_buffer_file_offset(struct tracecmd_output *handle, const char
int tracecmd_write_cmdlines(struct tracecmd_output *handle)
{
enum tracecmd_section_flags flags = 0;
+ bool compress = false;
tsize_t offset;
int ret;
@@ -1808,14 +1849,26 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle)
return -1;
}
+ if (handle->compress)
+ compress = true;
+
+ if (compress)
+ flags |= TRACECMD_SEC_FL_COMPRESS;
offset = out_write_section_header(handle, TRACECMD_OPTION_CMDLINES,
"command lines", flags, true);
if (offset == (off64_t)-1)
return -1;
+ out_compression_start(handle, compress);
+
ret = save_tracing_file_data(handle, "saved_cmdlines");
- if (ret < 0)
+ if (ret < 0) {
+ out_compression_reset(handle, compress);
return ret;
+ }
+
+ if (out_compression_end(handle, compress))
+ return -1;
if (out_update_section_header(handle, offset))
return -1;
--
2.31.1
next prev parent reply other threads:[~2021-09-13 12:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 12:41 [PATCH 00/20] Trace file version 7 - compression Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 01/20] trace-cmd library: Add support for compression algorithms Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 02/20] trace-cmd library: Internal helpers for compressing data Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 03/20] trace-cmd library: Internal helpers for uncompressing data Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 04/20] trace-cmd library: Inherit compression algorithm from input file Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 05/20] trace-cmd library: New API to configure compression on an output handler Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 06/20] trace-cmd library: Write compression header in the trace file Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` Tzvetomir Stoyanov (VMware) [this message]
2021-09-13 12:41 ` [PATCH 08/20] trace-cmd library: Add local helper function for data compression Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 09/20] trace-cmd library: Compress the trace data Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 10/20] trace-cmd library: Decompress the options section, if it is compressed Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 11/20] trace-cmd library: Read compression header Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 12/20] trace-cmd library: Extend the input handler with trace data decompression context Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 13/20] trace-cmd library: Initialize CPU data decompression logic Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 14/20] trace-cmd library: Add logic for in-memory decompression Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 15/20] trace-cmd library: Read compressed latency data Tzvetomir Stoyanov (VMware)
2021-09-13 12:41 ` [PATCH 16/20] trace-cmd library: Decompress file sections on reading Tzvetomir Stoyanov (VMware)
2021-09-13 12:42 ` [PATCH 17/20] trace-cmd library: Add zlib compression algorithm Tzvetomir Stoyanov (VMware)
2021-09-13 12:42 ` [PATCH 18/20] trace-cmd list: Show supported compression algorithms Tzvetomir Stoyanov (VMware)
2021-09-13 12:42 ` [PATCH 19/20] trace-cmd record: Add compression to the trace context Tzvetomir Stoyanov (VMware)
2021-09-13 12:42 ` [PATCH 20/20] trace-cmd report: Add new parameter for trace file compression 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=20210913124203.3677760-8-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).