From patchwork Mon Sep 13 12:50:33 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: 12488903 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.7 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 2ECC1C433F5 for ; Mon, 13 Sep 2021 12:50:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DC5861029 for ; Mon, 13 Sep 2021 12:50:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235651AbhIMMwD (ORCPT ); Mon, 13 Sep 2021 08:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234945AbhIMMwC (ORCPT ); Mon, 13 Sep 2021 08:52:02 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59E42C061574 for ; Mon, 13 Sep 2021 05:50:46 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id g19-20020a1c9d13000000b003075062d4daso1364356wme.0 for ; Mon, 13 Sep 2021 05:50:46 -0700 (PDT) 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=wg0a57cr/r26Fm3sybPaTjbWfq8hx070vW8oQ3zhuAQ=; b=kwbVVq0vXo6vYKHLJe5k96JyUh02kybHkCTSHz5M09AIce/c/YMZnsd+vTpe1LoM76 eanWscb0WVEQTD8082lcGkEToW06GmUJ31YVQGCtKsunZtbJm3N8bi27fTPBbVoOyJ5F a9GSTTXvPfdPhHPvLrL5lPk2+Nioi/uZTWcI+l2gV60j6cLRAdqNak+ppWUs6ojIw4CC HxzU4S0epsRBEBXnJ5WIQJdVPho8UtPQoXDSqYzxZDIKo6LgcixY0j45kPQCuEhZMMJh IeJs2Ms6sBmfCZG8fNQJCR/DYZfulB7FJIwV/0DRRG8szr5eKUJLown0WEl7YypCeJco aq3g== 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=wg0a57cr/r26Fm3sybPaTjbWfq8hx070vW8oQ3zhuAQ=; b=KEphhHLdJABM8MvzJztkwEHAqPhl1+hd6yg6FiYo4CtDgB11o40nl8R3ftY//X0URO AguXPsyr08JbqJk2oGZDeGCb4XrkeSe31L2IhV+1xiih9Ft10l3il8EOujNd2vux8VGz MPhnX/IGaCOZTsDzoSM5CYM3H5GsLrAu8GiJEqOno3iNtQRYZdB1h0z6T7U6i7q4dVxp 2SoZp1er8n6GjtpJ0fCxU3muU2Ei+CDv8JAH7ODCmqZhgF3Ex94mM1ohB0HM0BXF6Bue XbrIaovepKKk/5C/hW1JqyC0GR3YmFqQVxULllk1f921u2QbJECZcOVVz1XcwYrMxiOQ r3kA== X-Gm-Message-State: AOAM532PnPDFFrYl07v4WqvOtuRc+78CCe8SqFwNhRhBaFTxHTOt3vTp jVx4v9eegcP9GxJgX4cdAKXpWxKo/cs= X-Google-Smtp-Source: ABdhPJyDt488O/daOEOAQ9ZI7JOQf5MGxVI6t2w6rqmS+qyaJlcgYyW21IH2Iqy8JmMSv1Uy/LKrEw== X-Received: by 2002:a1c:a78d:: with SMTP id q135mr11072827wme.36.1631537445011; Mon, 13 Sep 2021 05:50:45 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id u27sm7756448wru.2.2021.09.13.05.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 05:50:44 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 04/10] trace-cmd dump: Read recursively all options sections Date: Mon, 13 Sep 2021 15:50:33 +0300 Message-Id: <20210913125039.3680986-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210913125039.3680986-1-tz.stoyanov@gmail.com> References: <20210913125039.3680986-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 supports multiple options sections in the file. The DONE option is extended to hold the offset to the next options section. A new logic for handling the extended DONE option and to read recursively all options sections is added. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 76 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index f7284436..dcc41030 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -422,6 +422,30 @@ static void dump_option_string(int fd, int size, char *desc) read_dump_string(fd, size, OPTIONS); } +static void dump_section_header(int fd, enum dump_items v, unsigned short *flags) +{ + unsigned long long offset; + unsigned short fl; + char buf[DUMP_SIZE]; + unsigned short id; + int size; + + offset = lseek64(fd, 0, SEEK_CUR); + if (read_file_number(fd, &id, 2)) + die("cannot read the section id"); + if (read_file_string(fd, buf, DUMP_SIZE)) + die("no section description"); + if (read_file_number(fd, &fl, 2)) + die("cannot read the section flags"); + if (read_file_number(fd, &size, 4)) + die("cannot read section size"); + do_print(v, "\t[Section %d @ %lld: \"%s\", flags 0x%X, %d bytes]\n", + id, offset, buf, fl, size); + + if (flags) + *flags = fl; +} + static void dump_option_buffer(int fd, int size) { unsigned long long offset; @@ -591,25 +615,48 @@ void dump_option_tsc2nsec(int fd, int size) do_print(OPTIONS, "%d %d %llu [multiplier, shift, offset]\n", mult, shift, offset); } -static void dump_options(int fd) +static int dump_options_read(int fd); + +static int dump_option_done(int fd, int size) { + unsigned long long offset; + + do_print(OPTIONS, "\t\t[Option DONE, %d bytes]\n", size); + + if (file_version < FILE_VERSION_SECTIONS || size < 8) + return 0; + if (read_file_number(fd, &offset, 8)) + die("cannot read the next options offset"); + do_print(OPTIONS, "%lld\n", offset); + if (!offset) + return 0; + + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) + die("cannot goto next options offset %lld", offset); + return dump_options_read(fd); +} + +static int dump_options_read(int fd) +{ + unsigned short flags = 0; unsigned short option; unsigned int size; int count = 0; + if (file_version >= FILE_VERSION_SECTIONS) + dump_section_header(fd, OPTIONS, &flags); + if ((flags & TRACECMD_SEC_FL_COMPRESS) && uncompress_block()) + die("cannot uncompress file block"); + for (;;) { if (read_file_number(fd, &option, 2)) die("cannot read the option id"); - if (!option) + if (option == TRACECMD_OPTION_DONE && file_version < FILE_VERSION_SECTIONS) break; if (read_file_number(fd, &size, 4)) die("cannot read the option size"); count++; - if (!DUMP_CHECK(OPTIONS) && !DUMP_CHECK(CLOCK) && !DUMP_CHECK(SUMMARY)) { - lseek64(fd, size, SEEK_CUR); - continue; - } switch (option) { case TRACECMD_OPTION_DATE: dump_option_string(fd, size, "DATE"); @@ -621,7 +668,8 @@ static void dump_options(int fd) dump_option_buffer(fd, size); break; case TRACECMD_OPTION_TRACECLOCK: - dump_option_string(fd, size, "TRACECLOCK"); + do_print(OPTIONS, "\t\t[Option TRACECLOCK, %d bytes]\n", size); + read_dump_string(fd, size, OPTIONS | CLOCK); has_clock = 1; break; case TRACECMD_OPTION_UNAME: @@ -654,6 +702,10 @@ static void dump_options(int fd) case TRACECMD_OPTION_TSC2NSEC: dump_option_tsc2nsec(fd, size); break; + case TRACECMD_OPTION_DONE: + uncompress_reset(); + count += dump_option_done(fd, size); + return count; default: do_print(OPTIONS, " %d %d\t[Unknown option, size - skipping]\n", option, size); @@ -661,8 +713,16 @@ static void dump_options(int fd) break; } } - do_print(SUMMARY, "\t[%d options]\n", count); + uncompress_reset(); + return count; +} + +static void dump_options(int fd) +{ + int count; + count = dump_options_read(fd); + do_print(SUMMARY|OPTIONS, "\t[%d options]\n", count); } static void dump_latency(int fd)