From patchwork Wed Jan 26 09:53:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12724860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD02CC28CF5 for ; Wed, 26 Jan 2022 09:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232830AbiAZJxo (ORCPT ); Wed, 26 Jan 2022 04:53:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxo (ORCPT ); Wed, 26 Jan 2022 04:53:44 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 393ADC06161C for ; Wed, 26 Jan 2022 01:53:44 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id m11so68072403edi.13 for ; Wed, 26 Jan 2022 01:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+FpDcHF6iMAWnRVXsjOkW4hlSmtQYvc7XXKJ2T2TU1s=; b=QM8CwkhMqclTHvNpiI3bOi7T8Z+rqcBVyrHEKG2K5XK6FoxzpeXouiCUQBWmSNDgaL AucIpQRHkXzCqK6uFJv1ArFwMxJ7Vv7ncWYr/l9ahgaa13sDhozgFmX4YOwbSR1KpQmN +f8Fc7AMdQsD3u9NgGbFPiGdItumCZeDY/XbCQq0+sO4SiqbimAdAbLs/QEVd/uLWFyH VuDU83yqCnuaOE7lxTAhKlU75cGL/hrGAz8S5wXHUgmWcaBJdq4VNZRRaBlBBhHKn7h3 NquC5UMIwWANaIJQHiu+U6UxFjWdAUNQ5JUJ0jk/2gRrepqIkqQ6nZ1jJGJlxi7bcIpn gUBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+FpDcHF6iMAWnRVXsjOkW4hlSmtQYvc7XXKJ2T2TU1s=; b=h5Jm7UrsF153ypClIxBUhtq9vZCGYIVUTcqvAATMX5Wz6A9+meOSWZ+fKP3f7sk9jn bbrRZb8Ut1hz7kee3u23O60x57a+6mZLj2qyGWexO3PTlpyWgy/k0xfO/AP5q1AXiQkW jQ/aPMMSBU8cdfTlNrjIAlSvVVEHeu1KIbxSxexi6oBY1W6XOBpgOBhYt0GYyYJhH08e 9zGLVEN1dgVseA76Q6oU7/1ESe1X0bF0xi7sZU0QWUFQEGqeZ+G2Q0lNAfhVk0hs3ad9 ZrGtbmPImgJGQZmhgkJ2dxjiILmtSi0weQctak9o/AtVtvGh1+67+CJTn0L2VQy2LxJw 1Hew== X-Gm-Message-State: AOAM5314TMbMdOOA+ccm0gE0RuZfT1R8XWtU1t0NQ6zaKXe26LdLu/iV 2iZ7j7mRr10SXOtziNTKD++6IGRU8YI= X-Google-Smtp-Source: ABdhPJy0+MUJeNK4jsNjbZTajQj2k1H42OvXNmBMstFpTHYhsWwbnPjHjiv4ph7dBBn168mQ2veDUQ== X-Received: by 2002:a50:9511:: with SMTP id u17mr25047451eda.380.1643190822811; Wed, 26 Jan 2022 01:53:42 -0800 (PST) Received: from oberon.zico.biz ([151.251.254.11]) by smtp.gmail.com with ESMTPSA id h19sm3177266edv.90.2022.01.26.01.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:42 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 01/11] trace-cmd dump: Add helpers for processing trace file version 7 Date: Wed, 26 Jan 2022 11:53:27 +0200 Message-Id: <20220126095337.570867-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220126095337.570867-1-tz.stoyanov@gmail.com> References: <20220126095337.570867-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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) --- tracecmd/trace-dump.c | 91 +++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 2408a4ab..a99dbded 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,71 @@ 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_buffer_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 +174,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 +195,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 +261,28 @@ 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; @@ -623,7 +672,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; } }