From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH v2 12/20] trace-cmd library: Extend the input handler with trace data decompression context
Date: Tue, 14 Sep 2021 16:16:37 +0300 [thread overview]
Message-ID: <20210914131645.3966308-13-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210914131645.3966308-1-tz.stoyanov@gmail.com>
The CPU trace data is compressed in chunks, as chunk's size is multiple
trace pages. The input handler is extended with the necessary
structures, to control the data decompression. There are two approaches
for data decompression, both are supported and can be used in different
use cases:
- in-memory decompression, page by page.
- using a temporary file
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
lib/trace-cmd/trace-input.c | 59 ++++++++++++++++++++++++++++++-------
1 file changed, 48 insertions(+), 11 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index d4728c86..658855a5 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -54,6 +54,24 @@ struct page {
#endif
};
+struct zchunk_cache {
+ struct list_head list;
+ struct tracecmd_compress_chunk *chunk;
+ void *map;
+ int ref;
+};
+
+struct cpu_zdata {
+ /* uncompressed cpu data */
+ int fd;
+ char file[26]; /* strlen(COMPR_TEMP_FILE) */
+ unsigned int count;
+ unsigned int last_chunk;
+ struct list_head cache;
+ struct tracecmd_compress_chunk *chunks;
+};
+
+#define COMPR_TEMP_FILE "/tmp/trace_cpu_dataXXXXXX"
struct cpu_data {
/* the first two never change */
unsigned long long file_offset;
@@ -72,6 +90,7 @@ struct cpu_data {
int page_cnt;
int cpu;
int pipe_fd;
+ struct cpu_zdata compress;
};
struct cpu_file_data {
@@ -150,6 +169,8 @@ struct tracecmd_input {
bool use_trace_clock;
bool read_page;
bool use_pipe;
+ bool read_zpage; /* uncompress pages in memory, do not use tmp files */
+ bool cpu_compressed;
int file_version;
struct cpu_data *cpu_data;
long long ts_offset;
@@ -3302,6 +3323,7 @@ static int init_cpu_data(struct tracecmd_input *handle)
endian = KBUFFER_ENDIAN_LITTLE;
for (cpu = 0; cpu < handle->cpus; cpu++) {
+ handle->cpu_data[cpu].compress.fd = -1;
handle->cpu_data[cpu].kbuf = kbuffer_alloc(long_size, endian);
if (!handle->cpu_data[cpu].kbuf)
goto out_free;
@@ -4043,6 +4065,7 @@ static inline void free_buffer(struct input_buffer_instance *buf)
*/
void tracecmd_close(struct tracecmd_input *handle)
{
+ struct zchunk_cache *cache;
struct file_section *del_sec;
int cpu;
int i;
@@ -4062,17 +4085,31 @@ void tracecmd_close(struct tracecmd_input *handle)
/* The tracecmd_peek_data may have cached a record */
free_next(handle, cpu);
free_page(handle, cpu);
- if (handle->cpu_data && handle->cpu_data[cpu].kbuf) {
- kbuffer_free(handle->cpu_data[cpu].kbuf);
- if (handle->cpu_data[cpu].page_map)
- free_page_map(handle->cpu_data[cpu].page_map);
-
- if (handle->cpu_data[cpu].page_cnt)
- tracecmd_warning("%d pages still allocated on cpu %d%s",
- handle->cpu_data[cpu].page_cnt, cpu,
- show_records(handle->cpu_data[cpu].pages,
- handle->cpu_data[cpu].nr_pages));
- free(handle->cpu_data[cpu].pages);
+ if (handle->cpu_data) {
+ if (handle->cpu_data[cpu].kbuf) {
+ kbuffer_free(handle->cpu_data[cpu].kbuf);
+ if (handle->cpu_data[cpu].page_map)
+ free_page_map(handle->cpu_data[cpu].page_map);
+
+ if (handle->cpu_data[cpu].page_cnt)
+ tracecmd_warning("%d pages still allocated on cpu %d%s",
+ handle->cpu_data[cpu].page_cnt, cpu,
+ show_records(handle->cpu_data[cpu].pages,
+ handle->cpu_data[cpu].nr_pages));
+ free(handle->cpu_data[cpu].pages);
+ }
+ if (handle->cpu_data[cpu].compress.fd >= 0) {
+ close(handle->cpu_data[cpu].compress.fd);
+ unlink(handle->cpu_data[cpu].compress.file);
+ }
+ while (!list_empty(&handle->cpu_data[cpu].compress.cache)) {
+ cache = container_of(handle->cpu_data[cpu].compress.cache.next,
+ struct zchunk_cache, list);
+ list_del(&cache->list);
+ free(cache->map);
+ free(cache);
+ }
+ free(handle->cpu_data[cpu].compress.chunks);
}
}
--
2.31.1
next prev parent reply other threads:[~2021-09-14 13:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-14 13:16 [PATCH v2 00/20] Trace file version 7 - compression Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 01/20] trace-cmd library: Add support for compression algorithms Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 02/20] trace-cmd library: Internal helpers for compressing data Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 03/20] trace-cmd library: Internal helpers for uncompressing data Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 04/20] trace-cmd library: Inherit compression algorithm from input file Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 05/20] trace-cmd library: New API to configure compression on an output handler Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 06/20] trace-cmd library: Write compression header in the trace file Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 07/20] trace-cmd library: Compress part of " Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 08/20] trace-cmd library: Add local helper function for data compression Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 09/20] trace-cmd library: Compress the trace data Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 10/20] trace-cmd library: Decompress the options section, if it is compressed Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 11/20] trace-cmd library: Read compression header Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` Tzvetomir Stoyanov (VMware) [this message]
2021-09-14 13:16 ` [PATCH v2 13/20] trace-cmd library: Initialize CPU data decompression logic Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 14/20] trace-cmd library: Add logic for in-memory decompression Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 15/20] trace-cmd library: Read compressed latency data Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 16/20] trace-cmd library: Decompress file sections on reading Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 17/20] trace-cmd library: Add zlib compression algorithm Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 18/20] trace-cmd list: Show supported compression algorithms Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 19/20] trace-cmd record: Add compression to the trace context Tzvetomir Stoyanov (VMware)
2021-09-14 13:16 ` [PATCH v2 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=20210914131645.3966308-13-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.