From patchwork Thu Nov 11 15:12:49 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: 12615159 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0591EC433FE for ; Thu, 11 Nov 2021 15:13:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3F4261354 for ; Thu, 11 Nov 2021 15:13:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233449AbhKKPPz (ORCPT ); Thu, 11 Nov 2021 10:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234038AbhKKPPy (ORCPT ); Thu, 11 Nov 2021 10:15:54 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73489C06127A for ; Thu, 11 Nov 2021 07:13:05 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id f4so25360126edx.12 for ; Thu, 11 Nov 2021 07:13:05 -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=YrVrPP534jX6fRrmD3ChIy6tMTByr1OJWLRo+Vo8E6A=; b=PwKh2Rskm6iGLLC5Kc2LfV5OGU4eKlo51JfPpdHGtevD1vL415cuDY6oZ4aUjXH4WN cJeqQ9rIWwfM3uZegrf2CzaGTgcCBMc2P40AQt0PS/vUrgy85fQS7j6/3KKfWn1igS1P UH2O8Nso1kFo+IRZExY7IHy5hSc2Nn5IR2jKKaU0+ChBv6lEjCrl0OM9Ahh3mnFbr/fO I4ytALGdWC4/6YYQKJDe9p7Hgz03iBGchs5hNH7KsUhAnQVAJgveDqm6jyBaWvo6qG7e gY9tdfOO1d98V0hDahMZbSG0OIyET41NH1V22ksFsNwN2/t5rhvrtUhz/428sowh4UKX sSWA== 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=YrVrPP534jX6fRrmD3ChIy6tMTByr1OJWLRo+Vo8E6A=; b=Xx4uFAeQWPRaUx3aahHkYCPYrzysZPWxhz5NklEKBM5HXFXUNcvgcbl9hZ2kGk8mwg OlEvchO1d5scwNWaRaO3M76rmOdO2TGxKdggEr4S14PtdqQgt0aG9EMNIdZcphyN7Cxk 9hWQLFH+9nJ2ByWI5DcdAih9Glxhlm+vut2akrYZiptlQt8EKiWd+fzfCJexXZj1JEYt jvhovmp0TJZSKmT1v7/iopPI/V6fWzZ2tVa+mVKHw3ADMI2FXqiPd0EBdoUXB5x2mK7a K7cTXpQ656kB5fwMNOrQa9zDfoSbxTSb+JWBO9Gv4K7i8XlURDL2ZpyoLMNwy4ECFjPo xtKg== X-Gm-Message-State: AOAM533d0GT9teWbrjt+RjZYEEQFm+wddV8Z6u0Px+bT48XCLAHHEKpz DmyqYj2slDoZ0rVlb7itQd0svkqCxEU+LA== X-Google-Smtp-Source: ABdhPJwv7eyJK5EHgfAtzEe8RWPgLX/VurS5OpzFyWi176UOSMVA4+3mKpY8nBHH32kmwjuXNw0MPA== X-Received: by 2002:aa7:cada:: with SMTP id l26mr10952672edt.376.1636643584026; Thu, 11 Nov 2021 07:13:04 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:13:03 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 09/10] trace-cmd dump: Add new argument --sections Date: Thu, 11 Nov 2021 17:12:49 +0200 Message-Id: <20211111151250.87023-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new "trace-cmd dump --sections" argument walks through the sections from a trace file version 7 and prints their headers. The logic does not rely on the options, describing these sections. It could be useful to dump broken or incomplete trace files. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 71 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index b2670744..8986f9b0 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -731,7 +731,7 @@ static void dump_option_section(int fd, unsigned int size, do_print(OPTIONS, "%lld\n", sec->offset); } -static void dump_sections(int fd) +static void dump_sections(int fd, int count) { struct file_section *sec = sections; unsigned short flags; @@ -769,6 +769,7 @@ static void dump_sections(int fd) uncompress_reset(); sec = sec->next; } + do_print(SUMMARY|SECTIONS, "\t[%d sections]\n", count); } static int dump_options_read(int fd); @@ -982,17 +983,76 @@ static void dump_v6_file(int fd) dump_therest(fd); } +static int walk_v7_sections(int fd) +{ + unsigned long long offset, soffset; + unsigned short fl; + char buf[DUMP_SIZE]; + unsigned short id; + int size, csize, rsize; + int count = 0; + + offset = lseek64(fd, 0, SEEK_CUR); + do { + soffset = lseek64(fd, 0, SEEK_CUR); + if (read_file_number(fd, &id, 2)) + break; + if (id >= TRACECMD_OPTION_MAX) + die("Unknown section id %d", id); + if (read_file_string(fd, buf, DUMP_SIZE)) + die("cannot read section description"); + if (read_file_number(fd, &fl, 2)) + die("cannot read section flags"); + if (read_file_number(fd, &size, 4)) + die("cannot read section size"); + if (size <= 4) + die("Section %d (%s) is too small, %d bytes", id, buf, size); + count++; + if (fl & TRACECMD_SEC_FL_COMPRESS) { + if (id == TRACECMD_OPTION_BUFFER || + id == TRACECMD_OPTION_BUFFER_TEXT) { + do_print(SECTIONS, + "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, " + "%d compressed bytes]\n", + id, soffset, buf, fl, size); + } else { + if (read_file_number(fd, &csize, 4)) + die("cannot read section size"); + if (read_file_number(fd, &rsize, 4)) + die("cannot read section size"); + do_print(SECTIONS, "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, " + "%d compressed, %d uncompressed]\n", + id, soffset, buf, fl, csize, rsize); + size -= 8; + } + } else { + do_print(SECTIONS, "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, %d bytes]\n", + id, soffset, buf, fl, size); + } + + if (lseek64(fd, size, SEEK_CUR) == (off_t)-1) + break; + } while (1); + + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) + die("cannot restore the original file location"); + return count; +} + static void dump_v7_file(int fd) { long long offset; + int sections; if (read_file_number(fd, &offset, 8)) die("cannot read offset of the first option section"); - if (lseek64(fd, offset, SEEK_SET) == (off64_t)-1) + sections = walk_v7_sections(fd); + + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) die("cannot goto options offset %lld", offset); dump_options(fd); - dump_sections(fd); + dump_sections(fd, sections); } static void free_sections(void) @@ -1033,6 +1093,7 @@ static void dump_file(const char *file) } enum { + OPT_sections = 241, OPT_verbose = 242, OPT_clock = 243, OPT_all = 244, @@ -1076,6 +1137,7 @@ void trace_dump(int argc, char **argv) {"options", no_argument, NULL, OPT_options}, {"flyrecord", no_argument, NULL, OPT_flyrecord}, {"clock", no_argument, NULL, OPT_clock}, + {"sections", no_argument, NULL, OPT_sections}, {"validate", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {"verbose", optional_argument, NULL, OPT_verbose}, @@ -1139,6 +1201,9 @@ void trace_dump(int argc, char **argv) if (trace_set_verbose(optarg) < 0) die("invalid verbose level %s", optarg); break; + case OPT_sections: + verbosity |= SECTIONS; + break; default: usage(argv); }