From patchwork Fri Dec 10 11:05:01 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: 12669365 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 5B362C433EF for ; Fri, 10 Dec 2021 11:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240052AbhLJLIw (ORCPT ); Fri, 10 Dec 2021 06:08:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240085AbhLJLIv (ORCPT ); Fri, 10 Dec 2021 06:08:51 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB082C061746 for ; Fri, 10 Dec 2021 03:05:16 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id y12so28156231eda.12 for ; Fri, 10 Dec 2021 03:05:16 -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=dtPax41mHcDC7JluSY//3hSd0yZljvOSGNGM63nx2Do=; b=YJ5ZxoLLnM3IGQRNDEKYTofDRKfHeHAJd3WuaKlm4bDMmRnTJ99Fv5PzF4KPIRQiav IYpQ5p9PPNDh7btkKVhjoYeEYQJsNg0eTOZdRRr1aG1MX8MSosNfal/ayY7Oky6kdidZ gMr7yhzk7ToNEt50xVaRQ8FUsyrxtHqXVJ8Dfmu5AapE+pP2AiFbt+fw+QdZMPEKau3L F71gNsxe0Yhc/8t1SfnoKILiyJIlAoK9sxBoZrPB2rvW34XdZhKdXq36M0FabIZPrIow aYdP+zpzI910lFiRfywJQE4o5Eg+e2A7NWjRwMc4cjG0gCDbrvXjHPvW7/oa6FrOcwak dXcw== 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=dtPax41mHcDC7JluSY//3hSd0yZljvOSGNGM63nx2Do=; b=52+9ivSS+eMKI8nr8c7IEZtiDKapqujC25lZfGpxEJWplTJjnMnRuvT++X7l2QwBqY 90bQImc9XvyLdguP17fh0qIcG7s6n7pPjIJFD8H9YmCagXxJq6YJBJj+bH5XKY7LeyHW HszMk9pqcuXa2utJngOS9tdsXdrH/Kk6YPy4NKkoLGuD0V8qf6j5Am/Y4nwmhXhmvtB/ ihtqF5KNADv2jplL/7REN1p46EC2vL4bxRxyI2+YZ3vLoxZNKiR8gxiiC4chrK7DNUbf IDH7QtFKSkowhxsJzLPYzU6/0tsinGhCUjzVrOtRBnNlqrScYrOKWI/5S0Bbo4NOPrB6 h+zA== X-Gm-Message-State: AOAM530bIakhhQHmxxi5v5Eb8yYWf49wli9bz5QMa1HW8wpseolaZruq cNKDMCFPHXjrZrvoRAKELSENqUpd+WY= X-Google-Smtp-Source: ABdhPJzo7enyl/3Oh10BN6FOLgN9mv71WWovRO9/nz5rFp7RyKZpuWn4JH2LTe3BVwsd37e+UjBOUA== X-Received: by 2002:a05:6402:3589:: with SMTP id y9mr39244948edc.44.1639134315215; Fri, 10 Dec 2021 03:05:15 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:14 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 01/11] trace-cmd dump: Add helpers for processing trace file version 7 Date: Fri, 10 Dec 2021 13:05:01 +0200 Message-Id: <20211210110511.98856-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-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 2408a4ab..23733194 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; @@ -623,7 +669,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; } } From patchwork Fri Dec 10 11:05:02 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: 12669369 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 20355C433EF for ; Fri, 10 Dec 2021 11:05:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240266AbhLJLIz (ORCPT ); Fri, 10 Dec 2021 06:08:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240246AbhLJLIy (ORCPT ); Fri, 10 Dec 2021 06:08:54 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F876C061353 for ; Fri, 10 Dec 2021 03:05:19 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id y13so28328721edd.13 for ; Fri, 10 Dec 2021 03:05:19 -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=BrG3YYYzPJeeHMDZrmsvJT3K7XJlnw/6xk4Ufrc2OFA=; b=gezFsOQ4s+fPs2b8obuzY3j2iBpPicMJdb1F6rhRO4uV9Rgbs4HiJ12bzUJJRRObmV a1b+FIIfc/7XJKJx2lKp1oVEVEYrG5/fGq/OgrIOS66gLReJawClf6njVEdYSGEyBxQk sxQK6tNLWY6kPDyppjt7azPJmtHB6/JiIS1AsnwcgCIGQgVL1WIj/sq2XaORC/bpZy5j qdIzPf38AiOeziD5g3+z26fgK7mZbgUEX3GZUWk4B/8Xlf0bQhKpwvR/KeOWRYw38bUT GaTEy7LQBTIsIfXZw7pgD4xZyU0mA9iqXOeW2ktr4UuOHi32PffhMFN8q47FnDEyOVpY J5CQ== 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=BrG3YYYzPJeeHMDZrmsvJT3K7XJlnw/6xk4Ufrc2OFA=; b=77YTMb5LFgc1w0aE1qILALmMuN348DoZhl3+hya3dv8zluXthBq+kEgaAswuVpTbs8 9ZlEbdx9GyTbCXgvr+hqUCR8JY733BvXvMSNVppCAfCEOkxfsxq3FfwRiGi0w0Fnr7CR W+wD+gUgajTlKf9U5jCsaftwA080+8at2OxuJnUqjQDiD6KNwiPcbq+YI7ug7Zd7+P6H vBM4wIUTrJpoKApWo+lxIBDfRZapythIUdocClSWtCfYOJLY9iG4H/+xCUAXDC6Fasaa fsgsrboow88s+t8NiDABxA768IG/+OoVot31yM3oMeeNQEvB4lhQzod2aRCR2j89QIlg LL4Q== X-Gm-Message-State: AOAM533SycQI9B+4gzvdavme0KpUKjfkKfl6PYITqL7xIrJAfE1Vg65c 7yapc0kYVxlv0YYz7SVAYJKvXauGeGs= X-Google-Smtp-Source: ABdhPJytXiKPte8bfuYX79BWi1LRYT+Lr6NiV1F67xn1zKqFTBLmgrPq8M9GgEqBHEl2PcjPLF6hEw== X-Received: by 2002:a17:907:98f6:: with SMTP id ke22mr22998884ejc.500.1639134316032; Fri, 10 Dec 2021 03:05:16 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:15 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 02/11] trace-cmd dump: Print compression header Date: Fri, 10 Dec 2021 13:05:02 +0200 Message-Id: <20211210110511.98856-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Dump the compression header of trace file version 7 Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 23733194..1503e2bf 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -217,6 +217,29 @@ static void dump_initial_format(int fd) do_print(SUMMARY, "\t\t%d\t[Page size, bytes]\n", val4); } +static void dump_compress(int fd) +{ + char zname[DUMP_SIZE]; + char zver[DUMP_SIZE]; + + if (file_version < FILE_VERSION_COMPRESSION) + return; + + /* get compression header */ + if (read_file_string(fd, zname, DUMP_SIZE)) + die("no compression header"); + if (read_file_string(fd, zver, DUMP_SIZE)) + die("no compression version"); + do_print((SUMMARY), "\t\t%s\t[Compression algorithm]\n", zname); + do_print((SUMMARY), "\t\t%s\t[Compression version]\n", zver); + + if (strcmp(zname, "none")) { + compress = tracecmd_compress_alloc(zname, zver, fd, tep, NULL); + if (!compress) + die("cannot uncompress the file"); + } +} + static void dump_header_page(int fd) { unsigned long long size; @@ -760,6 +783,7 @@ static void dump_file(const char *file) do_print(SUMMARY, "\n Tracing meta data in file %s:\n", file); dump_initial_format(fd); + dump_compress(fd); dump_header_page(fd); dump_header_event(fd); dump_ftrace_events_format(fd); From patchwork Fri Dec 10 11:05:03 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: 12669367 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 D42FAC433F5 for ; Fri, 10 Dec 2021 11:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240263AbhLJLIy (ORCPT ); Fri, 10 Dec 2021 06:08:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237368AbhLJLIy (ORCPT ); Fri, 10 Dec 2021 06:08:54 -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 4B129C061746 for ; Fri, 10 Dec 2021 03:05:18 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id e3so29125924edu.4 for ; Fri, 10 Dec 2021 03:05:18 -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=1RF9iTs0YQheWjPYt7oNCLhohHvFqiNhoZNvOlMV/x4=; b=hvaJaHJ7PEvhcImRWRWeE3K2ahx2/FYAb0R5/ydrhByAOC6ch0P01BSJ9VHzIB29hF U4exHkBpH0SBYRo3zsbMshTPvp8z92XIBrvuYLUai5mmKD2PzQpNIr8C19muckqWs/gj hjHIb8hiV8ss3sYWAj2x+4sPaRhVIH/qy8LBPmKf7RwC9KtKc4sBLr+v5InhHrdPuRfh t7n4XunDal3jaXaAIWgaQg/avQA9GW8elzZme/ddmtGyllCOt2w7B7okw/oU623284ox lHKW8BDRJDdztEwE3jbAF0kGVS46Ppg7aH7MFoNCDnsGMMhk7N7ttoutgkMuqfLSFQ7J l5ig== 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=1RF9iTs0YQheWjPYt7oNCLhohHvFqiNhoZNvOlMV/x4=; b=ML0/N8/3VEM4QFs7h4Zfjk7hUZ/5RbjhWos0l/EKI1A0ziMqqy5Vw7annXcvsvuxvJ soFVDnhJQnppr3DD6eh6I03Ulgmr+UjgdhP6EorNwpdtGEM+du6KCXpy3qa2CNMzJ+P3 hMceHRaO5UjoiBpiNozcvvtZAX+yw7SfY9HRdd89PRsKhkSkflTaqDJXoS3hadtCUKda 14DyKx88yW+4WK+QAT00TQG38AB/ENp3gSY/yjD/ybOtWfpjln1PqaCvPe88Dy815XE0 jXxM5Datmgx1oj5AdNywZPuHGph1YRo+ya8F+2+FwvwFyVITwZls7B2oa/AZxz/PTowE V3Kw== X-Gm-Message-State: AOAM533VZ3s4Uo8f38deK4ndl9+Z7QoKxWJsLaMXeH7IOuayZVKOczcE dJmGSTs1uqnNov5hjPnwUa3/+k1Ocf8= X-Google-Smtp-Source: ABdhPJyJpBuCHJCEyrhZqoOQJo/+wIEJAb1Gs/5D4sWgOQG9znOIwyu8gSodDKq1FT71ppzfvb9N+Q== X-Received: by 2002:a17:907:3f29:: with SMTP id hq41mr22970477ejc.216.1639134316882; Fri, 10 Dec 2021 03:05:16 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:16 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 03/11] trace-cmd dump: Add helpers for processing trace file sections Date: Fri, 10 Dec 2021 13:05:03 +0200 Message-Id: <20211210110511.98856-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added a new local database for storing sections, found in trace file version 7. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 1503e2bf..113eee8e 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -43,8 +43,18 @@ enum dump_items { OPTIONS = (1 << 9), FLYRECORD = (1 << 10), CLOCK = (1 << 11), + SECTIONS = (1 << 12), }; +struct file_section { + int id; + unsigned long long offset; + struct file_section *next; + enum dump_items verbosity; +}; + +static struct file_section *sections; + enum dump_items verbosity; #define DUMP_CHECK(X) ((X) & verbosity) @@ -768,6 +778,17 @@ static void dump_therest(int fd) } } +static void free_sections(void) +{ + struct file_section *del; + + while (sections) { + del = sections; + sections = sections->next; + free(del); + } +} + static void dump_file(const char *file) { int fd; @@ -793,7 +814,7 @@ static void dump_file(const char *file) dump_cmdlines(fd); dump_cpus_count(fd); dump_therest(fd); - + free_sections(); tep_free(tep); tep = NULL; close(fd); From patchwork Fri Dec 10 11:05:04 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: 12669371 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 BF1F7C433F5 for ; Fri, 10 Dec 2021 11:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240274AbhLJLIz (ORCPT ); Fri, 10 Dec 2021 06:08:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240250AbhLJLIy (ORCPT ); Fri, 10 Dec 2021 06:08:54 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52355C061A32 for ; Fri, 10 Dec 2021 03:05:19 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id y12so28156691eda.12 for ; Fri, 10 Dec 2021 03:05:19 -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=AuBFvWKU2KH1ROEAP0YCbTsIUDqlZwTOWLgEb58W5kI=; b=lVBIO+j1NSt7jjqYM/qjclZAtlvRcUsIj4kDrMXpj+cKG5IiD8N+IhlQWhQsR9yN1N /Q9xeeJNhx/Q91358pUSOMp1RbYR45e0CtLL8kafsk+gq7SoyM4GZHgFIRgkRhTcZFjA rY3QCgcn8sq9CSz1ImBEsBxvX8jgXsEq9xa8MusuzgtJPH4ol8iF6PvYR9kykby+/5YW bJHRq/5FDnhGlnW5ctHhUOGAZPdgFg+T8asXvEznAf9mk38+uqNO/lSeYGse1RzJ/uxC EGkHYR/bR2/To22bga+EwnZMqNcNUNRMO799c4k8/oMuLw/yRWef/2wAbfDo9zzsA3om GGZg== 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=AuBFvWKU2KH1ROEAP0YCbTsIUDqlZwTOWLgEb58W5kI=; b=d9+VQoqAdlcvhYpU+/lhGUtRrM8dqXUgln9Mx1jJa8oUFfATS6Rte/C2AAb2MJEngN 5eV5pbGTMUbVo6xJImYKSpr/du8e4c7yczADCoIDx1kPuVjZAG7ovedeaq3ZnrbrcUnf 17fJAJ6Q7rhvl8aCGeebQmYfwRiFeGwzUjXI0ugLOmOb80ml32FbXAS4vOWRPgMkG1uN TbvqN/ATI38DP8/FRAFrWSDSRcoV1HLMigq7Jgj0mCGOlsXezJw369s3/gYUY282UPd9 8GlnBsRz5TBVkd31UtTpCEQYJiZirJ9hsV7OgKAXVsXS12QPM2PSb5lbU/mGVV/9X2Dn YMyQ== X-Gm-Message-State: AOAM532FR8zCzGlF1JgwjUxfii/3b+bQRyIdIdWiSDDp6WCTHMKJlHWh yVQkzE7roGQ6QpJpwg/DgPgEkwLWGCE= X-Google-Smtp-Source: ABdhPJx8zKcGuOpEuaQEqCQ8s0dH0JqKo+uh9NhqT27cEU4fZym6/1TN+QMY7ZbkcEqcJ7Oj1sl2Rg== X-Received: by 2002:a05:6402:270a:: with SMTP id y10mr38172591edd.108.1639134317786; Fri, 10 Dec 2021 03:05:17 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:17 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 04/11] trace-cmd dump: Read recursively all options sections Date: Fri, 10 Dec 2021 13:05:04 +0200 Message-Id: <20211210110511.98856-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-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 | 78 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 113eee8e..53e2f9c0 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -422,6 +422,29 @@ 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, size; + unsigned short fl; + unsigned short id; + int desc_id; + + offset = lseek64(fd, 0, SEEK_CUR); + if (read_file_number(fd, &id, 2)) + die("cannot read the section id"); + if (read_file_number(fd, &desc_id, 4)) + die("no section description"); + if (read_file_number(fd, &fl, 2)) + die("cannot read the section flags"); + if (read_file_number(fd, &size, 8)) + die("cannot read section size"); + do_print(v, "\t[Section %d @ %lld, flags 0x%X, %lld bytes]\n", + id, offset, fl, size); + + if (flags) + *flags = fl; +} + static void dump_option_buffer(int fd, int size) { unsigned long long offset; @@ -636,25 +659,51 @@ 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); + + do_print(OPTIONS, "\n\n"); + + 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"); @@ -666,7 +715,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: @@ -699,6 +749,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); @@ -706,8 +760,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) From patchwork Fri Dec 10 11:05:05 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: 12669373 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 CEEFEC4332F for ; Fri, 10 Dec 2021 11:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240250AbhLJLI4 (ORCPT ); Fri, 10 Dec 2021 06:08:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240268AbhLJLIz (ORCPT ); Fri, 10 Dec 2021 06:08:55 -0500 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 29024C061746 for ; Fri, 10 Dec 2021 03:05:20 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id y12so28156859eda.12 for ; Fri, 10 Dec 2021 03:05:20 -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=cWEUjQFfa9nsvCpsv3XrVF1BP0Zlh07mx2tOZFBg20A=; b=eTtfwP1grjULwWNO0QA4ap/t3yyhRhcXLQ/KaK97WQ3TP2HtBuoB/vS15eOjLwm/6S NWLH2k94zBQTxB2YFgVrZl6quI+12VxGFBlAkvmdsrMrZieGBkX/zxniOBTnKdBkVnP5 wJGlY9HSUofu7NhGM6U2T4k/tnFmYCqavMkU8IMy0p5R8HSs9W+DKUDrUYmrITeSFM+i h5c4WcXmNReiqEuudkQSR8LeL8vbxQj2/kYY/fFKqUFmE+gSIJ9+fZlRh5J6Z+dsGPEX eCMU8GqV5njcDa7EDGXwVQlO2mZsuleNFycw3QPFlMtrNpcj1KguuNpSvfkYK/VnB08B b7tg== 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=cWEUjQFfa9nsvCpsv3XrVF1BP0Zlh07mx2tOZFBg20A=; b=Fggk4VvsHxIjmUiDgpGafFFRJxgvS3/lUDDD0gomfCpfFehzsdIXd0vsiYEZrVOWfY 3XS/HwiBKq5lMuPYIgmoBkjywWJfR601J9q4dQbYsvV/38ICaBpU5jmMct1BZUdzWT/b GelkE3ZW/yMH8NXRu0TG3PttR2hI7fSWXVFg80yZ7qe/imM1nAug8nBdc9qbl1ztSyMV 2Cec4PoTqD61q0z6ACIGQRFnteyXu+a2OuKbhxY8z/tjMvwokHxSA2iXvd53qnw0v0Ej sBzPPuoPT62eoaC/jTuINsdlnUPiUcNWOyx/dMfQ0CN1nkLet0uobYwJn/TUk7WYz2l8 r4JQ== X-Gm-Message-State: AOAM532hOw/Sqed3kkI6Socg7SLlQMlBwF/J/NMi3syGCEkTCAvzdf2t e2zklz8NAamVfslJeC4YypFx1u13tXQ= X-Google-Smtp-Source: ABdhPJy5di6HKyBGVx/O26ONHX+GqYY0Id7RnD1eS2ugxjl8Zp5N+QQt97bor/zDklNfeU01Sb09jA== X-Received: by 2002:a17:907:7850:: with SMTP id lb16mr22997356ejc.67.1639134318622; Fri, 10 Dec 2021 03:05:18 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:18 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 05/11] trace-cmd dump: Read extended BUFFER option Date: Fri, 10 Dec 2021 13:05:05 +0200 Message-Id: <20211210110511.98856-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In trace file version 7 the BUFFER option is extended to hold a trace metadata, related to the recorded instance. Also, a new BUFFER_TEXT option is added for latency trace data. Implemented logic for reading and printing these extended options. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 64 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 53e2f9c0..e4609c39 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -445,19 +445,72 @@ static void dump_section_header(int fd, enum dump_items v, unsigned short *flags *flags = fl; } -static void dump_option_buffer(int fd, int size) +static void dump_option_buffer(int fd, unsigned short option, int size) { + unsigned long long total_size = 0; + unsigned long long data_size; + unsigned long long current; unsigned long long offset; + unsigned short flags; + char clock[DUMP_SIZE]; + char name[DUMP_SIZE]; + int cpus = 0; + int id; + int i; if (size < 8) die("broken buffer option with size %d", size); if (read_file_number(fd, &offset, 8)) die("cannot read the offset of the buffer option"); + if (read_file_string(fd, name, DUMP_SIZE)) + die("cannot read the name of the buffer option"); + if (file_version < FILE_VERSION_SECTIONS) { + do_print(OPTIONS|FLYRECORD, "\t\t[Option BUFFER, %d bytes]\n", size); + do_print(OPTIONS|FLYRECORD, "%lld [offset]\n", offset); + do_print(OPTIONS|FLYRECORD, "\"%s\" [name]\n", name); + return; + } + + current = lseek64(fd, 0, SEEK_CUR); + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) + die("cannot goto buffer offset %lld", offset); + + dump_section_header(fd, FLYRECORD, &flags); + + if (lseek64(fd, current, SEEK_SET) == (off_t)-1) + die("cannot go back to buffer option"); + + do_print(OPTIONS|FLYRECORD, "\t\t[Option BUFFER, %d bytes]\n", size); + do_print(OPTIONS|FLYRECORD, "%lld [offset]\n", offset); + do_print(OPTIONS|FLYRECORD, "\"%s\" [name]\n", name); + + if (read_file_string(fd, clock, DUMP_SIZE)) + die("cannot read clock of the buffer option"); + do_print(OPTIONS|FLYRECORD, "\"%s\" [clock]\n", clock); + if (option == TRACECMD_OPTION_BUFFER) { + if (read_file_number(fd, &cpus, 4)) + die("cannot read the cpu count of the buffer option"); + + do_print(OPTIONS|FLYRECORD, "%d [CPUs]:\n", cpus); + for (i = 0; i < cpus; i++) { + if (read_file_number(fd, &id, 4)) + die("cannot read the id of cpu %d from the buffer option", i); + if (read_file_number(fd, &offset, 8)) + die("cannot read the offset of cpu %d from the buffer option", i); + if (read_file_number(fd, &data_size, 8)) + die("cannot read the data size of cpu %d from the buffer option", i); + total_size += data_size; + do_print(OPTIONS|FLYRECORD, " %d %lld\t%lld\t[id, data offset and size]\n", + id, offset, data_size); + } + do_print(SUMMARY, "\t\[buffer \"%s\", \"%s\" clock, " + "%d cpus, %lld bytes flyrecord data]\n", + name, clock, cpus, total_size); + } else { + do_print(SUMMARY, "\t\[buffer \"%s\", \"%s\" clock, latency data]\n", name, clock); + } - do_print(OPTIONS, "\t\t[Option BUFFER, %d bytes]\n", size); - do_print(OPTIONS, "%lld [offset]\n", offset); - read_dump_string(fd, size - 8, OPTIONS); } static void dump_option_int(int fd, int size, char *desc) @@ -712,7 +765,8 @@ static int dump_options_read(int fd) dump_option_string(fd, size, "CPUSTAT"); break; case TRACECMD_OPTION_BUFFER: - dump_option_buffer(fd, size); + case TRACECMD_OPTION_BUFFER_TEXT: + dump_option_buffer(fd, option, size); break; case TRACECMD_OPTION_TRACECLOCK: do_print(OPTIONS, "\t\t[Option TRACECLOCK, %d bytes]\n", size); From patchwork Fri Dec 10 11:05:06 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: 12669375 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 A0E37C433F5 for ; Fri, 10 Dec 2021 11:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240318AbhLJLI6 (ORCPT ); Fri, 10 Dec 2021 06:08:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240267AbhLJLIz (ORCPT ); Fri, 10 Dec 2021 06:08:55 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0CEFC061746 for ; Fri, 10 Dec 2021 03:05:20 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id r25so28243071edq.7 for ; Fri, 10 Dec 2021 03:05:20 -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=S0oPuBqmz0nlEBUWWBZJvD5Y08KtUeqByEXy2aXH1PA=; b=lPQz6u5f1TwPM/6ZNtKeL5NzTT3kIp6NzlprjNKKHZFiOv5+i5la/1yVTNrbVgAxda r+lqVn4FV3rwNfs9kIVRxeTEhL7261gFv6Vyqsb5izFKwNYkxyVirYQGxrodYfSyShpG OUmqBCToS59SWOJUz6/NdcA1q/rNi9ZlxXNjW9YYkFKG+HUJgIoqK7V2Aw5xeQKTs554 WzjkT7qRzs9TudeXzcgxDSe5AulkKIjgHLs0LXEfd7cPfMJ9qwNeTQux4ueuFJ4fSDdk tytC/Z/CRGfZsuyWvKAM0j2dHiAlkpG46E5ocsSc8dpmuYDUXyh8k7vCEOpAxr/1XuGU 8ziA== 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=S0oPuBqmz0nlEBUWWBZJvD5Y08KtUeqByEXy2aXH1PA=; b=2ELqWOpLq6FAWbUsYFfqd6+Z+UAjuJj2ZnAGfEXYnkofmlIpLtSqUnKUE8hyjE+LeQ z0UUBkjh21QgzO5LzBYHrlXTUNiwUzjCNEG+wTdCL8AkAxrjCES/nleOIKQja5Bl/UMt HTZL61f9p2n1J5GhX1rJdQ5wjAzL5PFOQzU+/DlNJXx0WAmU5rL3IUJqnAcZx/JTuv2/ eOXSmpM9fvK8QAkFANRK0YcY7VHO0X62+sXk2TOW4lB+Jtx8I4i431sk227nmn2M5uj6 1YKEKOs0c3LE42+LvmMaG2shuqk/ADDLqXt63y21UNKafwuDW7yFFbLBgH9sTA2d6E9y 2vQw== X-Gm-Message-State: AOAM532clZs4YI+uqj10LrpzSCqdjSqgMNDnPuPBXiVCUZrsa82ewQd0 RK0RCJM/STnFqb6+LbRLHVJVK1XAU54= X-Google-Smtp-Source: ABdhPJy7FCWOQeDlJ80inzbcA1KMjhAwUWSKnIveJHdQXbkdBqZQP+huYhTAjuCJ9NIAavN18dKl9A== X-Received: by 2002:a17:906:3ce9:: with SMTP id d9mr22726650ejh.172.1639134319404; Fri, 10 Dec 2021 03:05:19 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:19 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 06/11] trace-cmd dump: Dump sections Date: Fri, 10 Dec 2021 13:05:06 +0200 Message-Id: <20211210110511.98856-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In trace file version 7, headers are stored as sections. This allows their position in the file not to be fixed. Pointers to these sections are stored as trace options. Add logic to handle these new options: HEADER_INFO FTRACE_EVENTS EVENT_FORMATS KALLSYM PRINTK CMDLINES Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index e4609c39..f6d84e3b 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -712,6 +712,23 @@ void dump_option_tsc2nsec(int fd, int size) do_print(OPTIONS, "%d %d %llu [multiplier, shift, offset]\n", mult, shift, offset); } +static void dump_option_section(int fd, unsigned int size, + unsigned short id, char *desc, enum dump_items v) +{ + struct file_section *sec; + + sec = calloc(1, sizeof(struct file_section)); + if (!sec) + die("cannot allocate new section"); + sec->next = sections; + sections = sec; + sec->id = id; + sec->verbosity = v; + if (read_file_number(fd, &sec->offset, 8)) + die("cannot read the option %d offset", id); + do_print(OPTIONS, "\t\t[Option %s, %d bytes] @ %lld\n", desc, size, sec->offset); +} + static int dump_options_read(int fd); static int dump_option_done(int fd, int size) @@ -803,6 +820,25 @@ static int dump_options_read(int fd) case TRACECMD_OPTION_TSC2NSEC: dump_option_tsc2nsec(fd, size); break; + case TRACECMD_OPTION_HEADER_INFO: + dump_option_section(fd, size, option, "HEADERS", HEAD_PAGE | HEAD_EVENT); + break; + case TRACECMD_OPTION_FTRACE_EVENTS: + dump_option_section(fd, size, option, "FTRACE EVENTS", FTRACE_FORMAT); + break; + case TRACECMD_OPTION_EVENT_FORMATS: + dump_option_section(fd, size, option, + "EVENT FORMATS", EVENT_SYSTEMS | EVENT_FORMAT); + break; + case TRACECMD_OPTION_KALLSYMS: + dump_option_section(fd, size, option, "KALLSYMS", KALLSYMS); + break; + case TRACECMD_OPTION_PRINTK: + dump_option_section(fd, size, option, "PRINTK", TRACE_PRINTK); + break; + case TRACECMD_OPTION_CMDLINES: + dump_option_section(fd, size, option, "CMDLINES", CMDLINES); + break; case TRACECMD_OPTION_DONE: uncompress_reset(); count += dump_option_done(fd, size); From patchwork Fri Dec 10 11:05:07 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: 12669377 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 A48F3C433FE for ; Fri, 10 Dec 2021 11:05:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240277AbhLJLJA (ORCPT ); Fri, 10 Dec 2021 06:09:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240281AbhLJLI5 (ORCPT ); Fri, 10 Dec 2021 06:08:57 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4CFCC0617A2 for ; Fri, 10 Dec 2021 03:05:21 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id g14so28021552edb.8 for ; Fri, 10 Dec 2021 03:05:21 -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=WX47OPQEx83sN8j6buaugyeSyf6qywAdlZjc3Eu/hMY=; b=Hu8lwkLyzly1+Gq7AjnJGR5e3jICMTwou4Xf5s3H5U7X3RCmsbFxaa6eE12Kr3EAMV ElOYBWVLJJoCTi6cWTBOUjLlbThZltnl7FuN7zwUPffVA1+QpdRDB0uxPYHPGc4F+DmI onZuB77E3orOTKlzLBTQGlsHnI3SzWxzu9ONxgvIzhwRyiKUTFLgYFUveoolYgZHCWsd kE2ngy0fDCazrJFGgFNRg7HjYoetcQSfv3wcyzWt0IqkBdqH1/jjeWKemuJesHXRoLs0 7Bmk7f+xjO3HAsk7gXTIlEPKi2Rs1q6UfLZNmhla9kxnFaddpSDqa5ZLUrZgQ0BtUbKR 41iQ== 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=WX47OPQEx83sN8j6buaugyeSyf6qywAdlZjc3Eu/hMY=; b=ao4LgdyjoxUDhdMgSefKKr6XvxTlyh/+pGgMxvx13TONwDeUWgBH00K0dnXorVy8gk 9cG6Kj4CHXUd1DJAWlsUo6mOYI3o6hBSHGNfxpp9eePScEse3PR4Ts+jzP3w7hnTH5Zv XPOeUXmJhgr0HNaZlJCc8NzCzSHLCGOxdA7x5liBTY7hhI2JjsNIYvRaUilqeLblB0bx lAMsJK8Ymdm2i3pz1Nu9CAErJMAlsgALJifMH+YWjX1xIrVBiDc/wn/2ABlBmDEt40hv XFZZCNLEDyb/lsOd3xqUHpEWOWwtdBb5eNgDfOxZfvm73V02d7BuDilRrF98Kl3AEuEr cwqw== X-Gm-Message-State: AOAM531XY3NgXanL9rEG5IfMuqdh4zaDzhO4XsNuPGpwaHCz71AcmvaX pVIkXNjcHokTZjmTKG9wM6nxDnTz0to= X-Google-Smtp-Source: ABdhPJww7GkBYJoCeaSGL7JnhRelKJN+K5JnJzkMg3AwJOTaamEXd6gfEqKFOm/6hK1kl8Y4y/itGA== X-Received: by 2002:a05:6402:544:: with SMTP id i4mr37804763edx.9.1639134320369; Fri, 10 Dec 2021 03:05:20 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:19 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 07/11] trace-cmd dump: Dump trace file version 7 Date: Fri, 10 Dec 2021 13:05:07 +0200 Message-Id: <20211210110511.98856-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-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 has different structure than version 6. Separates parsing both versions in different flows. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index f6d84e3b..1ccdec22 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -930,6 +930,31 @@ static void dump_therest(int fd) } } +static void dump_v6_file(int fd) +{ + dump_header_page(fd); + dump_header_event(fd); + dump_ftrace_events_format(fd); + dump_events_format(fd); + dump_kallsyms(fd); + dump_printk(fd); + dump_cmdlines(fd); + dump_cpus_count(fd); + dump_therest(fd); +} + +static void dump_v7_file(int fd) +{ + long long offset; + + 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) + die("cannot goto options offset %lld", offset); + dump_options(fd); +} + static void free_sections(void) { struct file_section *del; @@ -957,15 +982,10 @@ static void dump_file(const char *file) dump_initial_format(fd); dump_compress(fd); - dump_header_page(fd); - dump_header_event(fd); - dump_ftrace_events_format(fd); - dump_events_format(fd); - dump_kallsyms(fd); - dump_printk(fd); - dump_cmdlines(fd); - dump_cpus_count(fd); - dump_therest(fd); + if (file_version < FILE_VERSION_SECTIONS) + dump_v6_file(fd); + else + dump_v7_file(fd); free_sections(); tep_free(tep); tep = NULL; From patchwork Fri Dec 10 11:05:08 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: 12669379 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 80E78C433EF for ; Fri, 10 Dec 2021 11:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240353AbhLJLJB (ORCPT ); Fri, 10 Dec 2021 06:09:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240301AbhLJLI5 (ORCPT ); Fri, 10 Dec 2021 06:08:57 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8497C0617A2 for ; Fri, 10 Dec 2021 03:05:22 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id g14so28021751edb.8 for ; Fri, 10 Dec 2021 03:05:22 -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=1pZfRn7VIhOLMNi4GJTD7rcBdqN8ePzWIVTbxc3bKvM=; b=lsHo7YT/3z6s+MOVvrQiFHaKYxy+7DUSNF9/emQWwS/98XmdRfUDAOUYqMWTzQE8JI QPBZNmkdXj3NOKV/2RUCSzbn7W9sUwwwwmpvCJEKMhO7fxt1gLGh9fvXf0PhdaCPaX08 Y6O4+7Y+z7OLGkOMXUCr47yCR/pGH2Ah3l9bz4yJ/oN7cDg6wvQ9jYSFD8f+KQpvC3Wk ewFkAySXjsa0t/KHz3e4cJL/6YWuzJ3oH8Tm65ZeNHBFmkOV0aZexIwUYxoDc8cF6kpe 4Ee+byUPYYCaU5lHdrmAjSpLpUwZEHElZNWf4giymzgMjP/+9GjMBy4wePYD6GtBe4Qa Ar3g== 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=1pZfRn7VIhOLMNi4GJTD7rcBdqN8ePzWIVTbxc3bKvM=; b=M6xtY5nooJK06ym69TQqECY/IhlxWnuT2UZGC2W0ZSWrpL5nl8F4IUtrpPOwGghfFg MFwcxe+u6f39S/B6gx4gNRF7d7VGoTVM2RHxGO9mNeWj32h/JuyH8txr/PVnVjChHjyP sw/PZBmUBhJlMmclMAFic/MFIM943jdlfJGW7QGHCnkkWXlj/ntjNeM/S5KcOmojOY/9 PzBlzAdclp9hUYaZI0QQTvtMsbWBJedrsZP2Gv3wHrm3FDgOpJzx7MB3Bvz+2h5K4ksH OoELeX0YtcymzYQggGILtO3rQnDZGhPMYKNqz2nj8O5hZ78IFwarIqNlDy8NID7kXvHq gR9Q== X-Gm-Message-State: AOAM531543twlYf08IYdY90gMOFwA/KbSbYPDSzJ37zHvAjuqA815Wv/ yr9itiAHRTnnTubEfj9PQifDk7NyknU= X-Google-Smtp-Source: ABdhPJwCrLT5OFJgCI5IvH5kXLEPDnCPM8kDO7mzVDR4tgY8hbSgMehWSD606JCf+EXwreXSWY3f0w== X-Received: by 2002:aa7:d445:: with SMTP id q5mr37297388edr.330.1639134321308; Fri, 10 Dec 2021 03:05:21 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:20 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 08/11] trace-cmd dump: Read strings sections from v7 trace files Date: Fri, 10 Dec 2021 13:05:08 +0200 Message-Id: <20211210110511.98856-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file v7 has sections with metadata strings. When such file is opened with "trace-cmd dump", read that section and store the strings in an internal database. Also, a new argument "--strings" is added to "trace-cmd dump", to display all strings sections from the file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 93 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 1ccdec22..4504645c 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -29,6 +29,8 @@ static int has_clock; static unsigned long file_version; static bool read_compress; static struct tracecmd_compression *compress; +static char *meta_strings; +static int meta_strings_size; enum dump_items { SUMMARY = (1 << 0), @@ -44,6 +46,7 @@ enum dump_items { FLYRECORD = (1 << 10), CLOCK = (1 << 11), SECTIONS = (1 << 12), + STRINGS = (1 << 13), }; struct file_section { @@ -177,6 +180,14 @@ static int read_file_number(int fd, void *digit, int size) return 0; } +static const char *get_metadata_string(int offset) +{ + if (!meta_strings || offset < 0 || meta_strings_size <= offset) + return NULL; + + return meta_strings + offset; +} + static void dump_initial_format(int fd) { char magic[] = TRACECMD_MAGIC; @@ -427,6 +438,7 @@ static void dump_section_header(int fd, enum dump_items v, unsigned short *flags unsigned long long offset, size; unsigned short fl; unsigned short id; + const char *desc; int desc_id; offset = lseek64(fd, 0, SEEK_CUR); @@ -434,12 +446,15 @@ static void dump_section_header(int fd, enum dump_items v, unsigned short *flags die("cannot read the section id"); if (read_file_number(fd, &desc_id, 4)) die("no section description"); + desc = get_metadata_string(desc_id); + if (!desc) + desc = "Uknown"; if (read_file_number(fd, &fl, 2)) die("cannot read the section flags"); if (read_file_number(fd, &size, 8)) die("cannot read section size"); - do_print(v, "\t[Section %d @ %lld, flags 0x%X, %lld bytes]\n", - id, offset, fl, size); + do_print(v, "\t[Section %d @ %lld: \"%s\", flags 0x%X, %lld bytes]\n", + id, offset, desc, fl, size); if (flags) *flags = fl; @@ -943,6 +958,73 @@ static void dump_v6_file(int fd) dump_therest(fd); } +static int read_metadata_strings(int fd, unsigned long long size) +{ + char *str, *strings; + int psize; + int ret; + + strings = realloc(meta_strings, meta_strings_size + size); + if (!strings) + return -1; + meta_strings = strings; + + ret = read_file_bytes(fd, meta_strings + meta_strings_size, size); + if (ret < 0) + return -1; + + do_print(STRINGS, "\t[String @ offset]\n"); + psize = 0; + while (psize < size) { + str = meta_strings + meta_strings_size + psize; + do_print(STRINGS, "\t\t\"%s\" @ %d\n", str, meta_strings_size + psize); + psize += strlen(str) + 1; + } + + meta_strings_size += size; + + return 0; +} + +static void get_meta_strings(int fd) +{ + unsigned long long offset, size; + unsigned int csize, rsize; + unsigned short fl, id; + int desc_id; + + offset = lseek64(fd, 0, SEEK_CUR); + do { + if (read_file_number(fd, &id, 2)) + break; + if (read_file_number(fd, &desc_id, 4)) + die("cannot read section description"); + if (read_file_number(fd, &fl, 2)) + die("cannot read section flags"); + if (read_file_number(fd, &size, 8)) + die("cannot read section size"); + if (id == TRACECMD_OPTION_STRINGS) { + if ((fl & TRACECMD_SEC_FL_COMPRESS)) { + read_file_number(fd, &csize, 4); + read_file_number(fd, &rsize, 4); + lseek64(fd, -8, SEEK_CUR); + if (uncompress_block()) + break; + } else { + rsize = size; + } + read_metadata_strings(fd, rsize); + uncompress_reset(); + } else { + 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"); +} + static void dump_v7_file(int fd) { long long offset; @@ -950,6 +1032,8 @@ static void dump_v7_file(int fd) if (read_file_number(fd, &offset, 8)) die("cannot read offset of the first option section"); + get_meta_strings(fd); + if (lseek64(fd, offset, SEEK_SET) == (off64_t)-1) die("cannot goto options offset %lld", offset); dump_options(fd); @@ -993,6 +1077,7 @@ static void dump_file(const char *file) } enum { + OPT_strings = 241, OPT_verbose = 242, OPT_clock = 243, OPT_all = 244, @@ -1036,6 +1121,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}, + {"strings", no_argument, NULL, OPT_strings}, {"validate", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {"verbose", optional_argument, NULL, OPT_verbose}, @@ -1099,6 +1185,9 @@ void trace_dump(int argc, char **argv) if (trace_set_verbose(optarg) < 0) die("invalid verbose level %s", optarg); break; + case OPT_strings: + verbosity |= STRINGS; + break; default: usage(argv); } From patchwork Fri Dec 10 11:05:09 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: 12669381 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 9A59FC433EF for ; Fri, 10 Dec 2021 11:05:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240377AbhLJLJC (ORCPT ); Fri, 10 Dec 2021 06:09:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240314AbhLJLI6 (ORCPT ); Fri, 10 Dec 2021 06:08:58 -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 ACEE5C061746 for ; Fri, 10 Dec 2021 03:05:23 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id z5so29250652edd.3 for ; Fri, 10 Dec 2021 03:05:23 -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=QqNop7z0zDfR5V4AXrYHtQdcUO0DiKaa8aLuPxN3IAA=; b=H51rKsvJ9/tl5nTOBoanur35PlhlBcGqaBdKkkmThfWWCEpv7w/rKFI9oyvq9iyww5 Lb6n9kGFA5qtqh2a4fwhfxisluUk/qBLB2Zc0/W1yXVft8muRbj225GGEy3EfmT+jcHY iZUbWzmiJ0h8hDK3I3AzBcqTpZJDe6e82pUf8edx9M6AlwcKVDZuTqsOe1DC91858QN/ NeSlvMRkrCCGSVG84OY++XeDGHvxFwmoz+YCT6bJvz5uIdfQLOVHPTngzNkrzqBvuVoI x4I0aueHjJ/EACn2UCwxEqR5dQbX8jAIHTjGP/C3O3UrVUscSVzKIRjvngSOb7aIb6TA W81A== 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=QqNop7z0zDfR5V4AXrYHtQdcUO0DiKaa8aLuPxN3IAA=; b=saC0pLZBHvQVbSsnu2AhsdhoTyR4iYaLwwBNju2+j98J2NUDsnxT0g0hV5xrfcIkm2 Q9e0r2ZEW1EE0ANUT/RdmsvYDwla1A78HQFrLcISPa8O9KREpNyge8WHYls4agh2MZMr +FuhsIfm1J2SymPELbreSrBLjgjRG+vzLE4dpJd5dugV25lYu4v75zIBHj+eF0XMVdEL nB9WLTiRSw2ECkcnGekur5/qgSYah2jBLwWpSpTMR8bJ7w7rni9ddFD0oAHqEklScWKe iU8zZ3/FTa5HNB77leqCvtYhCVADMEBYC/v9+Sx7d9kyDtWZ8m9o7GthhrEk1eXbxFwq Xe1w== X-Gm-Message-State: AOAM531lQ7JCfSVfp0Ih5kqC3Fjy1YmQ3CfQDDaI5fxQigHMAKY11CIM R8rzKapN/5PGIOUVL9HdF779xY2gu0M= X-Google-Smtp-Source: ABdhPJzb8jFE2Z2ULvJEuhICpjd0qGxk8QCl2vQmJm55R0+rzpqX854NIY85eTVKOw/tTZp1i+8v3A== X-Received: by 2002:a05:6402:b23:: with SMTP id bo3mr37046685edb.366.1639134322334; Fri, 10 Dec 2021 03:05:22 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:21 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 09/11] trace-cmd dump: Dump sections content Date: Fri, 10 Dec 2021 13:05:09 +0200 Message-Id: <20211210110511.98856-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org In trace file version 7, dump the content of the headers content, that are stored as sections. Added logic to dump these headers: HEADER_INFO FTRACE_EVENTS EVENT_FORMATS KALLSYM PRINTK CMDLINES Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 4504645c..3b2ba138 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -744,6 +744,46 @@ static void dump_option_section(int fd, unsigned int size, do_print(OPTIONS, "\t\t[Option %s, %d bytes] @ %lld\n", desc, size, sec->offset); } +static void dump_sections(int fd) +{ + struct file_section *sec = sections; + unsigned short flags; + + while (sec) { + if (lseek64(fd, sec->offset, SEEK_SET) == (off_t)-1) + die("cannot goto option offset %lld", sec->offset); + + dump_section_header(fd, sec->verbosity, &flags); + + if ((flags & TRACECMD_SEC_FL_COMPRESS) && uncompress_block()) + die("cannot uncompress section block"); + + switch (sec->id) { + case TRACECMD_OPTION_HEADER_INFO: + dump_header_page(fd); + dump_header_event(fd); + break; + case TRACECMD_OPTION_FTRACE_EVENTS: + dump_ftrace_events_format(fd); + break; + case TRACECMD_OPTION_EVENT_FORMATS: + dump_events_format(fd); + break; + case TRACECMD_OPTION_KALLSYMS: + dump_kallsyms(fd); + break; + case TRACECMD_OPTION_PRINTK: + dump_printk(fd); + break; + case TRACECMD_OPTION_CMDLINES: + dump_cmdlines(fd); + break; + } + uncompress_reset(); + sec = sec->next; + } +} + static int dump_options_read(int fd); static int dump_option_done(int fd, int size) @@ -1037,6 +1077,7 @@ static void dump_v7_file(int fd) if (lseek64(fd, offset, SEEK_SET) == (off64_t)-1) die("cannot goto options offset %lld", offset); dump_options(fd); + dump_sections(fd); } static void free_sections(void) From patchwork Fri Dec 10 11:05:10 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: 12669383 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 A89D7C433FE for ; Fri, 10 Dec 2021 11:05:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240382AbhLJLJD (ORCPT ); Fri, 10 Dec 2021 06:09:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240267AbhLJLI7 (ORCPT ); Fri, 10 Dec 2021 06:08:59 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A84EC061A32 for ; Fri, 10 Dec 2021 03:05:24 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id e3so29127175edu.4 for ; Fri, 10 Dec 2021 03:05:24 -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=9Y3rklqxxMOq7gesFvsO7dFqIEA5fNeflDjZudTR5qY=; b=btVTZ+ERzOK4sRPXa7vILRTZE8x9aZ8NU4kUtwsIyigOVcFU00CtzJMmxdFn8O8STY pm5xOIZUHe76hqmuvTeLJfU+3xIPfkL81ZiFBUIkKpe7/61Mi569EuIVeKDhVxPs6btP bjplch4NQ5sLyboViMCFBU0z4twGqVA4MnblXxxKfIuApBucSOhiKkvzSh+gF26bTh7Y BkInW0QSHxC7xrb9dU26mpZAzikfdgdKr9IIJ9vLyjrQDVQwg2aIayl43JlcB1t+scsT QlQ98VPseQxp/S4zEqFtNLHotV7oTsqOjtRk0ik5mVW9M4ha9YzqMPyTbBoxCelRJijk Exgw== 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=9Y3rklqxxMOq7gesFvsO7dFqIEA5fNeflDjZudTR5qY=; b=LVfKuPpQ66vdZyyN6zJZdcMr9J/Uhn+Hf3kPgKIA719quJx+PePI/jgPvtfLcjvMwg 4tz+bEfxo6tkYAo06dEv2xEAUZdoGthY6jWK2TqvYHBAUEMnQ1+zT6h73gNhBArnbJgp YdOnoeb8PMG1VdOO5KBuatZfHNmfy8XKPi5/ESTVnC+aInFT6g9BFzNW2AQJgQOkNSyG v7nsPr5OVhIAN+lM8b2fhZLcSCr0ahqiVWq4ZdGyYRH9siMANPAsov4Q7pFSs68PDdLa sDlQD3+2Uh+873394GNNxxqqatt766qcszV6pF6S3OVKdfpMmXh2L6OVpY/V2FtZyT45 Y5vw== X-Gm-Message-State: AOAM531i+3z/Vn5nnCw0FMnyfl9hi6cBGqH7fcvQO4mX31ppYqTaKcH0 prUzVoGwj0GV1BmeKtdrrgyeDvl3P5g= X-Google-Smtp-Source: ABdhPJzPaZRRaeBulv7IPnSEYxzx8EqRyJEsmT6NhVk5yjKhr5qQLDe407l3TV1Gyue4DW5g5SMydg== X-Received: by 2002:a05:6402:5106:: with SMTP id m6mr37161527edd.191.1639134323221; Fri, 10 Dec 2021 03:05:23 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:22 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 10/11] trace-cmd dump: Add new argument --sections Date: Fri, 10 Dec 2021 13:05:10 +0200 Message-Id: <20211210110511.98856-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-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 | 72 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 3b2ba138..907ebc90 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -744,7 +744,7 @@ static void dump_option_section(int fd, unsigned int size, do_print(OPTIONS, "\t\t[Option %s, %d bytes] @ %lld\n", desc, size, sec->offset); } -static void dump_sections(int fd) +static void dump_sections(int fd, int count) { struct file_section *sec = sections; unsigned short flags; @@ -782,6 +782,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); @@ -1065,19 +1066,79 @@ static void get_meta_strings(int fd) die("cannot restore the original file location"); } +static int walk_v7_sections(int fd) +{ + unsigned long long offset, soffset, size; + unsigned short fl; + unsigned short id; + int csize, rsize; + int count = 0; + int desc_id; + const char *desc; + + offset = lseek64(fd, 0, SEEK_CUR); + do { + soffset = lseek64(fd, 0, SEEK_CUR); + if (read_file_number(fd, &id, 2)) + break; + if (read_file_number(fd, &desc_id, 4)) + die("cannot read section description"); + desc = get_metadata_string(desc_id); + if (!desc) + desc = "Uknown"; + if (read_file_number(fd, &fl, 2)) + die("cannot read section flags"); + if (read_file_number(fd, &size, 8)) + die("cannot read section size"); + if (id >= TRACECMD_OPTION_MAX) + do_print(SECTIONS, "Unknown section id %d: %s", id, desc); + 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, " + "%lld compressed bytes]\n", + id, soffset, desc, 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, desc, fl, csize, rsize); + size -= 8; + } + } else { + do_print(SECTIONS, "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, %lld bytes]\n", + id, soffset, desc, 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"); get_meta_strings(fd); + sections = walk_v7_sections(fd); - if (lseek64(fd, offset, SEEK_SET) == (off64_t)-1) + 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) @@ -1118,6 +1179,7 @@ static void dump_file(const char *file) } enum { + OPT_sections = 240, OPT_strings = 241, OPT_verbose = 242, OPT_clock = 243, @@ -1163,6 +1225,7 @@ void trace_dump(int argc, char **argv) {"flyrecord", no_argument, NULL, OPT_flyrecord}, {"clock", no_argument, NULL, OPT_clock}, {"strings", no_argument, NULL, OPT_strings}, + {"sections", no_argument, NULL, OPT_sections}, {"validate", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {"verbose", optional_argument, NULL, OPT_verbose}, @@ -1229,6 +1292,9 @@ void trace_dump(int argc, char **argv) case OPT_strings: verbosity |= STRINGS; break; + case OPT_sections: + verbosity |= SECTIONS; + break; default: usage(argv); } From patchwork Fri Dec 10 11:05:11 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: 12669385 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 48802C4332F for ; Fri, 10 Dec 2021 11:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240222AbhLJLJF (ORCPT ); Fri, 10 Dec 2021 06:09:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240281AbhLJLJA (ORCPT ); Fri, 10 Dec 2021 06:09:00 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA16C0617A2 for ; Fri, 10 Dec 2021 03:05:25 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id z5so29250955edd.3 for ; Fri, 10 Dec 2021 03:05:25 -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=b4pWi4A2vvWE4/gD76knLe7GQI/kOC32ie15Oae6/rI=; b=SjP/o+Mq6C+aY3GR2GB0V90jB9pBKGP6ZnYjiTXCSCMY94TRZ7IEIcvZxZ0h+i/yT2 tfM4uoDi06OqeS9wK76L9IFr32YPdxIE/xPa5+LewNJBj1Sx5/WOoPMSVV6x2iTYzVIL 4QW6zdhdfLYzsbMdnDSh4TPOuH9FTiE5qxAhR+PFXS8bwdl6aDxbYUMDn5im81qHU0Rf TL0JoEt4+0FidxLiWkAyyzA/+Liw+gacnZBYocBxLMBxRvJEhQcY6GpcmBGFcoY7Ezgx SpBG1ZfZqvNsa9RQjYBCzbMRXBSTCGt/7dIlkEzPyfzwCnPav6Dz2Ia0kqdMSG7dmrfq YFwQ== 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=b4pWi4A2vvWE4/gD76knLe7GQI/kOC32ie15Oae6/rI=; b=4X0a6pYQYhW0q0vaPy5T0wBKkGCw7cKh5fHxP+OEmoULgQGqNIjBVejaLxyOnEcPaJ z693i3RcpS/SfJKlElr8D94JCd1xSPJz5Wv5O38oxvpiE0EAkiSZmORqAQxskr4eLRei QhNnCmH92cojCOdXv/OvbFqi3YB1R4OkX0V43/JJTYXHXU7TuvVGGi/6/1J3cwpdjbha vyCJgzlCxzWAl5a1cnK5tNmUJYhc4G5X0zv5gqRmJJyG8XVEqqDAm+XX5gjX3+wznmhP HAAdi0xyZBAZIrGquPCz5Zvqur8UoCVVOw2lWjwj5G4EiRXiiSXXHBCjZVxVvhpMffw8 EFAw== X-Gm-Message-State: AOAM533XEaEDXEQyEDQg2gl/QXJ15/0Ia7gVz9eG7G6tCoQ2a9paHiFt DDBRDQSODWTGNCEYzMn15G4GI1rIsZ4= X-Google-Smtp-Source: ABdhPJzN2AjQeO5bvBduu0ggEDBGePhsTkSkCYpOxU8JqtIUySzRz24tVTfEkGRYfM5TuPbX7/YEQA== X-Received: by 2002:aa7:c415:: with SMTP id j21mr36937924edq.289.1639134324111; Fri, 10 Dec 2021 03:05:24 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gs17sm1278887ejc.28.2021.12.10.03.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:05:23 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v6 11/11] trace-cmd dump: Align better the output of flyrecord dump Date: Fri, 10 Dec 2021 13:05:11 +0200 Message-Id: <20211210110511.98856-12-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211210110511.98856-1-tz.stoyanov@gmail.com> References: <20211210110511.98856-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The flyrecord dump prints various file offsets and sizes, that can be huge numbers. Add format arguments to align better the output. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 907ebc90..dd627c4f 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -959,7 +959,7 @@ static void dump_flyrecord(int fd) die("cannot read the cpu %d offset", i); if (read_file_number(fd, &cpu_size, 8)) die("cannot read the cpu %d size", i); - do_print(FLYRECORD, "\t\t %lld %lld\t[offset, size of cpu %d]\n", + do_print(FLYRECORD, "\t %10.lld %10.lld\t[offset, size of cpu %d]\n", cpu_offset, cpu_size, i); } dump_clock(fd);