From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 01/10] trace-cmd dump: Add helpers for processing trace file version 7
Date: Mon, 13 Sep 2021 15:50:30 +0300 [thread overview]
Message-ID: <20210913125039.3680986-2-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20210913125039.3680986-1-tz.stoyanov@gmail.com>
New global variables are added, that hold trace file context:
- trace file version
- compression context
Also a few helper functions for reading compressed data.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
tracecmd/trace-dump.c | 88 ++++++++++++++++++++++++++++++++-----------
1 file changed, 67 insertions(+), 21 deletions(-)
diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c
index 2334b57e..d0278f7e 100644
--- a/tracecmd/trace-dump.c
+++ b/tracecmd/trace-dump.c
@@ -26,6 +26,9 @@
static struct tep_handle *tep;
static unsigned int trace_cpus;
static int has_clock;
+static unsigned long file_version;
+static bool read_compress;
+static struct tracecmd_compression *compress;
enum dump_items {
SUMMARY = (1 << 0),
@@ -52,46 +55,69 @@ enum dump_items verbosity;
tracecmd_plog(fmt, ##__VA_ARGS__); \
} while (0)
-static int read_file_string(int fd, char *dst, int len)
+static int read_fd(int fd, char *dst, int len)
{
size_t size = 0;
int r;
do {
- r = read(fd, dst+size, 1);
+ r = read(fd, dst+size, len);
if (r > 0) {
- size++;
- len--;
+ size += r;
+ len -= r;
} else
break;
- if (!dst[size - 1])
- break;
- } while (r > 0 && len);
+ } while (r > 0);
- if (!size || dst[size - 1])
+ if (len)
return -1;
- return 0;
+ return size;
}
-static int read_file_bytes(int fd, char *dst, int len)
+static int read_compressed(int fd, char *dst, int len)
+{
+
+ if (read_compress)
+ return tracecmd_compress_read(compress, dst, len);
+ return read_fd(fd, dst, len);
+}
+
+static int do_lseek(int fd, int offset, int whence)
+{
+ if (read_compress)
+ return tracecmd_compress_lseek(compress, offset, whence);
+ return lseek64(fd, offset, whence);
+}
+
+static int read_file_string(int fd, char *dst, int len)
{
size_t size = 0;
int r;
do {
- r = read(fd, dst+size, len);
+ r = read_compressed(fd, dst+size, 1);
if (r > 0) {
- size += r;
- len -= r;
+ size++;
+ len--;
} else
break;
- } while (r > 0);
+ if (!dst[size - 1])
+ break;
+ } while (r > 0 && len);
- if (len)
+ if (!size || dst[size - 1])
return -1;
return 0;
}
+static int read_file_bytes(int fd, char *dst, int len)
+{
+ int ret;
+
+ ret = read_compressed(fd, dst, len);
+ return ret < 0 ? ret : 0;
+}
+
static void read_dump_string(int fd, int size, enum dump_items id)
{
char buf[DUMP_SIZE];
@@ -146,7 +172,6 @@ static void dump_initial_format(int fd)
char magic[] = TRACECMD_MAGIC;
char buf[DUMP_SIZE];
int val4;
- unsigned long ver;
do_print(SUMMARY, "\t[Initial format]\n");
@@ -168,11 +193,11 @@ static void dump_initial_format(int fd)
die("no version string");
do_print(SUMMARY, "\t\t%s\t[Version]\n", buf);
- ver = strtol(buf, NULL, 10);
- if (!ver && errno)
+ file_version = strtol(buf, NULL, 10);
+ if (!file_version && errno)
die("Invalid file version string %s", buf);
- if (!tracecmd_is_version_supported(ver))
- die("Unsupported file version %lu", ver);
+ if (!tracecmd_is_version_supported(file_version))
+ die("Unsupported file version %lu", file_version);
/* get file endianness*/
if (read_file_bytes(fd, buf, 1))
@@ -234,6 +259,27 @@ static void dump_header_event(int fd)
read_dump_string(fd, size, HEAD_EVENT);
}
+static void uncompress_reset(void)
+{
+ if (compress && file_version >= FILE_VERSION_COMPRESSION) {
+ read_compress = false;
+ tracecmd_compress_reset(compress);
+ }
+}
+
+static int uncompress_block(void)
+{
+ int ret = 0;
+
+ if (compress && file_version >= FILE_VERSION_COMPRESSION) {
+ ret = tracecmd_uncompress_block(compress);
+ if (!ret)
+ read_compress = true;
+
+ }
+ return ret;
+}
+
static void dump_ftrace_events_format(int fd)
{
unsigned long long size;
@@ -578,7 +624,7 @@ static void dump_options(int fd)
default:
do_print(OPTIONS, " %d %d\t[Unknown option, size - skipping]\n",
option, size);
- lseek64(fd, size, SEEK_CUR);
+ do_lseek(fd, size, SEEK_CUR);
break;
}
}
--
2.31.1
next prev parent reply other threads:[~2021-09-13 12:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 12:50 [PATCH 00/10] trace-cmd dump - v7 update Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` Tzvetomir Stoyanov (VMware) [this message]
2021-09-13 12:50 ` [PATCH 02/10] trace-cmd dump: Print compression header Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 03/10] trace-cmd dump: Add helpers for processing trace file sections Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 04/10] trace-cmd dump: Read recursively all options sections Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 05/10] trace-cmd dump: Read extended BUFFER option Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 06/10] trace-cmd dump: Dump sections Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 07/10] trace-cmd dump: Dump trace file version 7 Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 08/10] trace-cmd dump: Dump sections content Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 09/10] trace-cmd dump: Add new argument --sections Tzvetomir Stoyanov (VMware)
2021-09-13 12:50 ` [PATCH 10/10] trace-cmd dump: Align better the output of flyrecord dump 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=20210913125039.3680986-2-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).