From patchwork Thu Apr 29 04:01:13 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: 12230409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B24DAC43460 for ; Thu, 29 Apr 2021 04:01:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FA396144E for ; Thu, 29 Apr 2021 04:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbhD2ECJ (ORCPT ); Thu, 29 Apr 2021 00:02:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbhD2ECJ (ORCPT ); Thu, 29 Apr 2021 00:02:09 -0400 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 69D3EC06138B for ; Wed, 28 Apr 2021 21:01:23 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id r9so97790641ejj.3 for ; Wed, 28 Apr 2021 21:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K42z27jvf+Tkl8yK1wvpfyDoi543AlzEeQPwOCKc/vU=; b=KP9j6ClU2N8z08PA8wcTSPQh002UEQnBTA2mEiig5DPxMjYc2bZaWyfLNhCluGEHhp NvD89SsfP1d7wX4UKOKv0dqU/q+uYTjJtb425Y2UTSdwC1SaYOfY2X6+fcZ5hyjpDngO Wqir/KjeJlIX30HEu/rKehV4zSdUfSBpRPl9YonVr0a4+rrFixyc982KBQpiDW17sNbf Y5lhR18mf3RCA3eVfEeNK8mxEh+RVYhI9Vx/js9y1s79GsTluB/Gkt+iO0vUgSoe6z6s wr3eUy7RBpWuIPjH1rrbSj+fR4Cx58Au7vvxAV9/TwLE63u+8oiIihbQFrtn+Hs0ITI6 kMvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K42z27jvf+Tkl8yK1wvpfyDoi543AlzEeQPwOCKc/vU=; b=TXhlwAJDr8x8g1Dp1NL/s/gw8kGqoBY5MWxG2CUP6L/KAmHp4ufHXPwyLxpgRXnyiT 0V8ekMqU0c5yN5LtwYsx0JwNlUdeSa9mAOXV2u77V4vACmEt+0g0J1BiOiq5SlFMcjYL WaTdbQuNhRBjm0yfQgAeMO+33DgkwSdHUVCORvkVQtVX0evYaRLmwTLfaiqu+zmoKauQ A4XNZoItKDoAZbJ45f7JmfM7f7+Az6xosLfob6C6ArvH3RfqxgiXQeMe4Hcw77oefpZO CReZt0W9APD4Zkp5e5S2mlT3Fm5l+3CFH35Aqnf6lVao5nx0bF+ZiBjV+bhHuvpoLb0T 5q5w== X-Gm-Message-State: AOAM531FbsPKogeMEiWXhxomnCoqPUhqH9xbUrw+TkO6BCFSfS3zbCtw zN3xeiO0Eyf7H/Y6yh/DKxQ= X-Google-Smtp-Source: ABdhPJw3AwvZSORUGsv15OSnAoy4nSDgk8o/UmwHGe5wTR57bQMnoXm6ZoSX92tgtEyA3ahRMSCTjA== X-Received: by 2002:a17:906:2504:: with SMTP id i4mr32528511ejb.297.1619668882191; Wed, 28 Apr 2021 21:01:22 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:21 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 1/7] trace-cmd library: Remove unused private APIs for creating trace files Date: Thu, 29 Apr 2021 07:01:13 +0300 Message-Id: <20210429040119.843617-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Remove these unused private trace-cmd library APIs: tracecmd_create_file() tracecmd_create_file_glob() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 6 ---- lib/trace-cmd/trace-output.c | 29 ------------------- 2 files changed, 35 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 42e739fa..8ec33ea2 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -263,12 +263,6 @@ struct tracecmd_option; struct tracecmd_msg_handle; struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); -struct tracecmd_output *tracecmd_create_file(const char *output_file, - int cpus, char * const *cpu_data_files); -struct tracecmd_output * -tracecmd_create_file_glob(const char *output_file, - int cpus, char * const *cpu_data_files, - struct tracecmd_event_list *event_globs); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, struct tracecmd_event_list *list); diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index a4a1eecc..9231c319 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1614,35 +1614,6 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) return NULL; } -struct tracecmd_output * -tracecmd_create_file_glob(const char *output_file, - int cpus, char * const *cpu_data_files, - struct tracecmd_event_list *list) -{ - struct tracecmd_output *handle; - - handle = create_file(output_file, NULL, NULL, NULL, list); - if (!handle) - return NULL; - - if (tracecmd_write_cmdlines(handle)) - return NULL; - - if (tracecmd_append_cpu_data(handle, cpus, cpu_data_files) < 0) { - tracecmd_output_close(handle); - return NULL; - } - - return handle; -} - -struct tracecmd_output *tracecmd_create_file(const char *output_file, - int cpus, char * const *cpu_data_files) -{ - return tracecmd_create_file_glob(output_file, cpus, - cpu_data_files, &all_event_list); -} - struct tracecmd_output *tracecmd_create_init_fd(int fd) { return create_file_fd(fd, NULL, NULL, NULL, &all_event_list, NULL); From patchwork Thu Apr 29 04:01:14 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: 12230411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F400C433ED for ; Thu, 29 Apr 2021 04:01:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 048FD61450 for ; Thu, 29 Apr 2021 04:01:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbhD2ECN (ORCPT ); Thu, 29 Apr 2021 00:02:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbhD2ECL (ORCPT ); Thu, 29 Apr 2021 00:02:11 -0400 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 C1BB3C06138B for ; Wed, 28 Apr 2021 21:01:24 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id i3so51150129edt.1 for ; Wed, 28 Apr 2021 21:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zVFwLv+PTToBTggoexzPUquS2fS8UZ66ZfmMfMUkv8g=; b=Ig1tVEiHfIsCJ9ughsk0JkD0wCXXb+gBQEgTXtl4d8UkcXVGZTOzIqSV0IwN/bIwRg AZFPD7jCPK9GicIVKwaAKJyCAmSygppopGJ4yw9jt8wVTjj/skAYbFtsuH6JWL2ggNUt 4pSqzfLmpzNe4VZFKRGMeCAVGJDvR80qvIZvouyUjnjWS2Uh0wcZnX1zCWgSUaMQy1c5 fRMuL1PxoQLf3RnxmEuOKgowsnSlZUTtDTfzo38a57GfF/09zcoxNm4U7Q3MItO4c8F1 qLXxnzmKcSRDEq9MVEPgdicZWa/98GvtVj9xjfafKv/odfohTzKq/8tuZADU33/zRPix A0Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zVFwLv+PTToBTggoexzPUquS2fS8UZ66ZfmMfMUkv8g=; b=auFBqubPJpTN5Avh7f1N+jdpcxsCjoAhPY+2A2vLGhLiNC0sBPu3CnMO3KUzyN7y+E M8bERd0EHbwmeHbLPzSQJdTRn1v3Epr0Jg3SFVHtBR6yt5KfRaleC2vCBIAf7m0QMwst cU9JnTUg4/M7JI25739yuw2qO1DY3j5mN5xM6XmW6DXJTMfUG0PL73Fg7X2TNMlcUygl gt7XbJTv5FcbM31nqRHHhA65hqEKDrEWV9I7STl7v/glgliFIfMFbbqH0jWz2wLDwFm1 WDvg4UkFfYpaVoEJkhfVfwwVE5KA2lJ/t8eB8UoFyoG0ihETeGtkoGfL6lh41nJoGNq/ 1Zfg== X-Gm-Message-State: AOAM532rRzGIFE0eQ1okG3EWTNja5JDyvXz4WexeJD9P/ZfR+uQ4JBSJ wtpj1vPmbM5rVKGtWA9RrAE= X-Google-Smtp-Source: ABdhPJxapQDhBxCDTSXS4/HkpKWXWA0AjpRGlJo5GHDpJreHKCVxiUEeG3tTNPW/HDlcC0y27N9MpQ== X-Received: by 2002:a05:6402:351:: with SMTP id r17mr15650303edw.186.1619668883540; Wed, 28 Apr 2021 21:01:23 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:22 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 2/7] trace-cmd: Check if file version is supported Date: Thu, 29 Apr 2021 07:01:14 +0300 Message-Id: <20210429040119.843617-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When reading a trace file, version of the file is ignored. This could case problems when bumping the version number because of changes in in the structure of the file. The old code should detect unsupported file version and should not try to read it. A new trace-cmd library API is added to check if version is supported: tracecmd_is_version_supported() Checks are added in the code to ensure not trying to read trace file with unsupported version. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-input.c | 10 ++++++++++ lib/trace-cmd/trace-util.c | 7 +++++++ tracecmd/trace-dump.c | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 8ec33ea2..cbd8dc1f 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -42,6 +42,8 @@ void tracecmd_record_ref(struct tep_record *record); void tracecmd_set_debug(bool set_debug); bool tracecmd_get_debug(void); +bool tracecmd_is_version_supported(unsigned int version); + struct tracecmd_output; struct tracecmd_recorder; struct hook_list; diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index b17b36e0..a00fa982 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -130,6 +130,7 @@ struct tracecmd_input { bool use_trace_clock; bool read_page; bool use_pipe; + int file_version; struct cpu_data *cpu_data; long long ts_offset; struct tsc2nsec tsc_calc; @@ -3257,6 +3258,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) unsigned int page_size; char *version; char buf[BUFSIZ]; + unsigned long ver; handle = malloc(sizeof(*handle)); if (!handle) @@ -3281,6 +3283,14 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd, int flags) if (!version) goto failed_read; pr_stat("version = %s\n", version); + ver = strtol(version, NULL, 10); + if (!ver && errno) + goto failed_read; + if (!tracecmd_is_version_supported(ver)) { + tracecmd_warning("Unsupported file version %lu", ver); + goto failed_read; + } + handle->file_version = ver; free(version); if (do_read_check(handle, buf, 1)) diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 2d3bc741..a6fc64c8 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -582,3 +582,10 @@ unsigned long long tracecmd_generate_traceid(void) free(str); return hash; } + +bool tracecmd_is_version_supported(unsigned int version) +{ + if (version <= FILE_VERSION) + return true; + return false; +} diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index 3f56f65a..aa48eaad 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "trace-local.h" @@ -145,6 +146,7 @@ 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"); @@ -166,6 +168,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) + die("Invalid file version string %s", buf); + if (!tracecmd_is_version_supported(ver)) + die("Unsupported file version %lu", ver); /* get file endianness*/ if (read_file_bytes(fd, buf, 1)) From patchwork Thu Apr 29 04:01:15 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: 12230419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D4E8C433B4 for ; Thu, 29 Apr 2021 04:02:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45E626144E for ; Thu, 29 Apr 2021 04:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbhD2EDm (ORCPT ); Thu, 29 Apr 2021 00:03:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235005AbhD2EDl (ORCPT ); Thu, 29 Apr 2021 00:03:41 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2044DC06138C for ; Wed, 28 Apr 2021 21:01:39 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id z13so21706634lft.1 for ; Wed, 28 Apr 2021 21:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iHD82sINsZplFbyglii2VDYPeWFtu0uSNBpGrCNlO30=; b=Fk55F4/y5KCqs1MIeDgiYqiMBTXfLpNYQkCVqlQYRZ0p/Zs9lV8bN5stShwdwXhWfK n/bBc7A8eMVbSYCTVkfpx57KAyCPmfbXbNHti6W7SY3Stty5zLxhkQ2WN/F24ik/z6ql J95UXXrzlcZz4UrB1rmmsKovvz2ynN19hcjOCwMkboJ0vg2Y0y7UDgOFXOp9ISSxW/MU 8sQKg95T6FkD9KmmVk7UGsZ049IhfrVvAQKOZvM7/ZRHfSPeO0g23ln3WcTvlpv3VBly qMbN9NCfNwIByjX8dLr3QWqKLkCh3ABQSUeqlx1lgp+m1CzRNy2iu/B34h0vRB8k+1Nd hFJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iHD82sINsZplFbyglii2VDYPeWFtu0uSNBpGrCNlO30=; b=fOx0rbU59qDWxHjO31AeIqnax/Ukm+/En7W6bEliBeFdx44KdZZvX5ThjcE3UqsBtu G64uumhK1kpo16NuIe9JAeiWzSqUmRHYHaylfDX+K+2AgJDCm1zi5DLwxvki/Jc5De+r 8EGc7onijlznI+YaNTXDjfJpXrS8R/Ym7TYfrENgXwqelzh6ky3T+GFT8aRBe0O0bSQ8 UMuluLHIg+Y69cLd676TfFGQuHlcQn+yAYhKesbCJUoSmFPCQjCuFWeQubEHTWSLXSFX UywN0fl4SYagN6UXb0B6LEofhaJU5Gc/bhAfuviXZ59hfHhIabr67sqf3sob4kqxF6yh F5fQ== X-Gm-Message-State: AOAM533AzbDO6bUKbA4DgGa6lwNtALDCoHlEy2i3fBuTKx6R5V7cvzHm nakRSTFU255RDB1jdiUXZYXPQeo8mAUo0w== X-Google-Smtp-Source: ABdhPJz3V6z+L489OCS4GbgBMO7ZyuychNfrZQQ883LMmI9wE4pqH4FKC9YXfeM2JE7CoeCwK03R/A== X-Received: by 2002:a17:907:7634:: with SMTP id jy20mr4888810ejc.553.1619668884598; Wed, 28 Apr 2021 21:01:24 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:24 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 3/7] trace-cmd library: Bump the trace file version to 7 Date: Thu, 29 Apr 2021 07:01:15 +0300 Message-Id: <20210429040119.843617-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Adding a compression of the trace.dat file will change its structure. These changes are not backward compatible, the old trace-cmd binaries will not be able to read compressed trace files. Bumping the version to 7 will prevent old trace-cmd to read such files. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/trace-cmd-local.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index e8533b22..5578f00d 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -14,7 +14,7 @@ void tracecmd_warning(const char *fmt, ...); void tracecmd_fatal(const char *fmt, ...); /* trace.dat file format version */ -#define FILE_VERSION 6 +#define FILE_VERSION 7 #define _STR(x) #x #define STR(x) _STR(x) From patchwork Thu Apr 29 04:01:16 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: 12230413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42253C433ED for ; Thu, 29 Apr 2021 04:01:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24C5B61450 for ; Thu, 29 Apr 2021 04:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbhD2ECN (ORCPT ); Thu, 29 Apr 2021 00:02:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229956AbhD2ECN (ORCPT ); Thu, 29 Apr 2021 00:02:13 -0400 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 ACB3FC06138C for ; Wed, 28 Apr 2021 21:01:26 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id i24so17256418edy.8 for ; Wed, 28 Apr 2021 21:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0oxvIo367n5ZcnF0JSYULJMP8eja6XARiF+mak0nbbA=; b=slYW/LmduA01pQE68UTDpNnzx1PlGuqBcAiPikPRfBCHCF/pBqAmDzzJueY4GzFI4T qwUpPryLfC6qVMJtchrUPFVXGlaQ437dN56rBxRFkv7/IJltb0lziCF/bmp6X9vrhNno epK9bq0jEnuBSYB6TTiVWI+Swpp3736GFFx8J9V0bVBv7LfxYzgHwMUVSK9lkYic0rIt OzMsjKSrfJ8jwPTZZrocTCbGZJIQ5oRSY8E5p4dq+NXx8FNRd8Kz4uTgmhLajfshqWVd ajdlOxQV2/Y990Y22QDIQjWrqBvszMiIGLs9+oJz2dy6WaUoQlYy21jUPjLxz4h9ekJ5 G/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0oxvIo367n5ZcnF0JSYULJMP8eja6XARiF+mak0nbbA=; b=XNBccIfB9/OSxo1UNrOQ8odVwz5cA3bKbYz+JcAMNQ+vmBP9eMKmwTk/rECj2qO3oz lX+fkDjHzRZ5+xvo/W14r83mvZFdXvG4LjP0SgX5Mx+FomI/uvfeRoKUumfwtt1QDGcx o2ssVN3KLndgmFBxft8HYcdqWOJYrjovm7aVkBtSee9+COmqQn5gCOrtfy7svIazP4hm jsIiVxvZAglnsIkXsB0DLiA37OeJGLMmvCs9W5oLzkLqlwGtsNSXnlXcBwY8n3TyqnAW UtgyURQxDUIrKttB5dneBAmCenc2uLbir0m/fN8EUYdKni/SDnyeYoPxgkIRHbCnADZW IlnQ== X-Gm-Message-State: AOAM532wv3b7hgZ+CfJqVFT8Lt1YFhGUljnFpWm8ZVvx0R8pNDMzFLSD iOVYBdYSNF1TJR4zd4WSQjRCrpjxecx9gg== X-Google-Smtp-Source: ABdhPJyfzwRRuPnx0eabttE3iuE07LPKCodBEoBlOWy86xvCHR+zhXBswFbHWN+uAfgR9kZrsdD3ww== X-Received: by 2002:aa7:d705:: with SMTP id t5mr7392830edq.141.1619668885478; Wed, 28 Apr 2021 21:01:25 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:25 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 4/7] trace-cmd library: Add new API to get file version of input handler Date: Thu, 29 Apr 2021 07:01:16 +0300 Message-Id: <20210429040119.843617-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added an API to get the version of the trace file, associated with given input file handler. tracecmd_get_file_version() Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-input.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index cbd8dc1f..29e56271 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -232,6 +232,8 @@ int tracecmd_set_cursor(struct tracecmd_input *handle, unsigned long long tracecmd_get_cursor(struct tracecmd_input *handle, int cpu); +unsigned long tracecmd_get_file_version(struct tracecmd_input *handle); + int tracecmd_ftrace_overrides(struct tracecmd_input *handle, struct tracecmd_ftrace *finfo); bool tracecmd_get_use_trace_clock(struct tracecmd_input *handle); tracecmd_show_data_func diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index a00fa982..b2a03ab8 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -4034,6 +4034,15 @@ struct tep_handle *tracecmd_get_tep(struct tracecmd_input *handle) return handle->pevent; } +/** + * tracecmd_get_file_version - return the trace.dat file version + * @handle: input handle for the trace.dat file + */ +unsigned long tracecmd_get_file_version(struct tracecmd_input *handle) +{ + return handle->file_version; +} + /** * tracecmd_get_use_trace_clock - return use_trace_clock * @handle: input handle for the trace.dat file From patchwork Thu Apr 29 04:01:17 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: 12230415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975FCC433B4 for ; Thu, 29 Apr 2021 04:01:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79C0861450 for ; Thu, 29 Apr 2021 04:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbhD2ECQ (ORCPT ); Thu, 29 Apr 2021 00:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231356AbhD2ECP (ORCPT ); Thu, 29 Apr 2021 00:02:15 -0400 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 B7C91C06138B for ; Wed, 28 Apr 2021 21:01:27 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id j28so12828102edy.9 for ; Wed, 28 Apr 2021 21:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jh94CVkyZ80NZk00QNKScK1pMRGjLPh+Cdp2ACcN1r0=; b=MFzxsQZsBTMUQPcjB02Fl7T6nmacLo2qwWByACh7fYUZOUM13LdJssCsy1b7Y9DaQY 2vPJJjJQV7MZBrBvUYKSJqp4AN2TshNS7YWo1JL3DeC/lCdGOy7x8RQYmfIOLRXS4Hfq wCbNQ7w6cVpop3rm1oODKRQD8sHLAjEkzvqShlNchM0FoG/QH1bPI1cBeAOp1OgWyNJO 2wZD8jv93/NKjrPs0uZ4gGQt8mYuD+OhFjkOW7zOr+HcUDy/I3yhHI1qONwFpxesuKZ6 9pnDU6+ZQl9h2/coHitgpDwcfz1WiNzVLkZJKNj4YAAJrS7PXCh9UfxQf9KQesv83e6V 1oyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jh94CVkyZ80NZk00QNKScK1pMRGjLPh+Cdp2ACcN1r0=; b=HwH1bSlAsS7tOR/oIf/kZ3wQcaBzDENYihOoUTfq7EtiOSK/doYAw7CTDJJXyuxnnf 47i4AG9D/WjwMK6A2Zt/x8WTFHkG+RQBliiyX7T7wV4xbfJJ/0HsoLTtR46bPmUbtYMq pE+bodKvK4FBKSUHR2d3h2s28xuKDceZxx42UtO7qpEo7nE5xuvQzO9xqGiHowl3fqqh LHPLg9GN3w+2dsqnEjfkYN30S2VbQfREbvZWKRlArr2gWLhiHm+d8mUgosxEMISelOX4 JInmwPPB2eIaRZEcRfwpjXGYbqlQH3dahz8bCVvtxJFMMTS8u5H72TGhhJhFe8QnTkLT SejA== X-Gm-Message-State: AOAM5324MnfuCp5G+yBnFPd6vH/4D6i+RM4HX7pqcrf3F0yQGU+YG/VE IBuL108sod08m2xtB5PprMQ= X-Google-Smtp-Source: ABdhPJwyvMF7Uk11eP8AnNC3AQwxnB24t5BkVmu/ERJtW+Q21RJfgnYKKYVRrluagqfEvSuI/AhFmg== X-Received: by 2002:aa7:df0b:: with SMTP id c11mr15143362edy.288.1619668886535; Wed, 28 Apr 2021 21:01:26 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:26 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 5/7] trace-cmd library: Select the file version when writing trace file Date: Thu, 29 Apr 2021 07:01:17 +0300 Message-Id: <20210429040119.843617-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When a new output handler to trace file is allocated, select the proper file version. If this output handler is based on an existing input trace file handler, inherit the trace file version. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 9231c319..f36718f1 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -57,6 +57,7 @@ struct tracecmd_output { int nr_options; bool quiet; unsigned long file_state; + unsigned long file_version; struct list_head options; struct tracecmd_msg_handle *msg_handle; char *trace_clock; @@ -907,6 +908,17 @@ out_free: return ret; } +static int select_file_version(struct tracecmd_output *handle, + struct tracecmd_input *ihandle) +{ + if (ihandle) + handle->file_version = tracecmd_get_file_version(ihandle); + else + handle->file_version = FILE_VERSION; + + return 0; +} + static struct tracecmd_output * create_file_fd(int fd, struct tracecmd_input *ihandle, const char *tracing_dir, @@ -933,6 +945,9 @@ create_file_fd(int fd, struct tracecmd_input *ihandle, handle->msg_handle = msg_handle; + if (select_file_version(handle, ihandle)) + goto out_free; + list_head_init(&handle->options); buf[0] = 23; @@ -943,7 +958,8 @@ create_file_fd(int fd, struct tracecmd_input *ihandle, if (do_write_check(handle, buf, 10)) goto out_free; - if (do_write_check(handle, FILE_VERSION_STRING, strlen(FILE_VERSION_STRING) + 1)) + sprintf(buf, "%lu", handle->file_version); + if (do_write_check(handle, buf, strlen(buf) + 1)) goto out_free; /* get endian and page size */ @@ -1602,6 +1618,7 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) handle->pevent = tracecmd_get_tep(ihandle); tep_ref(handle->pevent); handle->page_size = tracecmd_page_size(ihandle); + handle->file_version = tracecmd_get_file_version(ihandle); list_head_init(&handle->options); tracecmd_close(ihandle); From patchwork Thu Apr 29 04:01:18 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: 12230421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD410C433ED for ; Thu, 29 Apr 2021 04:10:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84ABA61455 for ; Thu, 29 Apr 2021 04:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236336AbhD2ELf (ORCPT ); Thu, 29 Apr 2021 00:11:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235338AbhD2ELJ (ORCPT ); Thu, 29 Apr 2021 00:11:09 -0400 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 D36DFC06138B for ; Wed, 28 Apr 2021 21:01:34 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id w3so97829033ejc.4 for ; Wed, 28 Apr 2021 21:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oXpQDHKheNT8I7Fks8vU+n9ljb7v0VP3gPjBiPzBdx4=; b=SFJm6C5tRxVVjefRTPKBS4hQhRHbqXkzEywahO5CXp1pilgraTaFdPrf7QCg3mBkpe 6XDU9ZE8THUQvioERSEffeL5k9hiaP75ah7N9mCF1RRULIPBM3PKNb15iK77HbSsBHWw 6icDucTrPu7GiARubBa9kR58f7RUa9sw3/Er0whpF55W2iDVmLQqiOARb7RcPVq5mKeU Grl4m2NxU9ibKMekJ7GR4Cv/es1vDD3fw46hgMN/vjHuUpRLVb2wRQo76eZekQnTGeoK JuyZ7Qgcg+sThNaclFiaTIjUNu0p8+m5ent0qb8pE388ZjRqKtnro0Yzp1pzAGxn96DQ smCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oXpQDHKheNT8I7Fks8vU+n9ljb7v0VP3gPjBiPzBdx4=; b=bVD3h+XYfx7BeWbdkznzKpeXzrP5kt3THbiaV0IqrDOaT772F42aZxD1LkT5W6wbeL uo/BU7FZ64dsh/KKULY6E4hqYYZgZr3+bZds97W62X6r7pid3OjRBnMqKtXGDNv2Fsao Zm4pg3mwW9dgpbQTZ2GlnI2lbowhfubhMpaFydIlO1fUJm/fKhpIpE7yEgxLRQnUPMTe iEt+MzHXkw86AMaIYa7D5ILub5ugoCRpbFSvM8y1vIh6kE/NLcMLOUW3a1x++mnxKTia CbEnHKkV+6dQIgIeWVqPFvR3mGRz0wTmsgUYkSM7TtlPD0cgVz4qwIVNEvBC5jDz5iTc KmOQ== X-Gm-Message-State: AOAM533Ed7fTs5hfruwXRE0U8j27CLnQhna75ZnsI1/FMPW3m78bevy0 mcUxPP6C7aLpC8dSq3HV+DA= X-Google-Smtp-Source: ABdhPJwwsBn6BPv2l+ciaIA4qumOZV6pqq8ufOmRIte/sITC+xfndhJMDV8KUFF76sbor8zwp0HxhQ== X-Received: by 2002:a17:906:3b13:: with SMTP id g19mr21733356ejf.238.1619668887568; Wed, 28 Apr 2021 21:01:27 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:27 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 6/7] trace-cmd library: Extend the create file APIs to support different file version Date: Thu, 29 Apr 2021 07:01:18 +0300 Message-Id: <20210429040119.843617-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added additional parameter for file version to all trace-cmd library APIs for creating a new trace file. The caller could specify what is the desired version of the created file: tracecmd_create_file_latency tracecmd_create_init_file_glob tracecmd_create_init_fd_glob tracecmd_create_init_fd_msg tracecmd_create_init_file tracecmd_create_init_file_override Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 19 ++++--- lib/trace-cmd/trace-output.c | 56 ++++++++++++------- tracecmd/trace-record.c | 12 ++-- tracecmd/trace-restore.c | 4 +- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 29e56271..def01b68 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -266,20 +266,25 @@ struct tracecmd_event_list { struct tracecmd_option; struct tracecmd_msg_handle; -struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); +struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus, + unsigned long file_version); struct tracecmd_output * -tracecmd_create_init_file_glob(const char *output_file, - struct tracecmd_event_list *list); +tracecmd_create_init_file_glob(const char *output_file, struct tracecmd_event_list *list, + unsigned long file_version); struct tracecmd_output *tracecmd_create_init_fd(int fd); struct tracecmd_output * -tracecmd_create_init_fd_glob(int fd, struct tracecmd_event_list *list); +tracecmd_create_init_fd_glob(int fd, struct tracecmd_event_list *list, + unsigned long file_version); struct tracecmd_output * tracecmd_create_init_fd_msg(struct tracecmd_msg_handle *msg_handle, - struct tracecmd_event_list *list); -struct tracecmd_output *tracecmd_create_init_file(const char *output_file); + struct tracecmd_event_list *list, + unsigned long file_version); +struct tracecmd_output *tracecmd_create_init_file(const char *output_file, + unsigned long file_version); struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file, const char *tracing_dir, - const char *kallsyms); + const char *kallsyms, + unsigned long file_version); struct tracecmd_option *tracecmd_add_option(struct tracecmd_output *handle, unsigned short id, int size, const void *data); diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index f36718f1..edff7961 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -908,11 +908,13 @@ out_free: return ret; } -static int select_file_version(struct tracecmd_output *handle, - struct tracecmd_input *ihandle) +static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle, + unsigned long file_version) { if (ihandle) handle->file_version = tracecmd_get_file_version(ihandle); + else if (file_version > 0) + handle->file_version = file_version; else handle->file_version = FILE_VERSION; @@ -924,7 +926,8 @@ create_file_fd(int fd, struct tracecmd_input *ihandle, const char *tracing_dir, const char *kallsyms, struct tracecmd_event_list *list, - struct tracecmd_msg_handle *msg_handle) + struct tracecmd_msg_handle *msg_handle, + unsigned long file_version) { struct tracecmd_output *handle; struct tep_handle *pevent; @@ -945,7 +948,7 @@ create_file_fd(int fd, struct tracecmd_input *ihandle, handle->msg_handle = msg_handle; - if (select_file_version(handle, ihandle)) + if (select_file_version(handle, ihandle, file_version)) goto out_free; list_head_init(&handle->options); @@ -1023,7 +1026,8 @@ static struct tracecmd_output *create_file(const char *output_file, struct tracecmd_input *ihandle, const char *tracing_dir, const char *kallsyms, - struct tracecmd_event_list *list) + struct tracecmd_event_list *list, + unsigned long file_version) { struct tracecmd_output *handle; int fd; @@ -1032,7 +1036,7 @@ static struct tracecmd_output *create_file(const char *output_file, if (fd < 0) return NULL; - handle = create_file_fd(fd, ihandle, tracing_dir, kallsyms, list, NULL); + handle = create_file_fd(fd, ihandle, tracing_dir, kallsyms, list, NULL, file_version); if (!handle) { close(fd); unlink(output_file); @@ -1332,13 +1336,15 @@ int tracecmd_write_cmdlines(struct tracecmd_output *handle) return 0; } -struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus) +struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus, + unsigned long file_version) { struct tracecmd_output *handle; char *path; int ret; - handle = create_file(output_file, NULL, NULL, NULL, &all_event_list); + handle = create_file(output_file, NULL, NULL, NULL, + &all_event_list, file_version); if (!handle) return NULL; @@ -1633,39 +1639,46 @@ struct tracecmd_output *tracecmd_get_output_handle_fd(int fd) struct tracecmd_output *tracecmd_create_init_fd(int fd) { - return create_file_fd(fd, NULL, NULL, NULL, &all_event_list, NULL); + return create_file_fd(fd, NULL, NULL, NULL, &all_event_list, NULL, 0); } struct tracecmd_output * tracecmd_create_init_fd_msg(struct tracecmd_msg_handle *msg_handle, - struct tracecmd_event_list *list) + struct tracecmd_event_list *list, + unsigned long file_version) { - return create_file_fd(msg_handle->fd, NULL, NULL, NULL, list, msg_handle); + return create_file_fd(msg_handle->fd, NULL, NULL, NULL, + list, msg_handle, file_version); } struct tracecmd_output * -tracecmd_create_init_fd_glob(int fd, struct tracecmd_event_list *list) +tracecmd_create_init_fd_glob(int fd, struct tracecmd_event_list *list, + unsigned long file_version) { - return create_file_fd(fd, NULL, NULL, NULL, list, NULL); + return create_file_fd(fd, NULL, NULL, NULL, list, NULL, file_version); } struct tracecmd_output * -tracecmd_create_init_file_glob(const char *output_file, - struct tracecmd_event_list *list) +tracecmd_create_init_file_glob(const char *output_file, struct tracecmd_event_list *list, + unsigned long file_version) { - return create_file(output_file, NULL, NULL, NULL, list); + return create_file(output_file, NULL, NULL, NULL, list, file_version); } -struct tracecmd_output *tracecmd_create_init_file(const char *output_file) +struct tracecmd_output *tracecmd_create_init_file(const char *output_file, + unsigned long file_version) { - return create_file(output_file, NULL, NULL, NULL, &all_event_list); + return create_file(output_file, NULL, NULL, NULL, + &all_event_list, file_version); } struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file, const char *tracing_dir, - const char *kallsyms) + const char *kallsyms, + unsigned long file_version) { - return create_file(output_file, NULL, tracing_dir, kallsyms, &all_event_list); + return create_file(output_file, NULL, tracing_dir, kallsyms, + &all_event_list, file_version); } /** @@ -1682,7 +1695,8 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, { struct tracecmd_output *handle; - handle = create_file(file, ihandle, NULL, NULL, &all_event_list); + handle = create_file(file, ihandle, NULL, NULL, &all_event_list, + tracecmd_get_file_version(ihandle)); if (!handle) return NULL; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index fd03a605..6775338b 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3645,7 +3645,7 @@ setup_connection(struct buffer_instance *instance, struct common_record_context /* Now create the handle through this socket */ if (msg_handle->version == V3_PROTOCOL) { - network_handle = tracecmd_create_init_fd_msg(msg_handle, listed_events); + network_handle = tracecmd_create_init_fd_msg(msg_handle, listed_events, 0); if (!network_handle) goto error; tracecmd_set_quiet(network_handle, quiet); @@ -3663,8 +3663,7 @@ setup_connection(struct buffer_instance *instance, struct common_record_context if (ret) goto error; } else { - network_handle = tracecmd_create_init_fd_glob(msg_handle->fd, - listed_events); + network_handle = tracecmd_create_init_fd_glob(msg_handle->fd, listed_events, 0); if (!network_handle) goto error; tracecmd_set_quiet(network_handle, quiet); @@ -3851,8 +3850,7 @@ static void setup_agent(struct buffer_instance *instance, { struct tracecmd_output *network_handle; - network_handle = tracecmd_create_init_fd_msg(instance->msg_handle, - listed_events); + network_handle = tracecmd_create_init_fd_msg(instance->msg_handle, listed_events, 0); add_options(network_handle, ctx); tracecmd_write_cmdlines(network_handle); tracecmd_write_cpus(network_handle, instance->cpu_count); @@ -4244,7 +4242,7 @@ static void record_data(struct common_record_context *ctx) return; if (latency) { - handle = tracecmd_create_file_latency(ctx->output, local_cpu_count); + handle = tracecmd_create_file_latency(ctx->output, local_cpu_count, 0); tracecmd_set_quiet(handle, quiet); } else { if (!local_cpu_count) @@ -4275,7 +4273,7 @@ static void record_data(struct common_record_context *ctx) touch_file(temp_files[i]); } - handle = tracecmd_create_init_file_glob(ctx->output, listed_events); + handle = tracecmd_create_init_file_glob(ctx->output, listed_events, 0); if (!handle) die("Error creating output file"); tracecmd_set_quiet(handle, quiet); diff --git a/tracecmd/trace-restore.c b/tracecmd/trace-restore.c index 280a37f0..f2b15434 100644 --- a/tracecmd/trace-restore.c +++ b/tracecmd/trace-restore.c @@ -91,7 +91,7 @@ void trace_restore (int argc, char **argv) } handle = tracecmd_create_init_file_override(output, tracing_dir, - kallsyms); + kallsyms, 0); if (!handle) die("Unabled to create output file %s", output); if (tracecmd_write_cmdlines(handle) < 0) @@ -128,7 +128,7 @@ void trace_restore (int argc, char **argv) handle = tracecmd_copy(ihandle, output); tracecmd_close(ihandle); } else - handle = tracecmd_create_init_file(output); + handle = tracecmd_create_init_file(output, 0); if (!handle) die("error writing to %s", output); From patchwork Thu Apr 29 04:01:19 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: 12230417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 059ADC43461 for ; Thu, 29 Apr 2021 04:01:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D2CE261446 for ; Thu, 29 Apr 2021 04:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbhD2ECR (ORCPT ); Thu, 29 Apr 2021 00:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231405AbhD2ECP (ORCPT ); Thu, 29 Apr 2021 00:02:15 -0400 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 A19BFC06138C for ; Wed, 28 Apr 2021 21:01:29 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id z5so40352371edr.11 for ; Wed, 28 Apr 2021 21:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RLVirN8WZI8eB6p02Dt457R0Zc3l+ePoOZUR/rBIvJY=; b=SYpltgChO291U5pbrtmR/4unw6qmF8H8ZsbF0r/NGI+4Sf5jvSjL4hmTcDNCHlHSzI V4W68Z1L7dkJGiB/SjGyYxJjkFO482v32stVD7SdkxMW5mV9faa1s6MUMl1WHINamJBb GSKx8dCD/KO4UUYyywUyY9xAXQyiptFdiqxHah+uXvTtRkcwEyvHv48Tqr4gGNWHIzm0 BSTw1WMZB6wc6YWJ4oEpmNONTL3JFFAdVDcpf0yKG8GgS73FNi+aGGbfk01+pu0FgIUH 5oOuqDxWoLcCSczr936u991yNrK1XIJ6sKqpx0/fDbr1k5wDXIp4ev8SnoRPohkpIB6+ XsKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RLVirN8WZI8eB6p02Dt457R0Zc3l+ePoOZUR/rBIvJY=; b=Or5LjaC3IPzV3GH4Ln4UY0EW7eHOrajo1ziGTk8/JYaeaIIhH1kTAqUd7aR3e96oA7 RFJrYAG9Eff6nfFGvSPG73hIghSJwfReQ/eGt2pURVejxulTAW52k7YSmiRoBEDpTUdI Rt4eif6nMXv27jtSt9cs5DqVaU3SRBuc1xS/SyjuolOryaPSAn5g03N1KW0vjzZZKM1k s0cUZNbP7p6VDealOqmxoUkLkakT3RMgy04wQN3eRAKajUL1MTkFOBp6gVCZkKMZUlXI k44MrJo2Ui5N8FbB7ZkGC9H3VlRZX0XMlmdqZ9WVeyzyzDqOKQ/sLQDEE4r4/9T/cOzn 4wag== X-Gm-Message-State: AOAM531HWurm+meW4goCaFgqFdIb/qk/PnMTtFfoTZTDAO/W6nCGH9jX wvKS9Dk6OBBav/8GQGR1TuFc2/08EYHF0g== X-Google-Smtp-Source: ABdhPJz6+0zLRqtZO51fTiGRblVEdJg/M5Rf03DSs/RleB2RLNvj6pSfam839qxIbOLheHOexwYziA== X-Received: by 2002:aa7:dd96:: with SMTP id g22mr3603818edv.222.1619668888463; Wed, 28 Apr 2021 21:01:28 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id z26sm1040740ejl.38.2021.04.28.21.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 21:01:28 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 7/7] trace-cmd record: Add new parameter --file-version Date: Thu, 29 Apr 2021 07:01:19 +0300 Message-Id: <20210429040119.843617-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210429040119.843617-1-tz.stoyanov@gmail.com> References: <20210429040119.843617-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 optional parameter to "trace-cmd record", can be used to select the desired file version of the trace output file. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 23 ++++++++++++++++++----- tracecmd/trace-usage.c | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 6775338b..f95db0e4 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -199,6 +199,7 @@ struct common_record_context { char *date2ts; char *user; const char *clock; + unsigned long file_version; struct tsc_nsec tsc2nsec; int data_flags; int tsync_loop_interval; @@ -3645,7 +3646,8 @@ setup_connection(struct buffer_instance *instance, struct common_record_context /* Now create the handle through this socket */ if (msg_handle->version == V3_PROTOCOL) { - network_handle = tracecmd_create_init_fd_msg(msg_handle, listed_events, 0); + network_handle = tracecmd_create_init_fd_msg(msg_handle, listed_events, + ctx->file_version); if (!network_handle) goto error; tracecmd_set_quiet(network_handle, quiet); @@ -3663,7 +3665,8 @@ setup_connection(struct buffer_instance *instance, struct common_record_context if (ret) goto error; } else { - network_handle = tracecmd_create_init_fd_glob(msg_handle->fd, listed_events, 0); + network_handle = tracecmd_create_init_fd_glob(msg_handle->fd, listed_events, + ctx->file_version); if (!network_handle) goto error; tracecmd_set_quiet(network_handle, quiet); @@ -3850,7 +3853,8 @@ static void setup_agent(struct buffer_instance *instance, { struct tracecmd_output *network_handle; - network_handle = tracecmd_create_init_fd_msg(instance->msg_handle, listed_events, 0); + network_handle = tracecmd_create_init_fd_msg(instance->msg_handle, listed_events, + ctx->file_version); add_options(network_handle, ctx); tracecmd_write_cmdlines(network_handle); tracecmd_write_cpus(network_handle, instance->cpu_count); @@ -4242,7 +4246,8 @@ static void record_data(struct common_record_context *ctx) return; if (latency) { - handle = tracecmd_create_file_latency(ctx->output, local_cpu_count, 0); + handle = tracecmd_create_file_latency(ctx->output, local_cpu_count, + ctx->file_version); tracecmd_set_quiet(handle, quiet); } else { if (!local_cpu_count) @@ -4273,7 +4278,8 @@ static void record_data(struct common_record_context *ctx) touch_file(temp_files[i]); } - handle = tracecmd_create_init_file_glob(ctx->output, listed_events, 0); + handle = tracecmd_create_init_file_glob(ctx->output, listed_events, + ctx->file_version); if (!handle) die("Error creating output file"); tracecmd_set_quiet(handle, quiet); @@ -5499,6 +5505,7 @@ void init_top_instance(void) } enum { + OPT_file_version = 239, OPT_tsc2nsec = 240, OPT_fork = 241, OPT_tsyncinterval = 242, @@ -5933,6 +5940,7 @@ static void parse_record_options(int argc, {"tsync-interval", required_argument, NULL, OPT_tsyncinterval}, {"fork", no_argument, NULL, OPT_fork}, {"tsc2nsec", no_argument, NULL, OPT_tsc2nsec}, + {"file-version", required_argument, NULL, OPT_file_version}, {NULL, 0, NULL, 0} }; @@ -6354,6 +6362,11 @@ static void parse_record_options(int argc, die("TSC to nanosecond is not supported"); ctx->instance->flags |= BUFFER_FL_TSC2NSEC; break; + case OPT_file_version: + ctx->file_version = atoi(optarg); + if (!tracecmd_is_version_supported(ctx->file_version)) + die("File version %d is not supported", ctx->file_version); + break; case OPT_quiet: case 'q': quiet = true; diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 98247074..e5b54114 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -68,6 +68,7 @@ static struct usage_help usage_help[] = { " If a negative number is specified, timestamps synchronization is disabled" " If 0 is specified, no loop is performed - timestamps offset is calculated only twice," " at the beginnig and at the end of the trace\n" + " --file-version select the desired version of the trace output file\n" }, { "set",