From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 03/20] trace-cmd library: Internal helpers for uncompressing data
Date: Mon, 13 Sep 2021 15:41:46 +0300 [thread overview]
Message-ID: <20210913124203.3677760-4-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210913124203.3677760-1-tz.stoyanov@gmail.com>
New library internal helper functions are introduced, to add compression
functionality to the input trace handler.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/include/trace-cmd-local.h | 3 ++
lib/trace-cmd/trace-input.c | 49 ++++++++++++++++++++++---
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h
index 304bec49..14223a08 100644
--- a/lib/trace-cmd/include/trace-cmd-local.h
+++ b/lib/trace-cmd/include/trace-cmd-local.h
@@ -45,6 +45,9 @@ 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);
+void in_uncompress_reset(struct tracecmd_input *handle);
+int in_uncompress_block(struct tracecmd_input *handle);
+
unsigned long long
out_write_section_header(struct tracecmd_output *handle, unsigned short header_id,
char *description, enum tracecmd_section_flags flags, bool option);
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index b7d78a3a..25d376f7 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -155,6 +155,9 @@ struct tracecmd_input {
long long ts_offset;
struct tsc2nsec tsc_calc;
+ bool read_compress;
+ struct tracecmd_compression *compress;
+
struct host_trace_info host;
double ts2secs;
unsigned int cpustats_size;
@@ -262,13 +265,13 @@ static const char *show_records(struct page **pages, int nr_pages)
static int init_cpu(struct tracecmd_input *handle, int cpu);
-static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size)
+static ssize_t do_read_fd(int fd, void *data, size_t size)
{
ssize_t tot = 0;
ssize_t r;
do {
- r = read(handle->fd, data + tot, size - tot);
+ r = read(fd, data + tot, size - tot);
tot += r;
if (!r)
@@ -280,6 +283,22 @@ static ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size)
return tot;
}
+static inline int do_lseek(struct tracecmd_input *handle, int offset, int whence)
+{
+ if (handle->read_compress)
+ return tracecmd_compress_lseek(handle->compress, offset, whence);
+ else
+ return lseek(handle->fd, offset, whence);
+}
+
+static inline ssize_t do_read(struct tracecmd_input *handle, void *data, size_t size)
+{
+ if (handle->read_compress)
+ return tracecmd_compress_read(handle->compress, data, size);
+ else
+ return do_read_fd(handle->fd, data, size);
+}
+
static ssize_t
do_read_check(struct tracecmd_input *handle, void *data, size_t size)
{
@@ -304,9 +323,7 @@ static char *read_string(struct tracecmd_input *handle)
for (;;) {
r = do_read(handle, buf, BUFSIZ);
- if (r < 0)
- goto fail;
- if (!r)
+ if (r <= 0)
goto fail;
for (i = 0; i < r; i++) {
@@ -332,7 +349,7 @@ static char *read_string(struct tracecmd_input *handle)
}
/* move the file descriptor to the end of the string */
- r = lseek(handle->fd, -(r - (i+1)), SEEK_CUR);
+ r = do_lseek(handle, -(r - (i+1)), SEEK_CUR);
if (r < 0)
goto fail;
@@ -396,6 +413,26 @@ static int read8(struct tracecmd_input *handle, unsigned long long *size)
return 0;
}
+__hidden void in_uncompress_reset(struct tracecmd_input *handle)
+{
+ if (handle->compress) {
+ handle->read_compress = false;
+ tracecmd_compress_reset(handle->compress);
+ }
+}
+
+__hidden int in_uncompress_block(struct tracecmd_input *handle)
+{
+ int ret = 0;
+
+ if (handle->compress) {
+ ret = tracecmd_uncompress_block(handle->compress);
+ if (!ret)
+ handle->read_compress = true;
+ }
+ return ret;
+}
+
static struct file_section *section_get(struct tracecmd_input *handle, int id)
{
struct file_section *sec;
--
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 ` Tzvetomir Stoyanov (VMware) [this message]
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 ` [PATCH 07/20] trace-cmd library: Compress part of " Tzvetomir Stoyanov (VMware)
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-4-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).