From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v7 02/20] trace-cmd library: Internal helpers for compressing data
Date: Wed, 19 Jan 2022 10:26:57 +0200 [thread overview]
Message-ID: <20220119082715.245846-3-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20220119082715.245846-1-tz.stoyanov@gmail.com>
New library internal helper functions are introduced, to add compression
functionality to the output trace handler.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/include/trace-cmd-local.h | 7 ++++
lib/trace-cmd/trace-output.c | 56 +++++++++++++++++++++++--
2 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h
index d4047429..b848514e 100644
--- a/lib/trace-cmd/include/trace-cmd-local.h
+++ b/lib/trace-cmd/include/trace-cmd-local.h
@@ -42,6 +42,13 @@ void tracecmd_compress_free(void);
bool check_file_state(unsigned long file_version, int current_state, int new_state);
bool check_out_state(struct tracecmd_output *handle, int new_state);
+int out_uncompress_block(struct tracecmd_output *handle);
+int out_compression_start(struct tracecmd_output *handle, bool compress);
+int out_compression_end(struct tracecmd_output *handle, bool compress);
+void out_compression_reset(struct tracecmd_output *handle, bool compress);
+unsigned long long out_copy_fd_compress(struct tracecmd_output *handle,
+ int fd, unsigned long long max,
+ unsigned long long *write_size);
unsigned long long
out_write_section_header(struct tracecmd_output *handle, unsigned short header_id,
char *description, int flags, bool option);
diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c
index 15baef8f..2b944913 100644
--- a/lib/trace-cmd/trace-output.c
+++ b/lib/trace-cmd/trace-output.c
@@ -70,6 +70,8 @@ struct tracecmd_output {
unsigned long long options_start;
bool big_endian;
+ bool do_compress;
+ struct tracecmd_compression *compress;
struct list_head options;
struct list_head buffers;
@@ -100,18 +102,27 @@ 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)
{
+ if (handle->do_compress)
+ return tracecmd_compress_write(handle->compress, data, size);
if (handle->msg_handle)
return tracecmd_msg_data_send(handle->msg_handle, data, size);
-
return __do_write_check(handle->fd, data, size);
}
static inline off64_t do_lseek(struct tracecmd_output *handle, off_t offset, int whence)
{
+ if (handle->do_compress)
+ return tracecmd_compress_lseek(handle->compress, offset, whence);
if (handle->msg_handle)
return msg_lseek(handle->msg_handle, offset, whence);
- else
- return lseek64(handle->fd, offset, whence);
+ return lseek64(handle->fd, offset, whence);
+}
+
+static inline int do_preed(struct tracecmd_output *handle, void *dst, int len, off_t offset)
+{
+ if (handle->do_compress)
+ return tracecmd_compress_pread(handle->compress, dst, len, offset);
+ return pread(handle->fd, dst, len, offset);
}
static short convert_endian_2(struct tracecmd_output *handle, short val)
@@ -139,6 +150,43 @@ static unsigned long long convert_endian_8(struct tracecmd_output *handle,
return tep_read_number(handle->pevent, &val, 8);
}
+__hidden void out_compression_reset(struct tracecmd_output *handle, bool compress)
+{
+ if (!compress || !handle->compress)
+ return;
+ tracecmd_compress_reset(handle->compress);
+ handle->do_compress = false;
+}
+
+__hidden int out_uncompress_block(struct tracecmd_output *handle)
+{
+ int ret = 0;
+
+ if (!handle->compress)
+ return 0;
+ ret = tracecmd_uncompress_block(handle->compress);
+ if (!ret)
+ handle->do_compress = true;
+ return ret;
+}
+
+__hidden int out_compression_start(struct tracecmd_output *handle, bool compress)
+{
+ if (!compress || !handle->compress)
+ return 0;
+ tracecmd_compress_reset(handle->compress);
+ handle->do_compress = true;
+ return 0;
+}
+
+__hidden int out_compression_end(struct tracecmd_output *handle, bool compress)
+{
+ if (!compress || !handle->compress)
+ return 0;
+ handle->do_compress = false;
+ return tracecmd_compress_block(handle->compress);
+}
+
static long add_string(struct tracecmd_output *handle, const char *string)
{
int size = strlen(string) + 1;
@@ -1645,7 +1693,7 @@ static int append_options_v6(struct tracecmd_output *handle)
if (offset == (off_t)-1)
return -1;
- r = pread(handle->fd, &option, 2, offset);
+ r = do_preed(handle, &option, 2, offset);
if (r != 2 || option != TRACECMD_OPTION_DONE)
return -1;
--
2.34.1
next prev parent reply other threads:[~2022-01-19 8:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-19 8:26 [PATCH v7 00/20] Trace file version 7 - compression Tzvetomir Stoyanov (VMware)
2022-01-19 8:26 ` [PATCH v7 01/20] trace-cmd library: Add support for compression algorithms Tzvetomir Stoyanov (VMware)
2022-01-23 22:48 ` Steven Rostedt
2022-01-24 4:54 ` Tzvetomir Stoyanov
2022-01-24 20:03 ` Steven Rostedt
2022-01-24 21:24 ` Steven Rostedt
2022-01-25 7:48 ` Tzvetomir Stoyanov
2022-01-25 15:08 ` Steven Rostedt
2022-01-25 17:30 ` Tzvetomir Stoyanov
2022-01-26 4:56 ` Tzvetomir Stoyanov
2022-01-26 14:16 ` Steven Rostedt
2022-01-19 8:26 ` Tzvetomir Stoyanov (VMware) [this message]
2022-01-19 8:26 ` [PATCH v7 03/20] trace-cmd library: Internal helpers for uncompressing data Tzvetomir Stoyanov (VMware)
2022-01-19 8:26 ` [PATCH v7 04/20] trace-cmd library: Inherit compression algorithm from input file Tzvetomir Stoyanov (VMware)
2022-01-24 19:22 ` Steven Rostedt
2022-01-19 8:27 ` [PATCH v7 05/20] trace-cmd library: New API to configure compression on an output handler Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 06/20] trace-cmd library: Write compression header in the trace file Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 07/20] trace-cmd library: Compress part of " Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 08/20] trace-cmd library: Add local helper function for data compression Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 09/20] trace-cmd library: Compress the trace data Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 10/20] trace-cmd library: Decompress the options section, if it is compressed Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 11/20] trace-cmd library: Read compression header Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 12/20] trace-cmd library: Extend the input handler with trace data decompression context Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 13/20] trace-cmd library: Initialize CPU data decompression logic Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 14/20] trace-cmd library: Add logic for in-memory decompression Tzvetomir Stoyanov (VMware)
2022-01-25 18:30 ` Steven Rostedt
2022-01-19 8:27 ` [PATCH v7 15/20] trace-cmd library: Read compressed latency data Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 16/20] trace-cmd library: Decompress file sections on reading Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 17/20] trace-cmd library: Add zlib compression algorithm Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 18/20] trace-cmd list: Show supported compression algorithms Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 19/20] trace-cmd record: Add compression to the trace context Tzvetomir Stoyanov (VMware)
2022-01-19 8:27 ` [PATCH v7 20/20] trace-cmd report: Add new parameter for trace file compression Tzvetomir Stoyanov (VMware)
2022-01-25 18:39 ` [PATCH v7 00/20] Trace file version 7 - compression Steven Rostedt
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=20220119082715.245846-3-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).