From patchwork Thu Jul 29 05:09:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12407737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09CBDC4338F for ; Thu, 29 Jul 2021 05:11:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E440260C3F for ; Thu, 29 Jul 2021 05:11:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234098AbhG2FLG (ORCPT ); Thu, 29 Jul 2021 01:11:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234079AbhG2FLG (ORCPT ); Thu, 29 Jul 2021 01:11:06 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D0AC061757 for ; Wed, 28 Jul 2021 22:11:02 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id u12so6435987eds.2 for ; Wed, 28 Jul 2021 22:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0e3pzSC/jURaDUPtk817CJ7QmZ7kWKFhZA8bjqTmygo=; b=q4Hnuk5U8Hb5BIXGd4edjad2/9iReZg5gMN12Zqy51aDoo58MlsGywVUvy3m6sKjRn z4E6ZDrm2VonKuV+mwxh2iq3dY7hS6kiE+0QwEpWJa+VylOR8wvIjYCd9c9qpST0aWNZ CLfs95XJkAORy9YdD7rwWAcuRqjytNoPwLB33KByNULCbVfma7vdWk/lF18t+5daGFUg UWQo1OMA5hccp1P87XHFOcok0tyxSiO3Fjz1ekJ0gh1NP9OvsyXPjB/hb0nN/IcjPMYl KNG1X5TrtRjE0BAzVbT4ycsTEjGqyWMHI44uiDyAMPhD6OpR9o19qty1PkYztETSI8Nt WYJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0e3pzSC/jURaDUPtk817CJ7QmZ7kWKFhZA8bjqTmygo=; b=C4C470qQsMVGrIoB4glO9jGX3JT51DEhSixzOlitu6e7O4WJn+tRUL7mwC3qJUEqhe KfC0TMegxBnHudFOE7RrhfLYeBfAqgoQO7/8IaS4NxytyGBmMyfF+E4ZSFqnqKnnR6tr A9+F705bmXztbBYIDBn80ZNtrj6FFr6ZQ3eyUNHHScMtI/Q3XUh3HqTzWBtGCtShDX+4 JaG4xUt+37y5IeUsO3ymBziWD/XzWn/qOqcIZo4BqpzCv3t+7//UAkerdjg+Xm/RSuHJ M0/PcwPH7czSx0GHtPvMrYuT1dBFzkpVAIL2b0fK3fM+Rnh3YJj+/IJcXeU1ADl08qAx YSWA== X-Gm-Message-State: AOAM531Uk52BCfLy5h5ka+Z5WBRcHETqjfXyaTrxOUdeuxRK8OzBFI8s vQEZVUZ7ul0aNMHW8zXW58bPnNdzJdlZcA== X-Google-Smtp-Source: ABdhPJwSrx0N3dCfS5L2Zftn7YtWe5HjxuD7kPZFSvLpvBuYNUpJPMmV2+uVFkpHp1bFVsZ4xlj8hg== X-Received: by 2002:a05:6402:284:: with SMTP id l4mr3845729edv.108.1627535461388; Wed, 28 Jul 2021 22:11:01 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id s20sm530615eji.116.2021.07.28.22.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 22:11:00 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 62/87] trace-cmd dump: Add helpers for processing trace file version 7 Date: Thu, 29 Jul 2021 08:09:34 +0300 Message-Id: <20210729050959.12263-63-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210729050959.12263-1-tz.stoyanov@gmail.com> References: <20210729050959.12263-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 | 88 ++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 2334b57e..e150a17d 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 >= 7) { + read_compress = false; + tracecmd_compress_reset(compress); + } +} + +static int uncompress_block(void) +{ + int ret = 0; + + if (compress && file_version >= 7) { + 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; } }