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; } } From patchwork Wed Jan 26 09:53:28 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: 12724861 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 A2E13C28CF5 for ; Wed, 26 Jan 2022 09:53:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232870AbiAZJxq (ORCPT ); Wed, 26 Jan 2022 04:53:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxq (ORCPT ); Wed, 26 Jan 2022 04:53:46 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CB1FC06161C for ; Wed, 26 Jan 2022 01:53:45 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id j2so37404985ejk.6 for ; Wed, 26 Jan 2022 01:53:45 -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=DuNMznTqCVZx+zCPX/g816HeHkZU9bZzT+abn/p8vqc=; b=orkKQvmhm6rkRlhgeBTaTW6jwCRt979a4VNf+RdikXO7fHmmNU7kPbkzr+z4ea1I7S fOeVcV3ezqEmA8AjDwV/p5M4hnmJTgZ6138sG6qLpjp5TZqI6LNaGJQs1ybtWiq5hIvG 8gOCD/cl0W8HFvfB7G6RIzrY7UoQRu1pUq3fjepB45i77JbwbUQf59snLdBMv0E1P4rf rIuVKJ0+BuWRbVts4lp38+S/5QuOiqT8Yg1alaARm4ufCng9oPVBpcZZYsrKb/bvwY5i fPv0b2ytLjXsLTV9OL+CcmdWw9qcyx+VOTCF4xigu/1ivBI5QY2xTQhZwNodoodinNzi 7WtQ== 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=DuNMznTqCVZx+zCPX/g816HeHkZU9bZzT+abn/p8vqc=; b=x3M1J0M2WCizV2RXZRs9eF0HK3JYJ+GisijfRtOxNqq0uN4Q+pl9xc07Xw3rfm4Qo6 i24Xf3ajwFPojb/Ht49XSGWv4cRlpsKH6nTXKvACKtKvzdFNHKXLKPlYvoRlXAa7htBt qYe9zjLIXkCFXYmFeah1++m9CgIE8s6BDVpCcb5wE5R7T52J9iAkQySE/Az/BKflABB9 jGr9SAa9oO1nX+3o1n4bpOBWjCc4k56fOvj8mTA20S7lSgoX6CT2Ua7QIMeXcHcFqATZ 143J5+O32sdftdP9vbEwAPK5i8S7QoY20LosZ5+r5l3CNto5vSrVKx0RYT/mhaRJHg8N 4v/g== X-Gm-Message-State: AOAM530+SZ2Zlwj0M8JCAr45emNtT+RKHvjN7k1UZei+S+y1ZoEztaBY LCTPUK1BjYxLjbGhkd9tpCvrCCe9NPI= X-Google-Smtp-Source: ABdhPJzsHXhssbEA7KNndEumflUoi8/2vkedxe5yR9sF6nVGh8LEmiz5TcGkgKSEDPqnhhXDrpBCTA== X-Received: by 2002:a17:906:7948:: with SMTP id l8mr19072487ejo.636.1643190824117; Wed, 26 Jan 2022 01:53:44 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:43 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 02/11] trace-cmd dump: Print compression header Date: Wed, 26 Jan 2022 11:53:28 +0200 Message-Id: <20220126095337.570867-3-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 Dump the compression header of trace file version 7 Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index a99dbded..6dad0fef 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -219,6 +219,31 @@ 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; @@ -763,6 +788,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 Wed Jan 26 09:53:29 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: 12724862 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 80FEEC2BA4C for ; Wed, 26 Jan 2022 09:53:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232871AbiAZJxs (ORCPT ); Wed, 26 Jan 2022 04:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxr (ORCPT ); Wed, 26 Jan 2022 04:53:47 -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 D064FC06161C for ; Wed, 26 Jan 2022 01:53:46 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id u24so22129210eds.11 for ; Wed, 26 Jan 2022 01:53:46 -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=wtWPxN8Oue3QBL5BElSqeBvbJ4M85cZaC43Yh6M+LUA=; b=cLqUiQuvBDewWI7Nm6RZ8yXAED/LVV6MhseVx8LGyk0ccldzpACjgcDCLKgRu9xkid ZfrK8jTtPtBhd6YrByiEbYvC/3QLszMWWH6JqFibSRza7/zIFMfiHCy906Tsg3DGHXzJ fP31QpGxVyWltvSs+ZLkiGeZcGxucZk7LV2SCDLmdLTh3Jm8prqp9XTT0lPrbf/q/KPw B9sCgTlYIEtSeZD6F+2pbrt7J6ycEfpDfGRyNYLRmE8G/+6OvqZp/t/ra/SdTOpwlJyb N1wbMhbQ+tgPzLZcKRK2xG302hSAdpgSChjtCYH3uKC9VHoDNsgsnc933NGzFObIthcg T9IQ== 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=wtWPxN8Oue3QBL5BElSqeBvbJ4M85cZaC43Yh6M+LUA=; b=ao8EttrQTWfnRoL5wYq8GMtQhYwe8kvAm0bV9vzCk58jBaY51nVYbCrcOU4udhw4Bg m72nDyn1awZiCJlwmrYISIXbCLgt4d5oj7sNah/j8ZESiXrVG8F/fzX042koE08RnOF8 mYVeOQMm6oUFDv+KDf6QVwf4d/T9h9VSNL4RvRKvGwyJoUZVeC7K1yZun4kJUNlqb1cm BR+emwnBlC7WMgflfTIpzi9nAPqcSLGkhiqM7T+OlCCmrKlh/zTLpEPDwB/fEU/Xt+I4 6wVLtib/PgS36HqRrWp1s7fUfxlzXVhxxEk0mPWoW/fYM7GTbKsNdpYky9LjyIdHN927 W9sA== X-Gm-Message-State: AOAM531N3yc2WWSY1Gz5yogyA3m3WyEy1NpSCdjtrAie/+Yq/DmM2GK0 tzPDFqpO+ZEnVHXUpGE01r4= X-Google-Smtp-Source: ABdhPJx3fe7PrhgLHCBZKLUdUu1B3XxP4DN245BEgqyl/kDRzjFjjoG9X4Qhx60xLnaSiot4tjEOsQ== X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr24707074edr.207.1643190825402; Wed, 26 Jan 2022 01:53:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:44 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 03/11] trace-cmd dump: Add helpers for processing trace file sections Date: Wed, 26 Jan 2022 11:53:29 +0200 Message-Id: <20220126095337.570867-4-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 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 6dad0fef..c4ad6c5b 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) @@ -773,6 +783,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; @@ -798,7 +819,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 Wed Jan 26 09:53:30 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: 12724863 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 1EE42C63682 for ; Wed, 26 Jan 2022 09:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbiAZJxs (ORCPT ); Wed, 26 Jan 2022 04:53:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxs (ORCPT ); Wed, 26 Jan 2022 04:53:48 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04691C061744 for ; Wed, 26 Jan 2022 01:53:48 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id me13so37849489ejb.12 for ; Wed, 26 Jan 2022 01:53:47 -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=GE0s7iwcPZplwcBlTdkT7JDgvtvuOg4fTx6PEReRF0M=; b=X1zjVcrwWYeqepSjZfMQpQxH7zLIySrorDzkV8NI3hA4wLqgVDNcUbl9EPI4BzkO2j DK/pcOKjSpVc4BapwoogimymFx4B4bY64t/cQRL2xzKo/jfTey8ow2TxX6lnkl9cIRF9 oRvzWu9lCpNuRzBBIM99MP7w4Pjnpg8zKCtS/ncAdzy9pgxRTrbEdpAHlougFZyUDA98 +8wFL/4BgUb6XUIua8Txa3dWp5a9V377EpDyJ9Cueibc4KUkciAzmqbkqt50kQIM9/XL HUFuAJmrHxfqTIy7zFz4ZIhERAEz/iZ6qGDb5dIB4d6BepTJ4eaaCdox9fRROM5pYGTy je5w== 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=GE0s7iwcPZplwcBlTdkT7JDgvtvuOg4fTx6PEReRF0M=; b=WEg2cnXp4Kzdoom+mTSqkkWyC2lKOr/xR/5o1wCfsEAZViwU8hE77S9xdafea3iF82 ugQsa1zSf7Sq6Ary6bQaHaK/d/x2tT+SIHncG6dHxak9w2xNs3ifvf2QkAvBpTO0qPwK sS68Cwldw/kPZyR0X8CQYMrQjuboHtOIQhrEBfj0t+2LlR6mDD5F7eTOs0rKX8eD9PSv T2pMdNChHgb511AIUhr5SzxjtTcEn9YM2f7wKjEQSrnx5KXn0y8mskr1DYUQh0F7LC9V u5lGco5u0jBIAF92f3znH9v4rNkjlDxNfxuUqOhqQ5N0lRLg8k90zq8rOfeOtHasdmhk BQ4Q== X-Gm-Message-State: AOAM532ENBbCwM4cWrgQUByj9tjGuODs5hSukABlCNaE2gBC1iYPQS+6 sfJOz6y/0SudQt8jOyVLBATj4+jG/EM= X-Google-Smtp-Source: ABdhPJxQ47Sedtay618Ok4yxhi9BiuOIHyffEmR14OWgPloEeW8UvUEc6usmukuo5O3mFHMp1UOI1A== X-Received: by 2002:a17:907:1b24:: with SMTP id mp36mr19454624ejc.487.1643190826582; Wed, 26 Jan 2022 01:53:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:46 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 04/11] trace-cmd dump: Read recursively all options sections Date: Wed, 26 Jan 2022 11:53:30 +0200 Message-Id: <20220126095337.570867-5-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 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 | 85 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index c4ad6c5b..e04e275a 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -427,6 +427,33 @@ 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, &fl, 2)) + die("cannot read the section flags"); + + if (read_file_number(fd, &desc_id, 4)) + die("no section description"); + + 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; @@ -641,25 +668,54 @@ 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"); @@ -671,7 +727,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: @@ -704,6 +761,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); @@ -711,8 +772,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 Wed Jan 26 09:53:31 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: 12724864 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 600D7C28CF5 for ; Wed, 26 Jan 2022 09:53:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232931AbiAZJxu (ORCPT ); Wed, 26 Jan 2022 04:53:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxt (ORCPT ); Wed, 26 Jan 2022 04:53:49 -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 4EF16C06161C for ; Wed, 26 Jan 2022 01:53:49 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id j23so63034976edp.5 for ; Wed, 26 Jan 2022 01:53:49 -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=MXh/PXlQ/XSIgp9uo48l7Um3pQCiqoeuuS1vtlevE8A=; b=T7FyBh6lh6cVhXOhqq0XeelFjTzsQvT14nNHOjt1exjMBztPhud015c9IbVWljuQ1E U6IyTXDLc1xasr3UkYQsmmhnbmfY3I3f+oV6KXiT2Hb09Z39ctec3FBUE5RS8engn+NU 94GWMbbVSvYQ5CL+iy9QU53LIWf3vPdskuyi9Nomgsu5dKADhbTauLYBjs3JjecBF5K0 k8KHlY8THz3bRP13OXepdJ1lyymaVp8unI4AVzj0saxMlAfl0/eME0F4MqQaU68R75yN toEJq+EXVEi9Q6VGU1XJOTfLHBM1JkN6P3onboNsNhAoEIvAFzKXlOSF9Q+LKEP8J59p kDtw== 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=MXh/PXlQ/XSIgp9uo48l7Um3pQCiqoeuuS1vtlevE8A=; b=rTyQy8n+h+szDla38Y1Q36oHZl29ELcWmQj4NldjqD5Pz+8vIGH8HIHwUH9yFQI5Jw c2p32VXz1GFPS3dg0ph9+HVWInObA1ZWmlsNmcMpvx4Y8X6dWCG+k9t09OSxI+GKOFGZ 8RY647NNLwhQUZEVNJqsYeP5/Be0zLNaEul5m/OEpZ3upMlTr1Wc1N1RkDBDwLe1PMPx 50Hmvghrt7CiCvDdj0X5kNjk21HJCejH2afqZDoNXPXyo4n3KL520lcQgBbD0sGJNm62 wwxJnRqJtiu2sy+Uf3Q3XRVWL+GprU6hwjfD4vWutppQq1NoBQi+X4HYNhQSOuD5q8Wb PQcg== X-Gm-Message-State: AOAM530Ebv3T6wffXczKKKLpul5KXiiu2y0GOuVz/wrv/1s3xAgp6i3O wwtieQgQeR1sO4+fjspRN8y33lrIhPg= X-Google-Smtp-Source: ABdhPJzrKs4hfPZtxFy+1pIW10bGx6/b+WMLzcytilFlnOyr6Q/hjKTGdI7V2jLFBB5YsFSmXq3R2Q== X-Received: by 2002:a05:6402:190a:: with SMTP id e10mr24134463edz.135.1643190827910; Wed, 26 Jan 2022 01:53:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:47 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 05/11] trace-cmd dump: Read extended BUFFER option Date: Wed, 26 Jan 2022 11:53:31 +0200 Message-Id: <20220126095337.570867-6-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 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 | 70 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index e04e275a..e88fe033 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -454,9 +454,18 @@ 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); @@ -464,9 +473,59 @@ static void dump_option_buffer(int fd, int size) if (read_file_number(fd, &offset, 8)) die("cannot read the offset of the buffer option"); - 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); + 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); + } + } static void dump_option_int(int fd, int size, char *desc) @@ -724,7 +783,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 Wed Jan 26 09:53:32 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: 12724865 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 90C43C63682 for ; Wed, 26 Jan 2022 09:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239257AbiAZJxv (ORCPT ); Wed, 26 Jan 2022 04:53:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxu (ORCPT ); Wed, 26 Jan 2022 04:53:50 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B2C8C06161C for ; Wed, 26 Jan 2022 01:53:50 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a8so37614543ejc.8 for ; Wed, 26 Jan 2022 01:53:50 -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=Pq/SuCVC9YOPJ5WW7ivQsm2xNQAEbJ/v3B/pLUr1wcE=; b=fD5r+pSoY7Wa8jng9EB7uUMQAEEjRCE2RYW4QQq5eHnTPep1VTv9UL46h7U74kTXu4 /iKzpCef5mMaJoKuQe0bj1Yai5510Umtm2XBOfuPVeqPSSZob9A4mxhYr7BxG7BiGZMo D9qhbfwEMUAM4MSitk+J99rPz5ARNzeqqjxoGzOM435Bug0iFCDPZPARpO5FGefyk7tg bASf6xOqZIUQfV83xXKgZt/gGcrXMGVLsI84142+yjZXEIRpXt/e9GVnHnb18cEeOuTm 4F2AMgzQFroo4mGGstnSGeScyxNlHtxLKLBhWZ28m6f4zCT3l58Qfi3n16AsMLrB4qLJ jTbQ== 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=Pq/SuCVC9YOPJ5WW7ivQsm2xNQAEbJ/v3B/pLUr1wcE=; b=wg+av6rZ2OHpqFbuwlEsR4EPs+fpVuDo295YyE3FDgs4oHrL99O4vGkkJMfxx5q43P T56DfLsZQJmu4th0M/kbbs4dWG94U7a1cvpiIdAuoxkY3HW7/mCKlRjY8dzxbB/K6you it4p8F8wKeoxyb3zzKzoeRIJKM9VphVgq5qWtwW+CU4CJe06P1P3aLhOrsZIlmeZshPW B0YZ2qdAoctr4ybLPI0iSklmBkSute3gKBxAudlO9H0Yq6nqK1aBFMoo5EvpGLiRgkjQ G7LbjywK7EdMYHclNl/Mmww+L3GY1wfnJGORKN5E/R59/BXi/lkSsFvQ5jqy6OgN0oaR 6LRw== X-Gm-Message-State: AOAM530prnsZVrBJi0thkF0X0hbn41Y09mUfj07JQdXw5XwdQVM6Vf75 KTrYZQWJumaEQGSKp39nT49IpzT42dk= X-Google-Smtp-Source: ABdhPJw2rjuIeO20dh7Ris7MTllEyJ7jFLxyY9RfUncvS1JSLhsg22JKZIy+ZxOzqBNbwWwjTC+VNQ== X-Received: by 2002:a17:907:96ac:: with SMTP id hd44mr10771543ejc.88.1643190829255; Wed, 26 Jan 2022 01:53:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:48 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 06/11] trace-cmd dump: Dump sections Date: Wed, 26 Jan 2022 11:53:32 +0200 Message-Id: <20220126095337.570867-7-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 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 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index e88fe033..bb168370 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -727,6 +727,25 @@ 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) @@ -821,6 +840,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 Wed Jan 26 09:53:33 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: 12724866 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 38455C2BA4C for ; Wed, 26 Jan 2022 09:53:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239250AbiAZJxw (ORCPT ); Wed, 26 Jan 2022 04:53:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxw (ORCPT ); Wed, 26 Jan 2022 04:53:52 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFF0DC06161C for ; Wed, 26 Jan 2022 01:53:51 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id k25so37488656ejp.5 for ; Wed, 26 Jan 2022 01:53:51 -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=LadM73lqTUtDTGSoV/g9MNtuOhmQmX5nNaG1Uv1+FA8=; b=hoIleTQRZJ96ZU3xKa0XFl+bx5LWM4XDc4bw9IY23a3Kb7Wq5GjCZseJSxkyEwJVjC GUhtC46TkM4YqmR11Ia5fHore/9JhR+8cVVZssJe7QzWE+vKCzuuod84FhUu6aQtXp8f bUlY1av4ICBlG6AWxCl/UOj8JBN+Z27R1JW/D2d/7+YLiX5ii+gZDPvhpBuQNcGLGNgs +kTjvHRfSBBid9zdcwDu8SUBlOJ0WZNsEZSncwKRBB8qN50INlYdxjraGyVfsPgqCzl0 6DZxlWJqIuUYoidbK4km6OF3Oldx5tp7A2MWQwr5OfmYuxSGyn5YIZKAMmc0no6R/WtU dhNA== 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=LadM73lqTUtDTGSoV/g9MNtuOhmQmX5nNaG1Uv1+FA8=; b=j6sw0JPjX8DC22YePNzBCIGooUA1uzhCsf3bW9vM4uREbHhfINcUlf1BcdHwyE+fh9 UhsQdKCm9WLvRadq4hX3PZSCkW8VbeveDrEvH1GwzsqjaxToVcfEOAd+b7siisVfd86w LuwtJiw2XOVL3uhrODYgH+i1dTlCR4CEKSNI0grkpZ+6q7SXcPgNtgRiDMIq8OpJ6QMe 5oHkfzI+T7ttiXucOSYnlngRGQ6MCiIx/B9lPMq2VR80iblEFYxNo3qlC/L4tEBHQsaC lXEE1oo8MSq2xc7UFNEURXkjn2tC+lxjy2oYtD/cOJM3gdZiaZVHXc5AMOKnIe0gOJLA pX4Q== X-Gm-Message-State: AOAM530HHmWX7aqtIxiEOCFvtxu7SVZd4ntsE3aNNSC4kiVP9g+bIxpi ggzxxKuz1N2dYIjovvVgb1+3sahER3A= X-Google-Smtp-Source: ABdhPJytbH1AAQaMcoV90klEmuCqkSKXjDKMBJ4a/JWlioJ4ANuKuW5C20AmkB+RndP4tKcqHgd5xg== X-Received: by 2002:a17:906:f1d2:: with SMTP id gx18mr19559232ejb.674.1643190830477; Wed, 26 Jan 2022 01:53:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:50 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 07/11] trace-cmd dump: Dump trace file version 7 Date: Wed, 26 Jan 2022 11:53:33 +0200 Message-Id: <20220126095337.570867-8-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 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 | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index bb168370..31878c3a 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -950,6 +950,32 @@ 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; @@ -977,15 +1003,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 Wed Jan 26 09:53:34 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: 12724867 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 5617AC28CF5 for ; Wed, 26 Jan 2022 09:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239318AbiAZJxx (ORCPT ); Wed, 26 Jan 2022 04:53:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxx (ORCPT ); Wed, 26 Jan 2022 04:53:53 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 147D1C06161C for ; Wed, 26 Jan 2022 01:53:53 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id s13so37750977ejy.3 for ; Wed, 26 Jan 2022 01:53:53 -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=+POxsbu5fGLbRlmKIDiFIFAxsZz/f8OKNIdU5QPpHzk=; b=jH9IMRIk0QHi3yqkegLWbr6I5Bbr2/lHOogc8/S53D0Jqd/SLyI1dsZhvdwFl/5v4w AcNYrV//axg0IPAdMyoiLEoydHpkfOhncizixUR0byKiKgoxy+lrPrPid3wxFm4Xeapc mc9XeCqwwBL0kZmyf5lGCyNx1kN0La03egNLohZe3QfBuZkaDTDm67DMuwWXGX7JDazZ 2QuUtHCTkfba8JOzDNzbF9O3n3MU//zuBv/7RlaKa5/PUavyXgBKssd6bYkYxN2KvfhA RZcGyYP117PMr6msd1OgnM5kclwBLCE8vmM3lMWePgp5Yn5We8VEPA5Bbv97IzyFOCGZ Anww== 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=+POxsbu5fGLbRlmKIDiFIFAxsZz/f8OKNIdU5QPpHzk=; b=SpJUxP1sogbiNtOArTZsMjIUVK/1pofdeF1w9DWFmpZY3JKqcM8CQvxcKYHrMAQuKZ m0OS61i3K/a3TaFie99vw1PVKWqH7DwNFoP9aeoCXU95OFQ5iGiXKodoUnsaOz3LSLIe dtJSuO+OdivV50vMAYrPNCnY/t08Ag2SWUdSLCTGMculGsCkISu1peckZI7ZZy1OPDXB qwB97pm3T+3kRRo4helHjs8Kgs8ExbyJTLA3We55FLT7Ps00T6grIOSchYOYZrwtUx2m OFRzcOqOPpqgQ3EBWydpIFV9ZLztqWnF997/svMewG5HswzTxViRJBuLvjILVwyKUM+n 59sA== X-Gm-Message-State: AOAM530a6BHg0pNcE5Zgh95bs47es/p//fOPD9BjYaKDGzWgAS//vBQ/ qaOh0SPlUC+yn5Fdk6urIGRfKPDOX5c= X-Google-Smtp-Source: ABdhPJwwbSigdi5kMvBzmOWlFS4c5QCFFIEVU90m2yDKJw4WRQRYoniZtWCCut39LOlHIR9xfvRYig== X-Received: by 2002:a17:907:3f89:: with SMTP id hr9mr1659802ejc.3.1643190831596; Wed, 26 Jan 2022 01:53:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:51 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 08/11] trace-cmd dump: Read strings sections from v7 trace files Date: Wed, 26 Jan 2022 11:53:34 +0200 Message-Id: <20220126095337.570867-9-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 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 | 94 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 31878c3a..13e79002 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 { @@ -179,6 +182,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; @@ -432,6 +443,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); @@ -444,11 +456,15 @@ static void dump_section_header(int fd, enum dump_items v, unsigned short *flags if (read_file_number(fd, &desc_id, 4)) die("no section description"); + desc = get_metadata_string(desc_id); + if (!desc) + desc = "Unknown"; + 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; @@ -963,6 +979,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, &fl, 2)) + die("cannot read section flags"); + if (read_file_number(fd, &desc_id, 4)) + die("cannot read section description"); + 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; @@ -970,6 +1053,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); @@ -1014,6 +1099,7 @@ static void dump_file(const char *file) } enum { + OPT_strings = 241, OPT_verbose = 242, OPT_clock = 243, OPT_all = 244, @@ -1057,6 +1143,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}, @@ -1120,6 +1207,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 Wed Jan 26 09:53:35 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: 12724868 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 89660C2BA4C for ; Wed, 26 Jan 2022 09:53:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239320AbiAZJxz (ORCPT ); Wed, 26 Jan 2022 04:53:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJxy (ORCPT ); Wed, 26 Jan 2022 04:53:54 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B0D5C06161C for ; Wed, 26 Jan 2022 01:53:54 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id h7so37753706ejf.1 for ; Wed, 26 Jan 2022 01:53:54 -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=3QDeFnfuoF/bRZaQA4Qex16ZXM38q819ZL/YpY7Ys1o=; b=fMNFz+lH78I2pUFV91jPCqzbsp/rISmk+KmDZxI4K52xeudOtT/OKy7FIqrG0Ezkt1 nl5AIKXkLHSXDn+5AHEcShyt5eTulyX6r5HXwW3tP1I8324VT/mqtxuKawNNo44Xg9/S +yFmE7UQnyXwgJfeP4dpgs/r7pv0PNn3mpdLjZnEXwQEN8z/8vTmtCuMcz/fKlslEWRG G4/WXbqB5tnjwiLOEcyEmVKUXiyDIxZJluL0hx7uD/ZXk8rGz/F+p44/iHYsQwIvqGn2 rrRSMLvzFOhh1Qr7IKA2CQIpqFnd+5dMWvKbTyUaXqJWSXuRiU7JlJGfAsYwJ9h9EvmU 5JiQ== 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=3QDeFnfuoF/bRZaQA4Qex16ZXM38q819ZL/YpY7Ys1o=; b=4cWIuOffeBQo/hTHu5XyvyIFChg0vtwQ8S6M5GWZiXQxXYoPpxmgCWKRuOfRuPkxo1 TR49BdNTl6Qg0qT4F2THepc+YHaIONaynUDqkVex0CLGvTjflHGdu9oz6GCUOZVdCtmU KZUnFxHgAL93rd46A9LPyp7oGOhRQEB3XP9ozKAiPMlKGDZP11y5Q3i1cgwATtEVMSc/ 0ZEKtg7Bab5SvXuBjsNRirmBDi4xaYAJrZYjPD/5pl/Kd1DOL7QFCLu8XSwQMAzfNUmT 6HfUvc+NzS5Ed/6JDMMzcTT+/PA9c6nqMjGyaUZcncPHteSRrcMez4FuFQbS6Fcj69tD xu6w== X-Gm-Message-State: AOAM532NIQjHpol9kSGVvb11L+EDmVAbRkIZG07g37ebftYXpNhkmnJ3 f4vAw9pT6JsxjtZ4xkwW6IJZtH2kGJ8= X-Google-Smtp-Source: ABdhPJzF4bFuHvzyPAs7PBLL+Z9xhMyPCafmJCt486icdiqRcrCZqKsLyZhYdL4vh6TOvoKgwzaitA== X-Received: by 2002:a17:907:7204:: with SMTP id dr4mr7048726ejc.195.1643190832827; Wed, 26 Jan 2022 01:53:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:52 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 09/11] trace-cmd dump: Dump sections content Date: Wed, 26 Jan 2022 11:53:35 +0200 Message-Id: <20220126095337.570867-10-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 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 13e79002..19f77687 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -762,6 +762,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) @@ -1059,6 +1099,7 @@ static void dump_v7_file(int fd) die("cannot goto options offset %lld", offset); dump_options(fd); + dump_sections(fd); } static void free_sections(void) From patchwork Wed Jan 26 09:53:36 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: 12724869 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 02D76C63682 for ; Wed, 26 Jan 2022 09:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239322AbiAZJx4 (ORCPT ); Wed, 26 Jan 2022 04:53:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJx4 (ORCPT ); Wed, 26 Jan 2022 04:53:56 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F42C06161C for ; Wed, 26 Jan 2022 01:53:55 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id ah7so37537576ejc.4 for ; Wed, 26 Jan 2022 01:53:55 -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=OIR+jEwVy6Y6Ra9hmuFm+M+zsZN6yh2Xm1VXibJKyVs=; b=JnrUIZL1D2wcjWxi30B5Dg/Fp/ugMxhdj7+bzorWkEg0w6QJtQ4FDgo33gll2li96e 7mu1ss5xBXI9R/fuf3N5cULGXhRQJrDcVuW7e7aD08FsrCull08F8R8GH1SRXR8jDutl KXfxP/FhLrI+PpZmgMifDs1jK+yxiIr35XrBjKrJfy6Id/hTkn3rIkGVE6pSJBZnjJ5y SaOe2/fUeuiBCo8NAh9M5cOXYl80j+Cgg3FzUdGwCYCHEo31X/PVkIWRy4gpbZ+0Icg9 Rl0SIfJxn0YaJOlEzmRBBskCnUX4xHD8ZvkSlEwXGIF7b4he2DVf8oIa/mIB6yrvlwI2 KL0g== 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=OIR+jEwVy6Y6Ra9hmuFm+M+zsZN6yh2Xm1VXibJKyVs=; b=XkNP0hz/EORaXAVtcmsNa5JfMUlNSq+EnlVU0AtZFaYLGLs6cPhjiWRYQTw3Rp7zOE r5fJatPgPrzB5Gkkh+Yq2e+6UmjieZJtzxlqi5tXaRFFu48GoR4/htgneLN8OzgBYQlU 1mHYid9aKw3qYLoVQRFAk2Jw9cO3nookS1kMWGYbADv4Xr41xfhQLIDdNBiIWCBg4GFb /t9JnsXSXde3SdeH2SZU7Jm4V3ZOnnwWatiA7tA1/NC7uufW3c6HbspmF0TGJJPwGCZX 01qfp5sLDQvuXTDgEin/75YLVLqikztlpgZAbJ5j50mvlo/nlpkvoxQ0NWZTTXfJPAb7 ukIg== X-Gm-Message-State: AOAM532X6FDMx2rkCxlc5j59F+n7dM/xHYN46Gt1MZLeHwBjoYQcWfHp ZQAqzCjTx+cf0JgnNDyaxNHSO/n4ubY= X-Google-Smtp-Source: ABdhPJz+78ve8ivj33pyNpvDkwa5+KoPe+g8yoytmeBCCfVpEfYgIXBOCOq/Bd596tdcEKAL2VSOOA== X-Received: by 2002:a17:907:7f86:: with SMTP id qk6mr19322238ejc.631.1643190834188; Wed, 26 Jan 2022 01:53:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:53 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 10/11] trace-cmd dump: Add new argument --sections Date: Wed, 26 Jan 2022 11:53:36 +0200 Message-Id: <20220126095337.570867-11-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 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 | 81 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 19f77687..d6efa425 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -762,7 +762,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; @@ -800,6 +800,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); @@ -1086,20 +1087,89 @@ 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, &fl, 2)) + die("cannot read section flags"); + + if (read_file_number(fd, &desc_id, 4)) + die("cannot read section description"); + + desc = get_metadata_string(desc_id); + if (!desc) + desc = "Unknown"; + + 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) @@ -1140,6 +1210,7 @@ static void dump_file(const char *file) } enum { + OPT_sections = 240, OPT_strings = 241, OPT_verbose = 242, OPT_clock = 243, @@ -1185,6 +1256,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}, @@ -1251,6 +1323,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 Wed Jan 26 09:53:37 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: 12724870 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 8F62CC28CF5 for ; Wed, 26 Jan 2022 09:53:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239395AbiAZJx5 (ORCPT ); Wed, 26 Jan 2022 04:53:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbiAZJx5 (ORCPT ); Wed, 26 Jan 2022 04:53:57 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F15E2C06161C for ; Wed, 26 Jan 2022 01:53:56 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id jx6so37828752ejb.0 for ; Wed, 26 Jan 2022 01:53:56 -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=agcjCdY91hsZPtY3OJa43Tz/ThqoZkahTKUJIAC9Q5c=; b=DBdZTWHhfSD2UVLPTRThEB7h+Woz2zQz6mEDkjlE4rek94B3f/WmFVT4JwPFKFIAEl RhgKQx0jfbDwKfjmisxAwPFJBDVIq3X1Sus5qmEhhYchqZxaXKxhT6S8KxXvyP1KtNHv XIM0Dyuw2mB4Fbu5euRMTJFWtrKm1tk8ghjSDRGixR3Iy/oHx0M9Lury5rn75xMn4AOH ZqCx4pNGFapkpJQ2f82A6INBxMzLay0G4i1JOV3peUQucIbOzP8o14fYHGXVcarePqXm BRwCyaSGUC4GlSKlhona+nsu79Es+q6bdO6DANzQ3ugXtHA2bU//NUDLiLusislsh67k Z7XA== 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=agcjCdY91hsZPtY3OJa43Tz/ThqoZkahTKUJIAC9Q5c=; b=I1hfvh0dlBCp28W8YV3EdiXv1oSljb1n0u4pfZDtVsO2ZtXoge/2T03vCOEGusmf1h b72taskgGOSstWqBPKD0OQHLFMm2dc2yO/SOD52i7jINWtLqB6C/dTWIHJkYvXJgyD4Z TBywdC3AegjIienjLWbERPnF4EotnNUvAt8wbA2C05p/ACK6Yzaci/vaZd9Aeqorh38p g3XTatjPjWlIlkNXCRXHQTLg+hj41JKED7oIcOLu/PyYDPP4StTkZJxed0KORnfrbAqd 9k5d1PuUsQMZ3QxSAAVIAegYiA39Z7lpbtXqYmICeBi+rk/8n2JA07q4Lgm9twvQ+3JW grxQ== X-Gm-Message-State: AOAM531pXutN9ebl6iqNJEQbMecix63PX2RmFStKawU6u/YIE70+803X CaEkVTpPPFtnVWVS3aOb7pA5KTdj8fE= X-Google-Smtp-Source: ABdhPJyrsETWB/GONJW246Ks6xl3l9BYqcRqdBbafHIj3SyOnsw3WqUQREWATIg6KW37ytdpTUmyyQ== X-Received: by 2002:a17:907:7ea8:: with SMTP id qb40mr12499990ejc.541.1643190835522; Wed, 26 Jan 2022 01:53:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 01:53:54 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v8 11/11] trace-cmd dump: Align better the output of flyrecord dump Date: Wed, 26 Jan 2022 11:53:37 +0200 Message-Id: <20220126095337.570867-12-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 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 d6efa425..7ed86f61 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -980,7 +980,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);