From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v8 15/20] trace-cmd library: Read compressed latency data
Date: Wed, 26 Jan 2022 11:49:01 +0200 [thread overview]
Message-ID: <20220126094906.570451-16-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20220126094906.570451-1-tz.stoyanov@gmail.com>
Extended the latency read logic for reading comperssed latency trace
data. Both decompressing approaches are supported: in-memory and
using temporary file.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-input.c | 77 +++++++++++++++++++++++++++++++++----
1 file changed, 70 insertions(+), 7 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index c52aa951..7d8f0fe4 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -177,6 +177,7 @@ struct tracecmd_input {
bool cpu_compressed;
int file_version;
unsigned int cpustats_size;
+ struct cpu_zdata latz;
struct cpu_data *cpu_data;
long long ts_offset;
struct tsc2nsec tsc_calc;
@@ -3485,20 +3486,55 @@ static int read_options_type(struct tracecmd_input *handle)
int tracecmd_latency_data_read(struct tracecmd_input *handle, char **buf, size_t *size)
{
+ struct cpu_zdata *zdata = &handle->latz;
+ void *data;
+ int rsize;
+ int fd = -1;
+ int id;
+
if (!handle || !buf || !size)
return -1;
if (handle->file_state != TRACECMD_FILE_CPU_LATENCY)
return -1;
+ if (!handle->cpu_compressed) {
+ fd = handle->fd;
+ } else if (!handle->read_zpage) {
+ if (zdata->fd < 0)
+ return -1;
+ fd = zdata->fd;
+ }
+
/* Read data from a file */
- if (!(*buf)) {
- *size = BUFSIZ;
- *buf = malloc(*size);
- if (!(*buf))
+ if (fd >= 0) {
+ if (!(*buf)) {
+ *size = BUFSIZ;
+ *buf = malloc(*size);
+ if (!(*buf))
+ return -1;
+ }
+ return do_read_fd(fd, *buf, *size);
+ }
+
+ /* Uncompress data in memory */
+ if (zdata->last_chunk >= zdata->count)
+ return 0;
+
+ id = zdata->last_chunk;
+ if (!*buf || *size < zdata->chunks[id].size) {
+ data = realloc(*buf, zdata->chunks[id].size);
+ if (!data)
return -1;
+ *buf = data;
+ *size = zdata->chunks[id].size;
}
- return do_read(handle, *buf, *size);
+ if (tracecmd_uncompress_chunk(handle->compress, &zdata->chunks[id], *buf))
+ return -1;
+
+ rsize = zdata->chunks[id].size;
+ zdata->last_chunk++;
+ return rsize;
}
static int init_cpu_data(struct tracecmd_input *handle)
@@ -3566,7 +3602,29 @@ static int init_cpu_data(struct tracecmd_input *handle)
int init_latency_data(struct tracecmd_input *handle)
{
- /* To do */
+ unsigned long long wsize;
+ int ret;
+
+ if (!handle->cpu_compressed)
+ return 0;
+
+ if (handle->read_zpage) {
+ handle->latz.count = tracecmd_load_chunks_info(handle->compress, &handle->latz.chunks);
+ if (handle->latz.count < 0)
+ return -1;
+ } else {
+ strcpy(handle->latz.file, COMPR_TEMP_FILE);
+ handle->latz.fd = mkstemp(handle->latz.file);
+ if (handle->latz.fd < 0)
+ return -1;
+
+ ret = tracecmd_uncompress_copy_to(handle->compress, handle->latz.fd, NULL, &wsize);
+ if (ret)
+ return -1;
+
+ lseek64(handle->latz.fd, 0, SEEK_SET);
+ }
+
return 0;
}
@@ -4078,6 +4136,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags)
handle->fd = fd;
handle->ref = 1;
+ handle->latz.fd = -1;
/* By default, use usecs, unless told otherwise */
handle->flags |= TRACECMD_FL_IN_USECS;
@@ -4372,7 +4431,11 @@ void tracecmd_close(struct tracecmd_input *handle)
free(handle->strings);
free(handle->version);
close(handle->fd);
-
+ free(handle->latz.chunks);
+ if (handle->latz.fd >= 0) {
+ close(handle->latz.fd);
+ unlink(handle->latz.file);
+ }
while (handle->sections) {
del_sec = handle->sections;
handle->sections = handle->sections->next;
--
2.34.1
next prev parent reply other threads:[~2022-01-26 9:49 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 9:48 [PATCH v8 00/20] Trace file version 7 - compression Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 01/20] trace-cmd library: Add support for compression algorithms Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 02/20] trace-cmd library: Internal helpers for compressing data Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 03/20] trace-cmd library: Internal helpers for uncompressing data Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 04/20] trace-cmd library: Inherit compression algorithm from input file Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 05/20] trace-cmd library: New API to configure compression on an output handler Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 06/20] trace-cmd library: Write compression header in the trace file Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 07/20] trace-cmd library: Compress part of " Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 08/20] trace-cmd library: Add local helper function for data compression Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 09/20] trace-cmd library: Compress the trace data Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 10/20] trace-cmd library: Decompress the options section, if it is compressed Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 11/20] trace-cmd library: Read compression header Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 12/20] trace-cmd library: Extend the input handle with trace data decompression context Tzvetomir Stoyanov (VMware)
2022-01-26 9:48 ` [PATCH v8 13/20] trace-cmd library: Initialize CPU data decompression logic Tzvetomir Stoyanov (VMware)
2022-01-26 9:49 ` [PATCH v8 14/20] trace-cmd library: Add logic for in-memory decompression Tzvetomir Stoyanov (VMware)
2022-01-26 9:49 ` Tzvetomir Stoyanov (VMware) [this message]
2022-01-26 9:49 ` [PATCH v8 16/20] trace-cmd library: Decompress file sections on reading Tzvetomir Stoyanov (VMware)
2022-01-26 9:49 ` [PATCH v8 17/20] trace-cmd library: Add zlib compression algorithm Tzvetomir Stoyanov (VMware)
2022-01-26 9:49 ` [PATCH v8 18/20] trace-cmd list: Show supported compression algorithms Tzvetomir Stoyanov (VMware)
2022-01-26 9:49 ` [PATCH v8 19/20] trace-cmd record: Add compression to the trace context Tzvetomir Stoyanov (VMware)
2022-01-26 9:49 ` [PATCH v8 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=20220126094906.570451-16-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).