From patchwork Thu Nov 11 15:12:41 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: 12615143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D9D8C433FE for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2378161268 for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231739AbhKKPPs (ORCPT ); Thu, 11 Nov 2021 10:15:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbhKKPPo (ORCPT ); Thu, 11 Nov 2021 10:15:44 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35E58C061767 for ; Thu, 11 Nov 2021 07:12:55 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id w1so25481885edd.10 for ; Thu, 11 Nov 2021 07:12: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=9oXXCwAzmHcpVWjxzfY8kimTg/T2kFD6d0BsjQXDCWI=; b=A1y+xJwzI/akXTa1kKJ/drmzIKDzAh0Ujb3Fi7Kh/6OmqWvhg/Dg7b3ppqBl0TmVYW R+FT1NpuOeyYmg+YcUAoqjP0khteB9e2YLrw1cFqk2SMeEmD4XRz8jbD4+0BPeK7mcwa ng64iikRQfuAffpPb+NAEXroaR169orZ6ZrG8FFuFom7U2REyBQv1uaFF2AXYOSE/D7S 8I2av4aXg1ktRYMYF+lCurjcnN62ULwBb9SD4tsImZIP9oJHyHS3QtY6n1W6VX9iE7TU Q8xqa7nmI6nS8VwXDA5FwVfcABItt6r1aSYXfN3mSgYwBqe8KAyqizpIIoadoQordlSH /+DA== 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=9oXXCwAzmHcpVWjxzfY8kimTg/T2kFD6d0BsjQXDCWI=; b=xBqokkIzyuaaFjB6ZoZn4C+KZPI9Yq59XYF8am5E2vGwhWFaRhk3JJ4WCT9rkoG/M/ NOtUOOaFP/09rR+16YDb9D0LlHYALXeNvHt/2WSLYrsU2435ZrJtO6XfgAVID0XpYCt5 DlaB6m4U6T/zWKJsx7WYXo+DO1kSuE7LV0zUcG2o+ShsL5diOIcg7/i+N478qywffiGY 1Oxa0EZvAXrjBWadHFjl5jHiZRQGjzplRTEJ48UqF/LUv/KT68EPeGIgriPuj6LwW4/s llXH8l1Cy0Is6mEuRrZawHKDXiDzuAz+rgJiaFVoMo5NAcndhNd2WXX+KqEcyHdE4Xyu 2aDg== X-Gm-Message-State: AOAM532shxNPZ4BaxnOPvwDpPGkOQvPdXwSOv+J+TqVapjJf+CSmvBpx LwmBL/e4p+3Z6l51FPtO1AXdxkeA53XBzA== X-Google-Smtp-Source: ABdhPJw2G6o67mZo2m8QSC2ZzeTYQMDySJDA/gnS9Nsyd884gklh0dHLomQzR7foB6fulkYhfM6O8Q== X-Received: by 2002:a17:907:1b11:: with SMTP id mp17mr10218581ejc.275.1636643573733; Thu, 11 Nov 2021 07:12:53 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:53 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 01/10] trace-cmd dump: Add helpers for processing trace file version 7 Date: Thu, 11 Nov 2021 17:12:41 +0200 Message-Id: <20211111151250.87023-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 b19ce89a..75e40911 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 Thu Nov 11 15:12:42 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: 12615145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DA8DC433EF for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5994A61268 for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233909AbhKKPPs (ORCPT ); Thu, 11 Nov 2021 10:15:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234025AbhKKPPp (ORCPT ); Thu, 11 Nov 2021 10:15:45 -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 275EFC0613F5 for ; Thu, 11 Nov 2021 07:12:56 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id f4so25358344edx.12 for ; Thu, 11 Nov 2021 07:12: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=2pB8ZvqNIlqoaTXy8qeSvxTG+PBih+zcah2HllOhwAE=; b=QY/DK3MaIOJeFcnJelW84JTPn7y0Ec2krugmrpQJi08vE1gnN3KjN57he20KlKtd5J PUe2+wswQWd2IvOzJeLcnXrhvmY6TnTMvmj7F8rBghe/fSUHNT8I8CjfgDYgb3gn0wiw B6PhruSFfYMi4c52WNJ/JPF+5D8yiLOViyMYMTvZzqip4dDu1FBAPgdu2jCcK51M711E jnEq7T/2QGnmJG0uxp+DhyIdTZfu2yRGy9wQlG9zvpmvs+F0QlMwHf4HK3UxhXrv7To4 w2H8Voi92B9Gk50X0Hcq0csh2g0m5eUNUsHkSKxM1Jnf4lxBC5qRR2stQSkdHwJdoeT8 6crA== 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=2pB8ZvqNIlqoaTXy8qeSvxTG+PBih+zcah2HllOhwAE=; b=urXSgrOjxyz3aImlyfAJJdAP5QzGaQ+Uavi4l+R4AlyDbrxbKndhhNuujEjYa0LEaN 2LBn2pftoBZobA+mSuvq7jmh3fX5bhVIkq4uVQpGvVH5FdFjyvu4JsQoypLMCYye6HOE PeV9C4g4FqLfV8ZcCOVC4watc5eZseLorE6f5UAqYCVGocVo2MdsU+93YEJdlU/atT9L ohMhFdSFYOjYyrAnZW0L+uge9AtybCFPVhGQ4HYNDUfjvg/4YXprxm5bTp8eInADAsPv Nf+vq3QPMq93JCpsKEXvkLfruBY1HJy0u1MRhIdBJObtkuEMKUhduDoemgUvk2XhT5aV Y+Og== X-Gm-Message-State: AOAM5303QVRn1c1dFF6o2wGy11Kai9vXqBwl/pceBUFuxoEoAxHHUDzd jcwIsdEats7RwPawrBrsLNMtFpuILCw4Kg== X-Google-Smtp-Source: ABdhPJycdbmX1pKPpxV5CSsGwyeTkyVrMrycGICnOBngUkK9fhzmGRSBpC3GsSYK6Z655wsXJyNKJw== X-Received: by 2002:a05:6402:1d9a:: with SMTP id dk26mr10778891edb.222.1636643574732; Thu, 11 Nov 2021 07:12:54 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:54 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 02/10] trace-cmd dump: Print compression header Date: Thu, 11 Nov 2021 17:12:42 +0200 Message-Id: <20211111151250.87023-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 75e40911..a1fc6d7b 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 Thu Nov 11 15:12:43 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: 12615147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9803C4332F for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C4250603E9 for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234025AbhKKPPt (ORCPT ); Thu, 11 Nov 2021 10:15:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234029AbhKKPPq (ORCPT ); Thu, 11 Nov 2021 10:15:46 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B5CEC06127A for ; Thu, 11 Nov 2021 07:12:57 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id f4so25358491edx.12 for ; Thu, 11 Nov 2021 07:12:57 -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=/LcOcTAQq/E0EFpf44euFOpIpRgzGloaNazoVxOO5cs=; b=TxV6oe6XhsI7vfMIo3quV6Z81t2r+2WLUb8JOD2oRuVl801/2BjhD5s3lAA9Cupyqf AmMhsst3Wk5nfsofRJr+bybcqlgQkwzXRXa7Ams2tv0oDEDsBGr8+AE6QZH9brXZM8bm uHegJn4Og/lY0byKYEDIlfafCox5WC8g7QoH/wkJhKWDa6hV1PCCI17JaJw+G4xydOqU tOzpzlhllHLtOcPPL87AU49x4pbDCPmfenzWnvCSDx0T0Ue7KubylbJHS7Kw5wH2Ruv3 ICmHmPDgDbcEl6ckTnjQTdwV44QIcOEArjJ5m2936uq3L/GYna6l2QFEMQvmoB78FXfV 4yXw== 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=/LcOcTAQq/E0EFpf44euFOpIpRgzGloaNazoVxOO5cs=; b=As3APYnqB8EDsNZVXHke8aDHZgPyEtApPU1OrrlhfxeFGttW0F072pWm4yPQOAXh4q 346z1uWC0O9ivNBqugzMdyPsZ+SVm6ZjPvMh1FRTtyA/24WVXEiQppJ8v82H8DPo4WTK /KgzvZ3aL/VPamis1BdCbGq+tGZgNeD426xGL4wFfYh/rj3T1TPdgAeUUSkVE5zVY3dQ 3z9Sm+pe7bdV8OQkLCeg8Lsf32ujw8BQiZUoV+qG0FbhTyofBZ+WuimXLWg7nVNuwHf9 xTchxuCz/u69W4kyGYn1OQyEd2k8T+yEXV4eOKKLng4rxXxGU5lpsCJ+bytvIc49jhvN eE3g== X-Gm-Message-State: AOAM531BCGWrVd/KqRAFJHepyd+IV/6PR4tByBxuEDD4meZiBBK4cJnU yEUVKgvuC6Wp+r3ML7+w9L4MytrnJKHfbw== X-Google-Smtp-Source: ABdhPJyO7uyD5i0zXu4RtKeQBJ5Z4XOb2nQtWnC578YkjFSTFpYi7CV6wBfB4HhyBDXRVqnAVWExBw== X-Received: by 2002:a17:906:3056:: with SMTP id d22mr3983981ejd.548.1636643575692; Thu, 11 Nov 2021 07:12:55 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:55 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 03/10] trace-cmd dump: Add helpers for processing trace file sections Date: Thu, 11 Nov 2021 17:12:43 +0200 Message-Id: <20211111151250.87023-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 a1fc6d7b..e3c40a0d 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 Thu Nov 11 15:12:44 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: 12615149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F704C43219 for ; Thu, 11 Nov 2021 15:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE11361252 for ; Thu, 11 Nov 2021 15:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234029AbhKKPPt (ORCPT ); Thu, 11 Nov 2021 10:15:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234030AbhKKPPr (ORCPT ); Thu, 11 Nov 2021 10:15:47 -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 EBF48C061766 for ; Thu, 11 Nov 2021 07:12:57 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id f8so25656165edy.4 for ; Thu, 11 Nov 2021 07:12:57 -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=PH/XyhHdUEZTPFiWA1EBnh+dtXsTepoAuGsqMwaJ0o0=; b=lnbC5n/240a5HEpY2O7k7VB9fc/ihUyXlqjG6kK7H1sLQokf4MUUlaS5cwIk82jUz/ z9wxMtDhuu62o++CzzkRfvcTAdj02eBXpVQ40SeawPWY+J7eotMvruApeNy8MHMoDDvb 9h1OT/jkKs2mW0UYQjt2cZbfQC2n5xGcfehjIwd6yTaj/7SjeW0No13JGRHd5swQADat CVr5x3cZ2pvJ/Qacv0f631L4OXFjlX44A+4ASo6TP1goWNpNIPgKsl/6agy+ybRTgVDd G0+9iB0oalhU8BK8xp+hEXc34nqgOWkTtkxo9KUhdtjnREfZ0yTZMMsA0p/46c3i551h LUKw== 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=PH/XyhHdUEZTPFiWA1EBnh+dtXsTepoAuGsqMwaJ0o0=; b=wC/At5pfttNx3gCe3JCnBFRAmuiu/BYsNYlUA2eW1wLrJvYoaIsyLHYKeefW2hIkZs PaY+04ubcT0FgGBUvZ8SiQBoc71kp8oPSpx6Q03msV3PP5uNue/4YL/YeX9Tql/2VYV7 H9JvDoLNg8iXqi4pl0GnvZMh5Z2QTt/X7MppxYS4v2iq+UGD2mD9HuQtud5az54193IL QzVNm3a5nPxr0+z+ZFY39qIH+6iNLd+fmI/BhIUEcdGTyPLDp1Pu2NaEGLFzESi/SQvk WbXUC5kr+Mk/2D3jUbkDNUfXLxoARgUxdbynQFfzIf56FwfKdRW45VDjZZDEmTjj5NdM kgng== X-Gm-Message-State: AOAM5332LVwG4Ynorj57I3MaHVA4NSKwW2m34u6Fls9eDDRvB/GHs2XI VIKzNffsis/zp/mrHf4efLTq9c0SQtYC+Q== X-Google-Smtp-Source: ABdhPJzHZveY2W4DxVN8kt8+80xCBIESjsxVu3hqmqf12AQaJsDrjVGhVLcZEiVN98qPWbcYoZBKqQ== X-Received: by 2002:a05:6402:2808:: with SMTP id h8mr10770618ede.267.1636643576552; Thu, 11 Nov 2021 07:12:56 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:56 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 04/10] trace-cmd dump: Read recursively all options sections Date: Thu, 11 Nov 2021 17:12:44 +0200 Message-Id: <20211111151250.87023-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Trace file version 7 supports multiple options sections in the file. The DONE option is extended to hold the offset to the next options section. A new logic for handling the extended DONE option and to read recursively all options sections is added. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 76 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index e3c40a0d..a808c7d7 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -422,6 +422,30 @@ static void dump_option_string(int fd, int size, char *desc) read_dump_string(fd, size, OPTIONS); } +static void dump_section_header(int fd, enum dump_items v, unsigned short *flags) +{ + unsigned long long offset; + unsigned short fl; + char buf[DUMP_SIZE]; + unsigned short id; + int size; + + offset = lseek64(fd, 0, SEEK_CUR); + if (read_file_number(fd, &id, 2)) + die("cannot read the section id"); + if (read_file_string(fd, buf, DUMP_SIZE)) + die("no section description"); + if (read_file_number(fd, &fl, 2)) + die("cannot read the section flags"); + if (read_file_number(fd, &size, 4)) + die("cannot read section size"); + do_print(v, "\t[Section %d @ %lld: \"%s\", flags 0x%X, %d bytes]\n", + id, offset, buf, fl, size); + + if (flags) + *flags = fl; +} + static void dump_option_buffer(int fd, int size) { unsigned long long offset; @@ -636,25 +660,48 @@ void dump_option_tsc2nsec(int fd, int size) do_print(OPTIONS, "%d %d %llu [multiplier, shift, offset]\n", mult, shift, offset); } -static void dump_options(int fd) +static int dump_options_read(int fd); + +static int dump_option_done(int fd, int size) { + unsigned long long offset; + + do_print(OPTIONS, "\t\t[Option DONE, %d bytes]\n", size); + + if (file_version < FILE_VERSION_SECTIONS || size < 8) + return 0; + if (read_file_number(fd, &offset, 8)) + die("cannot read the next options offset"); + do_print(OPTIONS, "%lld\n", offset); + if (!offset) + return 0; + + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) + die("cannot goto next options offset %lld", offset); + return dump_options_read(fd); +} + +static int dump_options_read(int fd) +{ + unsigned short flags = 0; unsigned short option; unsigned int size; int count = 0; + if (file_version >= FILE_VERSION_SECTIONS) + dump_section_header(fd, OPTIONS, &flags); + if ((flags & TRACECMD_SEC_FL_COMPRESS) && uncompress_block()) + die("cannot uncompress file block"); + for (;;) { if (read_file_number(fd, &option, 2)) die("cannot read the option id"); - if (!option) + if (option == TRACECMD_OPTION_DONE && file_version < FILE_VERSION_SECTIONS) break; if (read_file_number(fd, &size, 4)) die("cannot read the option size"); count++; - if (!DUMP_CHECK(OPTIONS) && !DUMP_CHECK(CLOCK) && !DUMP_CHECK(SUMMARY)) { - lseek64(fd, size, SEEK_CUR); - continue; - } switch (option) { case TRACECMD_OPTION_DATE: dump_option_string(fd, size, "DATE"); @@ -666,7 +713,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 +747,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 +758,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 Thu Nov 11 15:12:45 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: 12615151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E54EC433F5 for ; Thu, 11 Nov 2021 15:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B70D61284 for ; Thu, 11 Nov 2021 15:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234030AbhKKPPt (ORCPT ); Thu, 11 Nov 2021 10:15:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234032AbhKKPPs (ORCPT ); Thu, 11 Nov 2021 10:15:48 -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 F0B17C061767 for ; Thu, 11 Nov 2021 07:12:58 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id v11so25489868edc.9 for ; Thu, 11 Nov 2021 07:12:58 -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=QPIUFJpkqiAuUFuCW3190ZdxIDY1q5QX69WLW69uC4o=; b=pbgGKIgvrN3RDX5yJjS04DYAO9nwvYnHqSB2HCYP3H4bQOmWuD7F29yl7Ls5gn+1A4 hhT1cHOsQAF9ZYIfw5SKNYhEfYGpepT7tekdp+Bxgy8JBY+FHA7KoleTG9vi3XPOH1uI qvy8w4sr0fCwf/H+aKhE9rvLjGRtPWKNY5jfjAWRA5rJQLuMhlc3vpTjnhr/vzhcPfJA 7yU7SPJCd5bHLJGZa+Cd11WhLscOaAGbAWaxyOCOuFo3plKmPQdxpub8e9tk36P+/Qqn dyKhwd2G02gq9hptypTaQoTY+FaPiOQPjvNmN8SXXUS+HCySg4soMu92PL35e8EOHHIE gobQ== 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=QPIUFJpkqiAuUFuCW3190ZdxIDY1q5QX69WLW69uC4o=; b=vc9b2YuWreU1D293h08ny4Y8YAT6L15z4zaJq+Db4dT7XIqpXLoNs8x9csMLsh7mh1 KU+aBV5h4mtGTCCrpFsp+BM7Lv1kCdHig2eQshZW++NKCHodJ9xYxWJ5ZMlxKJRsrqCS dd2YXeQfOzEC85AgCC4J/as0yN7QryR/Mr8B+uVdghpeuLOQZ3JZ6fzTY+/Gsyhzs2kD PlGabsj4GKvtEf9UDt19SJAKueMeQT+Pp48GSaRUB+nQ10pq/uJ7VxB28xO8vJdXPVds OYeMop7U0bccCzCaQGtDzztxl2WMaTcSJwWw2FyQiftLMrAUFrXY3GSjqaDWzTBhSjzN m0Qw== X-Gm-Message-State: AOAM533gsqCWKfi3Vwd6KYkRzq4630l7vxKIzlF7Bo2mb2dKwYnw+/8v hQwfhL0F9lwBM3+E0jHR/RRVSTT1KRfRsQ== X-Google-Smtp-Source: ABdhPJxIGZKu1ujIw3ihAn0eZmeEgqKlB0tG9ihw/VCcOamZ/7tGwO67Nl62aiyp7DMLoahtvXIWLg== X-Received: by 2002:a17:907:961a:: with SMTP id gb26mr10150908ejc.71.1636643577550; Thu, 11 Nov 2021 07:12:57 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:57 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 05/10] trace-cmd dump: Read extended BUFFER option Date: Thu, 11 Nov 2021 17:12:45 +0200 Message-Id: <20211111151250.87023-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 a808c7d7..f8909faa 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -446,19 +446,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) @@ -710,7 +763,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 Thu Nov 11 15:12:46 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: 12615153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FC15C43217 for ; Thu, 11 Nov 2021 15:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BDA961252 for ; Thu, 11 Nov 2021 15:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234032AbhKKPPu (ORCPT ); Thu, 11 Nov 2021 10:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234033AbhKKPPt (ORCPT ); Thu, 11 Nov 2021 10:15:49 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D2FBC061766 for ; Thu, 11 Nov 2021 07:13:00 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id j21so25230635edt.11 for ; Thu, 11 Nov 2021 07:13:00 -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=NHfFRdwp2KHFwMpvZOIB10k6MKj2ejsBTBRhj6Zgd5E=; b=qG3eVvD0tqABjXyLks1c96O2FEtkA4Fx9rlShlS8bYBe+j72vAqIyw83L4zxdoxcm/ /9klFTPRjJ0C+8zGxL3BEiKa30I+fMs1qfcG3gT6eIG34SC4GKfr+xzZ3FK+14BRCSlm /9ARrUSGiOSUVaEbmCLhrKQNkhvsXaZj4PdLx8JcIxR5eTQY7YI81Y8RuGOOoQQnqmnu jj2VtBf/wTWc7lm//7LrcLw9XLxYz5QXGoB62fr66HZWO0gHsU/82jTXMl9Q/+1GdmLB ykVks1He+Ah1tKEbSXCxG3K5dEftZcE/GIdtm23wo7XapnTZEmB7myWSKze9F/Ej5YIq cFIQ== 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=NHfFRdwp2KHFwMpvZOIB10k6MKj2ejsBTBRhj6Zgd5E=; b=z/ztwkbTn5mKNkol5hm2yw7F8SiGTsJSJKEw4eQShXZ9I211su4VV2ZjYHS8KiMXWg jTSSCbBAJlkRtHgh6Pvaj+brw/B5nZZ5mpazLrX5iATUgxZJWzP+lL7xd5eVDwIEbTJl OMyfmZUrGmLRyxGIswDD2olopJnvDSkELHVJMFdrFf/qXcEmsy2Ls6IbIZmJKlkPCunQ lnYgJqaHNvYBzUnMOHVbwD1pfkULsjQCQeKqtugSVdJh4q5ofJE3PQXJ+B4ikP8e4XqO 60DHnY5xl9SLUpwLvYHjt9ewUeHJSIp85hC0SmB60Dk7RrBOnYCztolSjv4R6DcyHj25 OP5w== X-Gm-Message-State: AOAM530h8umhR1RdfeC5KVjkaHnvhyGPSpcpJq0kG5xVL0k+Xjmrmqau wCxWGMe0zs+09HwsdJFfTL1l66eUR27fGw== X-Google-Smtp-Source: ABdhPJzT910GojluDjWufsr2fGLnuLokmLQGKgnhG8XyRw9SDOheKc9zCkTBbfjcTX6dWKAksn5U3A== X-Received: by 2002:a50:becf:: with SMTP id e15mr10961819edk.114.1636643578620; Thu, 11 Nov 2021 07:12:58 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:58 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 06/10] trace-cmd dump: Dump sections Date: Thu, 11 Nov 2021 17:12:46 +0200 Message-Id: <20211111151250.87023-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index f8909faa..2f8cd5fb 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -713,6 +713,24 @@ 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]\n", desc, size); + do_print(OPTIONS, "%lld\n", sec->offset); +} + static int dump_options_read(int fd); static int dump_option_done(int fd, int size) @@ -801,6 +819,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 Thu Nov 11 15:12:47 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: 12615155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45081C433F5 for ; Thu, 11 Nov 2021 15:13:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E570610D0 for ; Thu, 11 Nov 2021 15:13:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234041AbhKKPPy (ORCPT ); Thu, 11 Nov 2021 10:15:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234033AbhKKPPv (ORCPT ); Thu, 11 Nov 2021 10:15:51 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC332C061766 for ; Thu, 11 Nov 2021 07:13:01 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id j21so25230937edt.11 for ; Thu, 11 Nov 2021 07:13:01 -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=8gCpS+fcA3sOrLSl9R3BhH9qJggh8STZ7fo9+83uT00=; b=KJu7aN9fy4mN0NfuHUUo2Ia8V51sVysuKrrUxuUsIXjkQgWwoBVuXEQ7E4WJhtAf5e H/0qOS8SMq81wmFVxz2y8794H3bxAUiitbinNNcVT+wPrxclTtcYfASSvgacJEcdw3VP oNI5BeaP1FbzlcdZkYbReMbT59QK87+qllVoEocSiThaNIFhP357+xPWMq8wucu0JE5I uAZVbRHFf0BKgag2JY882GhqpEhNRYF69X5ZZll6XYeFFd01v+4y8zOHSsTmZUCLR9v4 ny5AnmZoz0FRPxMrXrpKCbP7TQvuMe9iH0mN3yGnnaiE86GL9ER4xJEQGsAsD7eZxKLe 1bYA== 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=8gCpS+fcA3sOrLSl9R3BhH9qJggh8STZ7fo9+83uT00=; b=crrMimhF/58d6nbtr3c2v5JthPToMy7j8lEFeW9srrH8xR/eC7DwWhPeUeGDpgUB6W 1UAesOABSMyscRu966f14yJQos3W/KrXiBmmX2Cze5+rcXwfmFwjnm/vvr2qWxvuM/xA lu1/9nmvhKsLc0otlT8lGSf9lIdJYTNh7ogbnmzajkK+I/bIygmV9zuU7Ce7ws6YZ84Q bsMjY+/usAkGQ76hBowoHqxPcb3IYuK2fPvDYSkij+1SexrD+j9aBy0I8shfGs6FxDck 7pg/GRbY+/PRH5nkKNatVscEJKrIkQg4n1T2iLJzn66PLXZUxmwtvOqudNcwrjWgaXm+ NR2g== X-Gm-Message-State: AOAM533JxZ+8EwcOz8kgH+sGigegpPH7EHGjIPGfCOGm+gBP46uROajT 1M04JPtB7VAK6gY83YCTWDyVR1S4ulZ/AA== X-Google-Smtp-Source: ABdhPJwCC+yTl/0fWanI77xmKslNuTvIJMKsWYAs+dtEGVNBHwI/ZN3Zr29gtfP9ytw5UqVdE7VQNQ== X-Received: by 2002:a05:6402:4315:: with SMTP id m21mr10846824edc.54.1636643580098; Thu, 11 Nov 2021 07:13:00 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:12:59 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 07/10] trace-cmd dump: Dump trace file version 7 Date: Thu, 11 Nov 2021 17:12:47 +0200 Message-Id: <20211111151250.87023-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 2f8cd5fb..11a6e1df 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -929,6 +929,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; @@ -956,15 +981,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 Thu Nov 11 15:12:48 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: 12615157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5C9BC433EF for ; Thu, 11 Nov 2021 15:13:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B12BC610D0 for ; Thu, 11 Nov 2021 15:13:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234033AbhKKPPz (ORCPT ); Thu, 11 Nov 2021 10:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234036AbhKKPPx (ORCPT ); Thu, 11 Nov 2021 10:15:53 -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 2BD64C0613F5 for ; Thu, 11 Nov 2021 07:13:04 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id j21so25231521edt.11 for ; Thu, 11 Nov 2021 07:13:04 -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=5tO/vriOUpiSa2W8k4G1fuBKcjRtAbnryAqq55gN4qY=; b=AOQ5FmBYbeVYjvH07Sd5Q/afh1vQQab45AtkaH/Re7pQ468Ng5bHzhM6DyZWntef4q AxnIU4bI8vCeAJJCBTOwau3yJ9AeUtid0C69vfQF/nTfmofgfiP/tOGVA3nAxvqRGpFc /gM+j7hrkysCOyecZHQ04EMp2nAjglST4bVv8bqUHrTQx5OYXHIB2mCIkm7lIlq0epym 09MqS2zycLCxaqOBdQQVDQhqz3ZLhVYSjLRX3em+MHMiAZKbhXVyB+fLCJY8z/hno4iC 4jwUxLZwITZawiXRrMPlCXzFP705+1+6Birluob2Vq5LYVH6TBSO4lp5Bp32oUM5Mcjy w4xA== 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=5tO/vriOUpiSa2W8k4G1fuBKcjRtAbnryAqq55gN4qY=; b=tE+H1E5IRxShRiYATF3kOdifCgvdB1+vg05wQyzN1c6HgWOkL80yISz9BKgqGhMvuw GLwFcs9n+31PsTF7szrbBkMhxPA9Bo/69xP9ENPLJYQm1vNQi6H6OZ+uZR8Ras6DsBJA L7E5rFP4Rh0QwhLbtsUkuOvYHopX4cXZsnzariVD8TgQ+sF/iWmACJxd3V5Dfws373GT dlF3IDsYy32QF5tIK+ClPCkHbl3OsG1E1qXzcw/KKwhHIv35cwrbOqpNw/91u894h++9 P8cHr7Jes4TAjmt8fV0irPT6mMLMIYgYlgMP1nQMWu2zhPQUQg+ILQxa3vEB1fLwWv5/ RN2g== X-Gm-Message-State: AOAM532fnCsPn68wwtkkzy1GG9rkR9uH/OJmVo8TCjQ1RtGJyxittDtF iyeZsisgXIgU/9eSj5ELVrtN7wCYZ5iQyQ== X-Google-Smtp-Source: ABdhPJzhpo6aiPRIukvIYf3bq4rBrjnOTEpcwG0gyBw/z0ys7+KXvb6ROxGuKfAKonnAJJ0K7KuQXQ== X-Received: by 2002:a17:907:1b16:: with SMTP id mp22mr10105954ejc.487.1636643582405; Thu, 11 Nov 2021 07:13:02 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:13:01 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 08/10] trace-cmd dump: Dump sections content Date: Thu, 11 Nov 2021 17:12:48 +0200 Message-Id: <20211111151250.87023-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 11a6e1df..b2670744 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -731,6 +731,46 @@ static void dump_option_section(int fd, unsigned int size, do_print(OPTIONS, "%lld\n", 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) @@ -952,6 +992,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 Thu Nov 11 15:12:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12615159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0591EC433FE for ; Thu, 11 Nov 2021 15:13:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3F4261354 for ; Thu, 11 Nov 2021 15:13:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233449AbhKKPPz (ORCPT ); Thu, 11 Nov 2021 10:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234038AbhKKPPy (ORCPT ); Thu, 11 Nov 2021 10:15:54 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73489C06127A for ; Thu, 11 Nov 2021 07:13:05 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id f4so25360126edx.12 for ; Thu, 11 Nov 2021 07:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YrVrPP534jX6fRrmD3ChIy6tMTByr1OJWLRo+Vo8E6A=; b=PwKh2Rskm6iGLLC5Kc2LfV5OGU4eKlo51JfPpdHGtevD1vL415cuDY6oZ4aUjXH4WN cJeqQ9rIWwfM3uZegrf2CzaGTgcCBMc2P40AQt0PS/vUrgy85fQS7j6/3KKfWn1igS1P UH2O8Nso1kFo+IRZExY7IHy5hSc2Nn5IR2jKKaU0+ChBv6lEjCrl0OM9Ahh3mnFbr/fO I4ytALGdWC4/6YYQKJDe9p7Hgz03iBGchs5hNH7KsUhAnQVAJgveDqm6jyBaWvo6qG7e gY9tdfOO1d98V0hDahMZbSG0OIyET41NH1V22ksFsNwN2/t5rhvrtUhz/428sowh4UKX sSWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YrVrPP534jX6fRrmD3ChIy6tMTByr1OJWLRo+Vo8E6A=; b=Xx4uFAeQWPRaUx3aahHkYCPYrzysZPWxhz5NklEKBM5HXFXUNcvgcbl9hZ2kGk8mwg OlEvchO1d5scwNWaRaO3M76rmOdO2TGxKdggEr4S14PtdqQgt0aG9EMNIdZcphyN7Cxk 9hWQLFH+9nJ2ByWI5DcdAih9Glxhlm+vut2akrYZiptlQt8EKiWd+fzfCJexXZj1JEYt jvhovmp0TJZSKmT1v7/iopPI/V6fWzZ2tVa+mVKHw3ADMI2FXqiPd0EBdoUXB5x2mK7a K7cTXpQ656kB5fwMNOrQa9zDfoSbxTSb+JWBO9Gv4K7i8XlURDL2ZpyoLMNwy4ECFjPo xtKg== X-Gm-Message-State: AOAM533d0GT9teWbrjt+RjZYEEQFm+wddV8Z6u0Px+bT48XCLAHHEKpz DmyqYj2slDoZ0rVlb7itQd0svkqCxEU+LA== X-Google-Smtp-Source: ABdhPJwv7eyJK5EHgfAtzEe8RWPgLX/VurS5OpzFyWi176UOSMVA4+3mKpY8nBHH32kmwjuXNw0MPA== X-Received: by 2002:aa7:cada:: with SMTP id l26mr10952672edt.376.1636643584026; Thu, 11 Nov 2021 07:13:04 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:13:03 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 09/10] trace-cmd dump: Add new argument --sections Date: Thu, 11 Nov 2021 17:12:49 +0200 Message-Id: <20211111151250.87023-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new "trace-cmd dump --sections" argument walks through the sections from a trace file version 7 and prints their headers. The logic does not rely on the options, describing these sections. It could be useful to dump broken or incomplete trace files. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-dump.c | 71 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index b2670744..8986f9b0 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -731,7 +731,7 @@ static void dump_option_section(int fd, unsigned int size, do_print(OPTIONS, "%lld\n", sec->offset); } -static void dump_sections(int fd) +static void dump_sections(int fd, int count) { struct file_section *sec = sections; unsigned short flags; @@ -769,6 +769,7 @@ static void dump_sections(int fd) uncompress_reset(); sec = sec->next; } + do_print(SUMMARY|SECTIONS, "\t[%d sections]\n", count); } static int dump_options_read(int fd); @@ -982,17 +983,76 @@ static void dump_v6_file(int fd) dump_therest(fd); } +static int walk_v7_sections(int fd) +{ + unsigned long long offset, soffset; + unsigned short fl; + char buf[DUMP_SIZE]; + unsigned short id; + int size, csize, rsize; + int count = 0; + + offset = lseek64(fd, 0, SEEK_CUR); + do { + soffset = lseek64(fd, 0, SEEK_CUR); + if (read_file_number(fd, &id, 2)) + break; + if (id >= TRACECMD_OPTION_MAX) + die("Unknown section id %d", id); + if (read_file_string(fd, buf, DUMP_SIZE)) + die("cannot read section description"); + if (read_file_number(fd, &fl, 2)) + die("cannot read section flags"); + if (read_file_number(fd, &size, 4)) + die("cannot read section size"); + if (size <= 4) + die("Section %d (%s) is too small, %d bytes", id, buf, size); + count++; + if (fl & TRACECMD_SEC_FL_COMPRESS) { + if (id == TRACECMD_OPTION_BUFFER || + id == TRACECMD_OPTION_BUFFER_TEXT) { + do_print(SECTIONS, + "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, " + "%d compressed bytes]\n", + id, soffset, buf, fl, size); + } else { + if (read_file_number(fd, &csize, 4)) + die("cannot read section size"); + if (read_file_number(fd, &rsize, 4)) + die("cannot read section size"); + do_print(SECTIONS, "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, " + "%d compressed, %d uncompressed]\n", + id, soffset, buf, fl, csize, rsize); + size -= 8; + } + } else { + do_print(SECTIONS, "\t[Section %2d @ %-16lld\t\"%s\", flags 0x%X, %d bytes]\n", + id, soffset, buf, fl, size); + } + + if (lseek64(fd, size, SEEK_CUR) == (off_t)-1) + break; + } while (1); + + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) + die("cannot restore the original file location"); + return count; +} + static void dump_v7_file(int fd) { long long offset; + int sections; if (read_file_number(fd, &offset, 8)) die("cannot read offset of the first option section"); - if (lseek64(fd, offset, SEEK_SET) == (off64_t)-1) + sections = walk_v7_sections(fd); + + if (lseek64(fd, offset, SEEK_SET) == (off_t)-1) die("cannot goto options offset %lld", offset); dump_options(fd); - dump_sections(fd); + dump_sections(fd, sections); } static void free_sections(void) @@ -1033,6 +1093,7 @@ static void dump_file(const char *file) } enum { + OPT_sections = 241, OPT_verbose = 242, OPT_clock = 243, OPT_all = 244, @@ -1076,6 +1137,7 @@ void trace_dump(int argc, char **argv) {"options", no_argument, NULL, OPT_options}, {"flyrecord", no_argument, NULL, OPT_flyrecord}, {"clock", no_argument, NULL, OPT_clock}, + {"sections", no_argument, NULL, OPT_sections}, {"validate", no_argument, NULL, 'v'}, {"help", no_argument, NULL, '?'}, {"verbose", optional_argument, NULL, OPT_verbose}, @@ -1139,6 +1201,9 @@ void trace_dump(int argc, char **argv) if (trace_set_verbose(optarg) < 0) die("invalid verbose level %s", optarg); break; + case OPT_sections: + verbosity |= SECTIONS; + break; default: usage(argv); } From patchwork Thu Nov 11 15:12:50 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: 12615161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 067BEC433EF for ; Thu, 11 Nov 2021 15:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E40A1603E9 for ; Thu, 11 Nov 2021 15:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233746AbhKKPP6 (ORCPT ); Thu, 11 Nov 2021 10:15:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234036AbhKKPP4 (ORCPT ); Thu, 11 Nov 2021 10:15:56 -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 14246C061766 for ; Thu, 11 Nov 2021 07:13:07 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id v11so25491688edc.9 for ; Thu, 11 Nov 2021 07:13:07 -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=Y1DZI9vkFNa4Z9XGNeMzOagH15AKNe1aTIBjcQnDKcg=; b=a5tVrNuuxY2olvDpVi9vDEqPdv9JKhRM+dP/X1xvp0XuTafocuwpYqzGcyYYbfySGX wxiK7SKF3gRnm+XwJ0iEQy79RkB7/AYz8AL+9JOQjgcpz+rGmqZWlW4f94g/3ZZjMCAw z2luxPeCReLTc0jVFopAKoiHFqUrgH8vKG4VixYleUHxFLN4ycMauaCF4uQH0JgD7Cfa Zdcd9IV62Go15VQIZOjiIX8atq+ilninvSRd9YUp43Ml8w0tCsVvInWRdwmnEd9NcomB 6WSow9TVL33IoyJ32rziqqcx765+AqflgZzFBRcLZ4lzK5afUB2w4uspn0OwSSRwFx9j CIKA== 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=Y1DZI9vkFNa4Z9XGNeMzOagH15AKNe1aTIBjcQnDKcg=; b=yniJM0LwnotLsCz+iFEtPQIcDdKn0zo3JGWpWGNcsjXCyDancZhBEJlrUvOX1pvt64 DuS/I1SSfBSPW3uaNcGNqte7Y216bdo5qRk7RpY/Yq0NIfIzB0ujLo/lv2chE/OVSWLb xdIEW84VmAl6f9kDWt0lJwvmP5srwhLE2d1l700iprgLhJbrc4MlE2GNXpjpc51IUArv 2bLF+43K+R/T10qEOezUL7TIgDEUcLCT8JFCV8me3XqAOo7/U4dd90/zFQGT1da6dBE1 fk39/cKlj/atWUZROIPECw1QRXpTt9rhMeFxGaVBd7mdnchOChzItihdFBzdn5KDsUy+ 6l9g== X-Gm-Message-State: AOAM532WwuIkxDP68ImEnozEml9oCCuSQ23yck+TIswEOM7epxBRU+hc 9EglT26VsQZ8WhHqL1UE9jfp23e/+H+2Zw== X-Google-Smtp-Source: ABdhPJzBxhCpqqV0qXwPs0WvTBL6pq+yJ/yugb3eSVFo7RxuQjaDHrebI+/r40aWAO5er8oz8h+RZw== X-Received: by 2002:a50:e089:: with SMTP id f9mr10991244edl.290.1636643585635; Thu, 11 Nov 2021 07:13:05 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id q2sm1443375eje.118.2021.11.11.07.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:13:05 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 10/10] trace-cmd dump: Align better the output of flyrecord dump Date: Thu, 11 Nov 2021 17:12:50 +0200 Message-Id: <20211111151250.87023-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111151250.87023-1-tz.stoyanov@gmail.com> References: <20211111151250.87023-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The 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 8986f9b0..9013f8b5 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -943,7 +943,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);