From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 11/20] trace-cmd library: Read compression header
Date: Mon, 13 Sep 2021 15:41:54 +0300 [thread overview]
Message-ID: <20210913124203.3677760-12-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210913124203.3677760-1-tz.stoyanov@gmail.com>
Trace file version 7 introduced new mandatory compression header,
storing information about the compression algorithm used to compress the
trace file. Added code to read that header and to initialize compression
context according to it.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-input.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 320561d0..19a86269 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -189,6 +189,7 @@ __thread struct tracecmd_input *tracecmd_curr_thread_handle;
#define CHECK_READ_STATE(H, S) ((H)->file_version < FILE_VERSION_SECTIONS && (H)->file_state >= (S))
#define HAS_SECTIONS(H) ((H)->flags & TRACECMD_FL_SECTIONED)
+#define HAS_COMPRESSION(H) ((H)->flags & TRACECMD_FL_COMPRESSION)
static int read_options_type(struct tracecmd_input *handle);
@@ -3795,7 +3796,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
char test[] = TRACECMD_MAGIC;
unsigned int page_size;
size_t offset;
- char *version;
+ char *version = NULL;
+ char *zver = NULL;
+ char *zname = NULL;
char buf[BUFSIZ];
unsigned long ver;
@@ -3833,9 +3836,12 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
}
handle->file_version = ver;
free(version);
+ version = NULL;
if (handle->file_version >= FILE_VERSION_SECTIONS)
handle->flags |= TRACECMD_FL_SECTIONED;
+ if (handle->file_version >= FILE_VERSION_COMPRESSION)
+ handle->flags |= TRACECMD_FL_COMPRESSION;
if (do_read_check(handle, buf, 1))
goto failed_read;
@@ -3865,6 +3871,26 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
handle->total_file_size = lseek64(handle->fd, 0, SEEK_END);
lseek64(handle->fd, offset, SEEK_SET);
+ if (HAS_COMPRESSION(handle)) {
+ zname = read_string(handle);
+ if (!zname)
+ goto failed_read;
+ zver = read_string(handle);
+ if (!zver)
+ goto failed_read;
+ if (strcmp(zname, "none")) {
+ handle->compress = tracecmd_compress_alloc(zname, zver,
+ handle->fd,
+ handle->pevent, NULL);
+ if (!handle->compress) {
+ tracecmd_warning("Unsupported file compression %s %s", zname, zver);
+ goto failed_read;
+ }
+ }
+ free(zname);
+ free(zver);
+ }
+
if (HAS_SECTIONS(handle)) {
if (read8(handle, &(handle->options_start))) {
tracecmd_warning("Filed to read the offset of the first option section");
@@ -3877,6 +3903,9 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
return handle;
failed_read:
+ free(version);
+ free(zname);
+ free(zver);
free(handle);
return NULL;
@@ -4075,7 +4104,8 @@ void tracecmd_close(struct tracecmd_input *handle)
if (handle->flags & TRACECMD_FL_BUFFER_INSTANCE)
tracecmd_close(handle->parent);
else {
- /* Only main handle frees plugins and pevent */
+ /* Only main handle frees plugins, pevent and compression context */
+ tracecmd_compress_destroy(handle->compress);
tep_unload_plugins(handle->plugin_list, handle->pevent);
tep_free(handle->pevent);
}
--
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 ` [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 ` Tzvetomir Stoyanov (VMware) [this message]
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-12-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).