From patchwork Fri Oct 8 04:13:12 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: 12544213 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 9AD37C433EF for ; Fri, 8 Oct 2021 04:13:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7669A60F6E for ; Fri, 8 Oct 2021 04:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237133AbhJHEPV (ORCPT ); Fri, 8 Oct 2021 00:15:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229932AbhJHEPU (ORCPT ); Fri, 8 Oct 2021 00:15:20 -0400 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 697A7C061570 for ; Thu, 7 Oct 2021 21:13:25 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id d3so3831600edp.3 for ; Thu, 07 Oct 2021 21:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+vzs8CFP8MRdUsZf0wYt3y8jinycwtDdu6GHRKFah8Y=; b=VUYBCbEs91VmeEHwym5klOiFjQZt5npIwLZorjpOtUMIYcjg21WEhqmJCVF1oOHYrm LwFGf8dV6OS81UKrkKdL59vRYCa27sV4AhqGmOxR2JCgwHGod/mNhMSfXjiuHCTUndSC ++mGXXNSwmA/xCLpjQU9+uCL+zI99BHsepVM+VRQJSpYtnJL9rOhXj/Rtk120ZJCH9MH VQ3PnBHVMpbTgV8kf6mauPsaJwCsXQL7UgNd5UIVBU3eE9LdSJCMwR60mrarbG+/pWpn RCrajUipLbbHxM87yqllZhafUT2wm/uNHDo4p20CYk1Tox3Khv4hnEx/662V3afPNDSn bVwg== 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=+vzs8CFP8MRdUsZf0wYt3y8jinycwtDdu6GHRKFah8Y=; b=LOHQvMPnYdJLE2T4YCMNIrLzmR4JfZaZ05vs3Z1Bg4muwdq+2sWM4ggYBJGe0Wu8sY 1GLoKlRqLwCQhYFOg/jL6nJ2Q5DCIyzqsAeymHL71TaOFTiDt8IfJS+7dlbbsIjauKSG YMLvYEYSeo8VSTaeSmWCbwHmkZQ9fUUcIvyv08a5TNYKKe9SQKHO/1N+IehlZf5ZmEaE 6QKHsIkORqTcdFT8uWddCFa4D0RwkDD8kLEQWI6YGEfz6w+oBW8Pjc3WJ0+oTWO7Iobu mth87c//8umcPDZAyo14Fv41+YlLICCjMe8GqKKD9YcOR+oE0G25Gu/09M4Q5wHRX9kh GCUw== X-Gm-Message-State: AOAM532iW9lgFlOf4+TijhvPsIIBpub7LmM0tJx/76ZdGCfxoeMhFLdd 0AJrJExUPKrKMI0CoZ5/iAu0mjm++D5l5Q== X-Google-Smtp-Source: ABdhPJxWMaL6fkDsjPEnhpN3GEDcRZjhzcv8U9oQBjEtProYlvw3xroux7zHu6EcbIXj6GWvVVrEFg== X-Received: by 2002:a50:bf0f:: with SMTP id f15mr11630337edk.43.1633666404080; Thu, 07 Oct 2021 21:13:24 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:23 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 01/10] trace-cmd library: New API for allocating an output handler Date: Fri, 8 Oct 2021 07:13:12 +0300 Message-Id: <20211008041321.973755-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The API only allocates a handler and performs minimal initialization. No data is written in the file. tracecmd_output_allocate() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 4 ++- lib/trace-cmd/trace-output.c | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index c58b09e9..b4cee0f6 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -102,7 +102,8 @@ static inline int tracecmd_host_bigendian(void) /* --- Opening and Reading the trace.dat file --- */ enum tracecmd_file_states { - TRACECMD_FILE_INIT = 1, + TRACECMD_FILE_ALLOCATED = 0, + TRACECMD_FILE_INIT, TRACECMD_FILE_HEADERS, TRACECMD_FILE_FTRACE_EVENTS, TRACECMD_FILE_ALL_EVENTS, @@ -268,6 +269,7 @@ struct tracecmd_event_list { struct tracecmd_option; struct tracecmd_msg_handle; +struct tracecmd_output *tracecmd_output_allocate(int fd); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index fe1d1aaa..3878b963 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -59,6 +59,7 @@ struct tracecmd_output { unsigned long file_state; unsigned long file_version; size_t options_start; + bool big_endian; struct list_head options; struct tracecmd_msg_handle *msg_handle; @@ -883,6 +884,41 @@ out_free: return ret; } +/** + * tracecmd_output_allocate - allocate new output handler to a trace file + * @handle: file descriptor to an empty file, it can be -1 if the handler + * will not write to a file + * + * This API only allocates a handler and performs minimal initialization. + * No data is written in the file. + * + * Returns pointer to a newly allocated file descriptor, that can be used + * with other library APIs. In case of an error, NULL is returned. The returned + * handler must be freed with tracecmd_output_close() or tracecmd_output_free() + */ +struct tracecmd_output *tracecmd_output_allocate(int fd) +{ + struct tracecmd_output *handle; + + handle = calloc(1, sizeof(*handle)); + if (!handle) + return NULL; + + handle->fd = fd; + + handle->file_version = FILE_VERSION; + + handle->page_size = getpagesize(); + handle->big_endian = tracecmd_host_bigendian(); + + list_head_init(&handle->options); + + handle->file_state = TRACECMD_FILE_ALLOCATED; + + return handle; +} + + static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) { From patchwork Fri Oct 8 04:13: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: 12544215 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 2E78CC433F5 for ; Fri, 8 Oct 2021 04:13:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B92E60F6B for ; Fri, 8 Oct 2021 04:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbhJHEPV (ORCPT ); Fri, 8 Oct 2021 00:15:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237160AbhJHEPV (ORCPT ); Fri, 8 Oct 2021 00:15:21 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8022EC061570 for ; Thu, 7 Oct 2021 21:13:26 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id p13so31726590edw.0 for ; Thu, 07 Oct 2021 21:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bkf14UTvC7wyjQOgnsEbWJkZBpY0MyQC1pPagFRphH0=; b=c9DccbL9kQ5wo+9gF+DbY3ZoO8A7TMeGcQqvXaOeoYvbSnY07QWc+TqZ52pnJQDDq1 37wDFwkY8C+xngOgc8aD+QbhVRysJP5vubM0dP/CbDzq6TH6dNo7MNwckYJ7UyfIRnCp CSs+R6RCmFdMm5B06c5VZBAnfF41A4vhHEzxpw35AsrmAaGCD8Gt72eTYfjGijCsMH+0 irC9OcoJZ/5PlquGU28VHhDJylWDyf28/yrVaw5LiBsYhe8oVRkDuJ+N6tXcgShVHv3m bu0DEkXSujBEOVPh++1Krp7/+77Me7kmk9nso6W3p/nsVhaNHhZ7y0AtznNe5yb6d8kI lgJQ== 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=Bkf14UTvC7wyjQOgnsEbWJkZBpY0MyQC1pPagFRphH0=; b=QyLNSFKv6LcEAT2jsIUJmevX5S054cx6YwQ6P5rYqCeLDuQSUvDcJ8TvcUkQ7JgXnM 0BfrpuCIuS+rB3STCLWZgI5pRWvKzyQXQqYKdrEI8QDEPxP4DPKpQy8knqkmFasM/0UE gabHQFWvLDgxYPLZy4rkOhl+5fXZ5vQg/SSOfb2hycKBWGx5BEP6CHAqf1GGA/C68KBb R6tmda4B9QsbgIm3s8gFFew4lMR4QmwZw0cBxXR/Bsl1olyImIrHV4oPZVft/Rv1qi5n RGAwM0FyeWDxJ9L+4KzLKsEq2OYjf0x6Kepo4Bc9uEusAsdNd/LzDc6LMKInt70KUM3R N2JQ== X-Gm-Message-State: AOAM530xdD1shkn2Uion+1RKRX0oT2NcLKYME3jlePXIdcQ7YwU7ZdDk MZ8lDYfNdkrDJgsG5U5mpzBb/3U5A+UsfA== X-Google-Smtp-Source: ABdhPJztPEhIzgzrjiNryZqNjCBHDvNIkiQ2c8NJXd99NAve2gRbcJjmAGZY7Q8yBQxQ09vl8e6CkQ== X-Received: by 2002:a17:906:cd11:: with SMTP id oz17mr1330437ejb.67.1633666405160; Thu, 07 Oct 2021 21:13:25 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:24 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 02/10] trace-cmd library: New API for setting a message context to an output handler Date: Fri, 8 Oct 2021 07:13:13 +0300 Message-Id: <20211008041321.973755-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new API associates previously created handler to message context with given output handler. The message context is used by the output handler to send data over a network, instead writing to a local file. tracecmd_output_allocate() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 2 ++ lib/trace-cmd/trace-output.c | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index b4cee0f6..2f34af13 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -270,6 +270,8 @@ struct tracecmd_option; struct tracecmd_msg_handle; struct tracecmd_output *tracecmd_output_allocate(int fd); +int tracecmd_output_set_msg(struct tracecmd_output *handler, + struct tracecmd_msg_handle *msg_handle); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 3878b963..d73c4f99 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -918,6 +918,28 @@ struct tracecmd_output *tracecmd_output_allocate(int fd) return handle; } +/** + * tracecmd_output_set_msg - associated an output file handler with network message handler + * @handle: output handler to a trace file. + * @msg_handle: network handler, allocated by tracecmd_msg_handle_alloc() + * + * This API associates an output file handler with a network stream. All subsequent API calls + * with this output file handler will send data over the network using the @msg_handle, instead + * of writing to a file. + * This API must be called after the handler file version is set and before + * tracecmd_output_write_init(). + * + * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state. + */ +int tracecmd_output_set_msg(struct tracecmd_output *handler, struct tracecmd_msg_handle *msg_handle) +{ + if (!handler || handler->file_state != TRACECMD_FILE_ALLOCATED) + return -1; + + handler->msg_handle = msg_handle; + + return 0; +} static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) From patchwork Fri Oct 8 04:13: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: 12544217 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 03A09C433F5 for ; Fri, 8 Oct 2021 04:13:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC5CC60F6E for ; Fri, 8 Oct 2021 04:13:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237217AbhJHEPX (ORCPT ); Fri, 8 Oct 2021 00:15:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237160AbhJHEPW (ORCPT ); Fri, 8 Oct 2021 00:15:22 -0400 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 E22A2C061570 for ; Thu, 7 Oct 2021 21:13:27 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id y12so17935865eda.4 for ; Thu, 07 Oct 2021 21:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JmSHQOTfdOzRzctnytqTBAoaR6Vu2rTRbusrUGqCZYk=; b=plA5/3BRN0cat6nhlzdoHb19je0Icn6DM9/zlEX46yH/eKg6DAz8ZPbJTh5cvd69Uu +N/JVJjg87Nu8bxg8f4zt+tLEipaRXCYBEhbXKeD0YyTgqGTJVsQIXRtNvxFv6HE/VYW pcYgOBjrcZIJ8Vqjh6dz4F/uHnq7Io+IO9Pj2p2YGmfUNmCfFWbTlo4h5Gn+lh2lqiAO WEVRD+ru1+yS9+Ki0FVwZCQ2Ohab3ITxfGorrV9KEeP1z9FNjRFqyjOBPCFMIIZDTOG+ 2VMrH7wyc2+HsqOc0Rl37vJpC8fgEe0EBe5Y0y9Y2oZW1kQA6IutvK1xFMkt9YjlYu5L LYaA== 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=JmSHQOTfdOzRzctnytqTBAoaR6Vu2rTRbusrUGqCZYk=; b=sNKLGGD4CYLoh4iMysJZGJC9zfkpNfuMZmzJwxkSyAD9XhW+Dcm/+hf2WslkOX3cb8 7SfKeUglY1x32wyUAzeo3ZdblVdt5F0sbIMFbUq7UVf95SVAdA7kSJnFXwAjoFv5v7Cu 4fv+ibOEAp9JNGGYnelFL+9dhvziXWx3QBesQenhOwNy37UTdaak/72GO3R1AGZKcbWm ZYxJ/beX6cHm/zvF4g4fLkFAkakCdwDC8B09n/KhXxZtmo6SHYWrcExtH/SHPU6TdKGP pI+QyH0CYPJ2WLe/a9Kldp5+4DbE3BC37uQmx49Kco/EIFzsI29wp5wHxOPs9o3HsQNH iZGQ== X-Gm-Message-State: AOAM532tc3Sq6E0Pjy2Jum7+h06hMYstpqozrweaOaFGXkeU+N63p/RT GfiJH/y2t5tf8/v5GcOzuZ7JoBRVOd3t7w== X-Google-Smtp-Source: ABdhPJz7/TAFwYOmiEb7ag3zGhmFDQWvLAy5Xm3UzQpBLkAl3mtfECcXbAytEQ2tB8txrUc7c/BUmw== X-Received: by 2002:a50:cfc1:: with SMTP id i1mr11643528edk.251.1633666406565; Thu, 07 Oct 2021 21:13:26 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:25 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 03/10] trace-cmd library: New API for setting a custom trace directory to an output handler Date: Fri, 8 Oct 2021 07:13:14 +0300 Message-Id: <20211008041321.973755-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new API associates a custom tracing directory with an output file handler. It is used when creating the trace file instead of the system default tracing directory. tracecmd_output_set_trace_dir() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 2f34af13..ad9d5265 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -272,6 +272,7 @@ struct tracecmd_msg_handle; struct tracecmd_output *tracecmd_output_allocate(int fd); int tracecmd_output_set_msg(struct tracecmd_output *handler, struct tracecmd_msg_handle *msg_handle); +int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index d73c4f99..a5d7ed5f 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -941,6 +941,33 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler, struct tracecmd_msg return 0; } +/** + * tracecmd_output_set_trace_dir - Set a custom tracing dir, instead of system default + * @handle: output handler to a trace file. + * @tracing_dir: full path to a directory with tracing files + * + * This API associates an output file handler with a custom tracing directory, to be used when + * creating the trace file instead of the system default tracing directory. + * This API must be called before tracecmd_output_write_init(). + * + * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state. + */ +int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir) +{ + if (!handler || handler->file_state != TRACECMD_FILE_ALLOCATED) + return -1; + + free(handler->tracing_dir); + if (tracing_dir) { + handler->tracing_dir = strdup(tracing_dir); + if (!handler->tracing_dir) + return -1; + } else + handler->tracing_dir = NULL; + + return 0; +} + static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) { From patchwork Fri Oct 8 04:13: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: 12544219 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 7EC39C433EF for ; Fri, 8 Oct 2021 04:13:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 637B360F6E for ; Fri, 8 Oct 2021 04:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237160AbhJHEPY (ORCPT ); Fri, 8 Oct 2021 00:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEPX (ORCPT ); Fri, 8 Oct 2021 00:15:23 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 212AEC061570 for ; Thu, 7 Oct 2021 21:13:29 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id r18so31235220edv.12 for ; Thu, 07 Oct 2021 21:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=etcGgXiYo5reRZk9tFjJLvh4qcHFH/gCF83vi60PtVw=; b=RGwqI9ocsrp3IzCylz5UMREOCrDvF8LqxUxx4x+LnxHeEIIkbD2JXhZfAnx63W5GCQ 1S2G0Gk+nADxNY255wPwcad7JMeRAeSiY4UYyN44LjYsP2dnRPYGmH+y4BfymthfLYJC HkYitEOb4r7NnRbDlzj0PyIFCbtal4cPotRU1WC0xi7IMZi3ZI1eIKfbdb652iXOuk7l CFt9qTrDMhRHmT73X6ToZ3F2UFApsPnpUrFWSQjVA0uKho8iQHAaKeYdtFI9jIWMZJxw ZFpYN/a2Rpnb92QorQcBo/NmKLa1c2CIhMwEBrVrKaalyL1rDe981E6IwVGzTIeQsmu8 ZcOg== 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=etcGgXiYo5reRZk9tFjJLvh4qcHFH/gCF83vi60PtVw=; b=A7CUj5qIrkbx/ooyWbs/CEBosire/7ImLSobMk/2GlaVPwUcDfIm0rR0PYrBLY2nxj HWlM17zSjEejT8peEERRGTeW1alI7MTkRRjAuKZqrZFF0gn5pDvDWV9bCvulXfP1Onl4 uvM+GklQvlpI5f2OWXDeOwBT0I2rTNPaVkFAG+OxyK0h56SOo+fUey3/sN6eJl1DcjZV gwvxAXaiSdwY57iPTvoXsRrGqQA5YMLNqQJFZ3PaZ3o0v72QiGJx+W1FiiJ5BaD8uPgN 6bBNn8jk4eDHFQA8+QqabKVjVYSPMI+bb15WMzvJaVhTYkhPVegnL3FdwQwYzsR19p3x ynbA== X-Gm-Message-State: AOAM532r4Uw6MEEkAe0RjcOIAmmOx8AQEy7CLmeZhHo6hWFWCSuduw9Y lnpDjHKBeBIaDqeGb2eecXYoDhnBQ3MbtQ== X-Google-Smtp-Source: ABdhPJzD56QTvgsFBl6aopU8xyMyn8qrUE8rN5Dbl7F6agcqS0Aw3x+RkYq7LPYp2+depkWrfSm6pA== X-Received: by 2002:a05:6402:143b:: with SMTP id c27mr12201044edx.224.1633666407713; Thu, 07 Oct 2021 21:13:27 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:27 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 04/10] trace-cmd library: New API for setting a custom kallsyms to an output handler Date: Fri, 8 Oct 2021 07:13:15 +0300 Message-Id: <20211008041321.973755-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new API associates an output file handler with a custom kernel symbols file. It is used when creating the trace file instead of the system default kernel symbols file. tracecmd_output_set_kallsyms() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index ad9d5265..8ef448eb 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -273,6 +273,7 @@ struct tracecmd_output *tracecmd_output_allocate(int fd); int tracecmd_output_set_msg(struct tracecmd_output *handler, struct tracecmd_msg_handle *msg_handle); int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir); +int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index a5d7ed5f..c654561a 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -54,6 +54,7 @@ struct tracecmd_output { int cpus; struct tep_handle *pevent; char *tracing_dir; + char *kallsyms; int nr_options; bool quiet; unsigned long file_state; @@ -767,8 +768,8 @@ static int read_proc_kallsyms(struct tracecmd_output *handle, return -1; } - if (kallsyms) - path = kallsyms; + if (handle->kallsyms) + path = handle->kallsyms; ret = stat(path, &st); if (ret < 0) { @@ -968,6 +969,33 @@ int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *t return 0; } +/** + * tracecmd_output_set_kallsyms - Set a custom kernel symbols file, instead of system default + * @handle: output handler to a trace file. + * @tracing_dir: full path to a file with kernel symbols + * + * This API associates an output file handler with a custom kernel symbols file, to be used when + * creating the trace file instead of the system default kernel symbols file. + * This API must be called before tracecmd_output_write_init(). + * + * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state. + */ +int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms) +{ + if (!handler || handler->file_state != TRACECMD_FILE_ALLOCATED) + return -1; + + free(handler->kallsyms); + if (kallsyms) { + handler->kallsyms = strdup(kallsyms); + if (!handler->kallsyms) + return -1; + } else + handler->kallsyms = NULL; + + return 0; +} + static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) { From patchwork Fri Oct 8 04:13: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: 12544221 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 8FABEC4332F for ; Fri, 8 Oct 2021 04:13:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77E6161073 for ; Fri, 8 Oct 2021 04:13:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237293AbhJHEPZ (ORCPT ); Fri, 8 Oct 2021 00:15:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEPY (ORCPT ); Fri, 8 Oct 2021 00:15:24 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32AC7C061570 for ; Thu, 7 Oct 2021 21:13:30 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id b8so31166063edk.2 for ; Thu, 07 Oct 2021 21:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oVu8pY3/hQgRZzpaZTZau6X6vXl9h+f2NZxNYNpdzgA=; b=emr0jCV9cE6VY3o7tYq6pyPFCY20tEuEhHcmL3i1HuUkbSooRNdpBephvpvO49Opqg WLWLOAunIdA0JROA1+5J7teqwwWl2RUEbERmFafEolH6U1yncd082wSjqxFgLaXAL+v/ gjV7p3HwIx/Mmj+2bao6yb5RG+VmJe1Od3lI68RWb75xlDBffDo4+WaN2if1898FqnTg 8fFCZLjEN+qNAG8V0+4plXYLhiq9rD8DQCgDJa5RSkY6UOZF+jAzjNpr5LHXb2rL4VoC OBDQcLlJvA6sKNowh7qgeRatd1MIMJsQxYEoguBAyRUCMki5dj6IB5YhxToFT9Nv8xZn cacQ== 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=oVu8pY3/hQgRZzpaZTZau6X6vXl9h+f2NZxNYNpdzgA=; b=qhIzzl+Zu2c+iSAVFI2ySjyLVacilm8zvQYopdwiQkP8UCyfsGSH+oCpk+CVvOFCOn bawT/GmVUnCC9CxFo4qorV6SMxF6truRk6mQGF1sWbruw5XvQOLXjMkiFL41qXRU7R5G AJMxDbgeYzFO2vZZxUEq13RosoifYKh5xfnEGE/5jpAaVClJ9hqP7T/3Ga/PqzO6arJe QE7RyBQQ1/4Aq+g29HpnhBSBHX3HJyab8CY3aPHhk/Jvp/UbMl6Re/yteT1VgA1tQIjv KPAv0xkhFaXMLN4AFrOxh9jzfesrRvl23kDYg8b6SnWwNG5lfxZ912tJAYcBIHEX48dI 97iA== X-Gm-Message-State: AOAM530fIRup+i04dSmkMMLVYtDtTnfVOzypI/XShu2KIB79KAsCFKp6 K/FZs5rCjn8b/fnHPvIf449WIHIIEN2lUg== X-Google-Smtp-Source: ABdhPJyZG9LIk/VYMOKothjGHj3XGV8g2DaHr3T888egMByb9M98vNe284YvueEMPibYJciHJ0qkhg== X-Received: by 2002:a50:eac4:: with SMTP id u4mr11540946edp.259.1633666408739; Thu, 07 Oct 2021 21:13:28 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:28 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 05/10] trace-cmd library: New API to inherit parameters from an existing trace file Date: Fri, 8 Oct 2021 07:13:16 +0300 Message-Id: <20211008041321.973755-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The new API initializes previously allocated output handler with parameters from an input handler to a trace file. tracecmd_output_set_from_input() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 8ef448eb..da1dbb09 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -274,6 +274,7 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler, struct tracecmd_msg_handle *msg_handle); int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir); int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms); +int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index c654561a..7db3729b 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -996,6 +996,39 @@ int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *ka return 0; } +/** + * tracecmd_output_set_from_input - Inherit parameters from an existing trace file + * @handle: output handler to a trace file. + * @ihandle: input handler to an existing trace file. + * + * This API copies parameters from input handler @ihandle, associated with an existing trace file, + * to the output handler @handle, associated with file that is going to be created. + * These parameters are copied: + * - tep handler + * - page size + * - file endian + * - file version + * - file compression protocol + * This API must be called before tracecmd_output_write_init(). + * + * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state. + */ +int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle) +{ + if (!handler || !ihandle || handler->file_state != TRACECMD_FILE_ALLOCATED) + return -1; + + /* get endian, page size, file version and compression */ + /* Use the pevent of the ihandle for later writes */ + handler->pevent = tracecmd_get_tep(ihandle); + tep_ref(handler->pevent); + handler->page_size = tracecmd_page_size(ihandle); + handler->file_version = tracecmd_get_in_file_version(ihandle); + handler->big_endian = tep_is_file_bigendian(handler->pevent); + + return 0; +} + static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) { From patchwork Fri Oct 8 04:13: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: 12544223 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 A6AE3C433F5 for ; Fri, 8 Oct 2021 04:13:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F9A160F6B for ; Fri, 8 Oct 2021 04:13:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237331AbhJHEP0 (ORCPT ); Fri, 8 Oct 2021 00:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEPZ (ORCPT ); Fri, 8 Oct 2021 00:15:25 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F5C0C061570 for ; Thu, 7 Oct 2021 21:13:31 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id i20so15143959edj.10 for ; Thu, 07 Oct 2021 21:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aRa2gSP9g5is5oS3zhXj4hYvo2PgF1YJz8fVmoNqysg=; b=lfKwLj6TnLiDd2k6RjvrOtplQZKrtytfXTCWtijt28vjRz7bfon58uvF1hy4Ug+Ai5 87jDm1zcUAS+SbmO6aOF7fCLZa0qeFfpueCxdMTgiwAgWJRFQlU8AqPGdHL51G12JGlT Zg/Ahs4CodVB0a7nsR2yiknBon7xgYtS375pw9QEHfpZjQDTa49teNly3gDCN0+i5vVh JqL+cExy5/abhFcybKHgzI9UqpuNewb0dfhCFU6/VtSRGiHSlD+RwssUg0vZtdQwfuLS GUse7oVCmyeDRsOBQ8rK2XSQMtw44PipF4exmpC1ExBRw3sdshxFm8gpzV+Fs6BjkhA6 jZ0g== 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=aRa2gSP9g5is5oS3zhXj4hYvo2PgF1YJz8fVmoNqysg=; b=zv+rLgtHIp3FgXx1Y5qKhIXfo3oQnGsPEv27zPSDvq5r6hoW9fExLrhHwKBY7/1C1g ej/gqni8Z8SCmI8a2l1HsdfPC0aVfVIQC8n631VYGCc/nvBJ8Raqa7qhga/tdLcQEzoR oGILs90w4j2QYrGCTrx6tmZnvyuwIX660VxwkSRCwDHP/zk+ZnvQ/6IjRKGbi3lpvde6 Sydt1EvNpkRftT43NQpVogjPQaXIBoKubjMZpdgkvPOaj0xvOYRPq8+6vC4hnz9lyFuY amM7dIZishvxaX1RLeZDki6RIqNc7uZeC3ABvv6CxtIMIdQYDRhExRW3zDa69tKeV1Zq fk8w== X-Gm-Message-State: AOAM531QjU9eOdmJwEWy430HvH9rfeGa7DXc+OuTj2PgZLpwFFx/qvvk CCesAifP0vSR7pbF7llhcRI/SyK6KDfrGg== X-Google-Smtp-Source: ABdhPJzQaqcZ/Fm9OQfjHlsP1GhWvz19Xz+OBzEm717ZD7TGXzet4YbnHVxrLkGaKjcge/oonZIIfQ== X-Received: by 2002:a17:906:48ce:: with SMTP id d14mr1283783ejt.336.1633666409752; Thu, 07 Oct 2021 21:13:29 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:29 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 06/10] trace-cmd library: New API tracecmd_output_write_init Date: Fri, 8 Oct 2021 07:13:17 +0300 Message-Id: <20211008041321.973755-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The API writes initial magic bits in a trace file. tracecmd_output_write_init() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 1 + lib/trace-cmd/trace-output.c | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index da1dbb09..08ec765f 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -275,6 +275,7 @@ int tracecmd_output_set_msg(struct tracecmd_output *handler, int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *tracing_dir); int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms); int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle); +int tracecmd_output_write_init(struct tracecmd_output *handler); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 7db3729b..6e4549f9 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1029,6 +1029,60 @@ int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct trace return 0; } +/** + * tracecmd_output_write_init - Write the initial magics in the trace file + * @handle: output handler to a trace file. + * + * This API must be called after all tracecmd_output_set_...() APIs and before writing anything + * to the trace file. This initial information is written in the file: + * - initial file magic bytes + * - file version + * - data endian + * - long size + * - page size + * - compression header + * + * Returns 0 on success, or -1 if the output file handler is not allocated or not in expected state. + */ +int tracecmd_output_write_init(struct tracecmd_output *handler) +{ + char buf[BUFSIZ]; + int endian4; + + if (!handler || handler->file_state != TRACECMD_FILE_ALLOCATED) + return -1; + + buf[0] = 23; + buf[1] = 8; + buf[2] = 68; + memcpy(buf + 3, "tracing", 7); + + if (do_write_check(handler, buf, 10)) + return -1; + + sprintf(buf, "%lu", handler->file_version); + if (do_write_check(handler, buf, strlen(buf) + 1)) + return -1; + + if (handler->big_endian) + buf[0] = 1; + else + buf[0] = 0; + if (do_write_check(handler, buf, 1)) + return -1; + + /* save size of long (this may not be what the kernel is) */ + buf[0] = sizeof(long); + if (do_write_check(handler, buf, 1)) + return -1; + + endian4 = convert_endian_4(handler, handler->page_size); + if (do_write_check(handler, &endian4, 4)) + return -1; + handler->file_state = TRACECMD_FILE_INIT; + return 0; +} + static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) { From patchwork Fri Oct 8 04:13: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: 12544225 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 A883FC433EF for ; Fri, 8 Oct 2021 04:13:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B6CC60FC4 for ; Fri, 8 Oct 2021 04:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237300AbhJHEP1 (ORCPT ); Fri, 8 Oct 2021 00:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEP0 (ORCPT ); Fri, 8 Oct 2021 00:15:26 -0400 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 147F4C061570 for ; Thu, 7 Oct 2021 21:13:32 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id b8so31166292edk.2 for ; Thu, 07 Oct 2021 21:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qz3DnBbaKVcB7Hzd0sRLfkmhyCjllO3KWpE9qOE4CPY=; b=fxRrJODhb8uLRNTSsfQn4Y9XeSd/ASs8yzlTicrMxnOXYV7EFNb0xhPkBkpHI3CK33 XGruIas70Sh5jJj0NN3Di66NK9hm0dprHRc/WhqvlQ7VHY6zHaHgCQ3DE/W3/wX2/Qlq xalnUe2oqP69tB3Yf6diEdySjE4ri2u314tSB8Iy9fA1pDg32sP+u3wqyt0dsIGW6xwL 7u00fu9l7KjI/7OGj1P+41odDTK1kkgqrJ7vP3jG8eghN18dbs/z+tD9x+KwFgFj6xGy Tn47hjYW0KQtiZk/2Yii510TE4OLs09oAgrihNr0Zd4sfPg/LxuB37aSFgQ96QCZYWyl l0sg== 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=Qz3DnBbaKVcB7Hzd0sRLfkmhyCjllO3KWpE9qOE4CPY=; b=b0ZNvWvDiCm+Lcc0qRKWn7FLV+jla90s+13iYmoRyoVj4eHpjRdo5cm+y5JUpsBPGI 7QO5BFzS1/KGldo+Xf+ITIkOdzUdqL+w1swXdNsutWqRi4Ej0s6g3l2P6pGhQ/2ZH7Av G3Mm/W4muwhSvVMHBzhivUgL9suHw58FVitfvzyOT1mFdoh7mm5dvB1cyUYZH0cImh6a YN/u9bcKMB/m3xdMMH331BhdJuHx/pkORdRGxo3HAbhRRt4k423wRvmmcvI06aRFj2x5 uBAC0RIvnmrTS1BaCOBu0zsbTnwPK7l6FfymwQ6atX5cK6IY4N7hCDRc7tmxGa38J++3 LWqA== X-Gm-Message-State: AOAM531s4Vt1M11EfsSvH7uhJ9R+BY8pklzGzjl897ZUYKrm7E/01ROE jkVEkzWkzf/fqqyzqYAV65Jhsr0fQe1dMg== X-Google-Smtp-Source: ABdhPJwwFRA4QBWX9oy+CECpBkWf4jtMrGiYBW0CnulgGyPPYwzggtiFX9zEcK9m6dxOzYaTw+99Dg== X-Received: by 2002:a17:907:785a:: with SMTP id lb26mr1230390ejc.77.1633666410700; Thu, 07 Oct 2021 21:13:30 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:30 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 07/10] trace-cmd library: New API to write headers of a trace file Date: Fri, 8 Oct 2021 07:13:18 +0300 Message-Id: <20211008041321.973755-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The API writes metadata headers in a trace file. tracecmd_output_write_headers() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 3 ++ lib/trace-cmd/trace-output.c | 44 +++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 08ec765f..086e6906 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -276,6 +276,9 @@ int tracecmd_output_set_trace_dir(struct tracecmd_output *handler, const char *t int tracecmd_output_set_kallsyms(struct tracecmd_output *handler, const char *kallsyms); int tracecmd_output_set_from_input(struct tracecmd_output *handler, struct tracecmd_input *ihandle); int tracecmd_output_write_init(struct tracecmd_output *handler); +int tracecmd_output_write_headers(struct tracecmd_output *handler, + struct tracecmd_event_list *list); + struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); struct tracecmd_output * tracecmd_create_init_file_glob(const char *output_file, diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 6e4549f9..f8a16d82 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -684,7 +684,7 @@ static int read_event_files(struct tracecmd_output *handle, break; } /* all events are listed, use a global glob */ - if (list) + if (!event_list || list) event_list = &all_events; systems = create_event_list(handle, event_list); @@ -754,8 +754,7 @@ err: tracecmd_warning("can't set kptr_restrict"); } -static int read_proc_kallsyms(struct tracecmd_output *handle, - const char *kallsyms) +static int read_proc_kallsyms(struct tracecmd_output *handle) { unsigned int size, check_size, endian4; const char *path = "/proc/kallsyms"; @@ -1083,6 +1082,43 @@ int tracecmd_output_write_init(struct tracecmd_output *handler) return 0; } +/** + * tracecmd_output_write_headers - Write the trace file headers + * @handle: output handler to a trace file. + * @list: desired events that will be included in the trace file. + * It can be NULL for all available events + * + * These headers are written in the file: + * - header files from the tracing directory + * - ftrace events from the tracing directory + * - event file from the tracing directory - all or only the one from @list + * - kernel symbols from the tracing directory + * - kernel printk strings from the tracing directory + * + * Returns 0 on success, or -1 in case of an error. + */ +int tracecmd_output_write_headers(struct tracecmd_output *handler, + struct tracecmd_event_list *list) +{ + if (!handler || handler->file_state < TRACECMD_FILE_ALLOCATED) + return -1; + + /* Write init data, if not written yet */ + if (handler->file_state < TRACECMD_FILE_INIT && tracecmd_output_write_init(handler)) + return -1; + if (read_header_files(handler)) + return -1; + if (read_ftrace_files(handler)) + return -1; + if (read_event_files(handler, list)) + return -1; + if (read_proc_kallsyms(handler)) + return -1; + if (read_ftrace_printk(handler)) + return -1; + return 0; +} + static int select_file_version(struct tracecmd_output *handle, struct tracecmd_input *ihandle) { @@ -1181,7 +1217,7 @@ create_file_fd(int fd, struct tracecmd_input *ihandle, if (read_event_files(handle, list)) goto out_free; - if (read_proc_kallsyms(handle, kallsyms)) + if (read_proc_kallsyms(handle)) goto out_free; if (read_ftrace_printk(handle)) From patchwork Fri Oct 8 04:13: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: 12544227 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 A51CFC4332F for ; Fri, 8 Oct 2021 04:13:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B26A60F55 for ; Fri, 8 Oct 2021 04:13:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237325AbhJHEP2 (ORCPT ); Fri, 8 Oct 2021 00:15:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEP1 (ORCPT ); Fri, 8 Oct 2021 00:15:27 -0400 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 11B85C061570 for ; Thu, 7 Oct 2021 21:13:33 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id d3so3832409edp.3 for ; Thu, 07 Oct 2021 21:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HKqSsAljzOi3bpGyyBEOR9QJLA1ahp92JGLNoMGVxq4=; b=eqzrgJTTbDCe6xwqbTXdlV0zSAcoOQmD5Szy+GVwJH5GCnjLVRffsULRDZosyY2ypa +hndZcIOQUjAe6pCIItK706jfbGqrjfG/XzyKlB3aYb9hemZ1oFLFbtayh840qo/sJMX YU5/3k0ua0fig85p+Nx9Sxak3kltHLOCd4T/qBkLTzUxjQwTIionNSg6YPI5WgFdPZ+I QhesrNKjLsx3dTUOB3JFXtWhvB9csjfG9QcwmATR0XV0uHDh7CRjq6x8MR0v2/urpc90 9aFMQhYnTa9P3S0HmWjGHYte34JxBDiruoJB/oCixC9Y2/tfNZyCIRZvQ2Fbbxnb8mHU i3Wg== 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=HKqSsAljzOi3bpGyyBEOR9QJLA1ahp92JGLNoMGVxq4=; b=CmoivEwntyMSsVKEZc4f0JWeqJEyaKgfAi2Aldf2Lix0WRQVfA49dUqB4YFSDTdYnj jQalT2VaVfPkoubrDZ7QgQ+4D8nTLm+Mob2hTSPfhWogg5ZLAG/Rx/WOR96JfE/YlHEd 7iEIsUYnTtG83OI4dJ4Ydztzm/urwL9gdj2sbzILs8zJ1T1AgNJvhkw9FMTjLrBj5m8z 80fLHHdZjPDIFNYwu3Q5lxfWNmwtaeKTvdvmZEJ4cHmM4Rbx6r+gYjUBMSVpPbXXszBR 0ehXqbvfYBICxZwrZP96LdqPAxhuqkZMsYn19HDjUBBkuf62QeEg1qzXlz7/3Kzp8Z08 LLzQ== X-Gm-Message-State: AOAM532WEkB7eaThig91DCsda3BkhqEwXBYbQT0JJKtC8b4Zst0o4N5B Ip4FESnZ0VMA0uDTmhz3JOKDpg0UEYECoA== X-Google-Smtp-Source: ABdhPJxGg15VMxo6hlbiC9FhdZkJ3d4PKeZe6Crjizl5/nejwAf8ilbeFcuUTMfgqsuPmB/axMa16g== X-Received: by 2002:a17:906:2cd5:: with SMTP id r21mr1237023ejr.435.1633666411719; Thu, 07 Oct 2021 21:13:31 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:31 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 08/10] trace-cmd library: Use the new flow when creating output handler Date: Fri, 8 Oct 2021 07:13:19 +0300 Message-Id: <20211008041321.973755-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The trace-cmd library APIs, that create a new output handler to a trace file, are converted to use the newly introduced APIs. Affected are: tracecmd_create_file_latency() tracecmd_create_init_fd() tracecmd_create_init_file() tracecmd_copy() Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-output.c | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index f8a16d82..9ea85b1c 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1503,11 +1503,19 @@ struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, in { struct tracecmd_output *handle; char *path; + int fd; - handle = create_file(output_file, NULL, NULL, NULL, &all_event_list); - if (!handle) + fd = open(output_file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + if (fd < 0) return NULL; + handle = tracecmd_output_allocate(fd); + if (!handle) + goto out_free; + if (tracecmd_output_write_init(handle)) + goto out_free; + if (tracecmd_output_write_headers(handle, NULL)) + goto out_free; /* * Save the command lines; */ @@ -1801,7 +1809,20 @@ 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); + struct tracecmd_output *out; + + out = tracecmd_output_allocate(fd); + if (!out) + return NULL; + if (tracecmd_output_write_init(out)) + goto error; + if (tracecmd_output_write_headers(out, NULL)) + goto error; + + return out; +error: + tracecmd_output_close(out); + return NULL; } struct tracecmd_output * @@ -1826,7 +1847,20 @@ tracecmd_create_init_file_glob(const char *output_file, struct tracecmd_output *tracecmd_create_init_file(const char *output_file) { - return create_file(output_file, NULL, NULL, NULL, &all_event_list); + struct tracecmd_output *handle; + int fd; + + fd = open(output_file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + if (fd < 0) + return NULL; + handle = tracecmd_create_init_fd(fd); + if (!handle) { + close(fd); + unlink(output_file); + return NULL; + } + + return handle; } struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file, @@ -1849,11 +1883,19 @@ struct tracecmd_output *tracecmd_copy(struct tracecmd_input *ihandle, const char *file) { struct tracecmd_output *handle; + int fd; - handle = create_file(file, ihandle, NULL, NULL, &all_event_list); - if (!handle) + fd = open(file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + if (fd < 0) return NULL; + handle = tracecmd_output_allocate(fd); + if (!handle) + goto out_free; + if (tracecmd_output_set_from_input(handle, ihandle)) + goto out_free; + tracecmd_output_write_init(handle); + if (tracecmd_copy_headers(ihandle, handle->fd, 0, 0) < 0) goto out_free; From patchwork Fri Oct 8 04:13:20 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: 12544229 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 60907C433FE for ; Fri, 8 Oct 2021 04:13:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 453EE60F55 for ; Fri, 8 Oct 2021 04:13:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237373AbhJHEP3 (ORCPT ); Fri, 8 Oct 2021 00:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEP2 (ORCPT ); Fri, 8 Oct 2021 00:15:28 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D312C061570 for ; Thu, 7 Oct 2021 21:13:34 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id x7so30377004edd.6 for ; Thu, 07 Oct 2021 21:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cgA2EXLva61pHVu6N4nurZRVa3PGBo44xaD3Gjgteec=; b=powJ0GA5+NKUx+y5wGMAXoA0lZnsgLaJzRGske6mMPj22fTZUTaCi+2V1eSFgxJeAo jrZ+mAGsPrUR+QyJDjv8iBXnamoPG+hfLXfs8hbDjcjLtHtRKZjG8yxSnYpWuOhCZnGs LPFZLF46DYH+8/Ecs/16+rnCb9FfC8qL7ZFqGTsprIeXb49Jj4TA0Y1QmksV7t65mGxr ygtN9D6x3CdH2wl3Oe7Uyjt128kCDagFC3T6MwWLywcxXeuu9HkL0lsej2ujqB0pru5k xHFpaRtHCyRI1dGLqSGLScr9jAySr8OO9y9ZT/yEkN8JAEjnVA9/q6bwWapxszgHQnsD ZMYA== 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=cgA2EXLva61pHVu6N4nurZRVa3PGBo44xaD3Gjgteec=; b=dffzNLJVv8acsVyWpvqt4ntDrB4K4wxAMz0LlDLEvCPTgTgSg/xCjO2OtY6SwsRFYy 8EoiYQEEzjKlwOjZMLiYssqNFxE66D9y+24smg9J023yRMNaOhP5AxTbx09OwYH3C4/d Pm7z8M1QpCZb49h26iOPBVIRmQop1W78bQbjKVl0sy46853ryXwuQglk4x1oZXOcfbFJ LVveo8JPpj3rcj2hVvraa0qmcFJMAa9cNupHxj91craHpk4LOuS3e2r83gES2mkbi0y7 nJbkMf2WiOnVWRbHlkamJdJnjZ1wRP5tfxv4DhVLJiK3hL1jHffAFzShsZs+Qv9Kyvjm SZVQ== X-Gm-Message-State: AOAM530jORRsEOJvWYGg+zvTnFMTksSLOUxEd9l3VsQ7B/mn0735axcN o2iFQNpp9hY878G5+oF8vcT8WM0vHeRZCw== X-Google-Smtp-Source: ABdhPJy9osTsERL84H1n0z60dmuxZOBnAhKF6PKWME/GjijiYSMtzVOYo+m+MANVmYb2enSz3o0UGA== X-Received: by 2002:a50:dac4:: with SMTP id s4mr11290983edj.374.1633666412657; Thu, 07 Oct 2021 21:13:32 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:32 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 09/10] trace-cmd: Use the new flow when creating output handler Date: Fri, 8 Oct 2021 07:13:20 +0300 Message-Id: <20211008041321.973755-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The trace-cmd commands, that create a new output handler to a trace file, are converted to use the newly introduced trace-cmd APIs. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-record.c | 55 +++++++++++++++++++++++++++++++++++----- tracecmd/trace-restore.c | 32 +++++++++++++++++++++-- 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 1767a6c6..15e07cf0 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3689,6 +3689,25 @@ again: static void add_options(struct tracecmd_output *handle, struct common_record_context *ctx); +static struct tracecmd_output *create_net_output(struct common_record_context *ctx, + struct tracecmd_msg_handle *msg_handle) +{ + struct tracecmd_output *out; + + out = tracecmd_output_allocate(-1); + if (!out) + return NULL; + if (tracecmd_output_set_msg(out, msg_handle)) + goto error; + if (tracecmd_output_write_headers(out, listed_events)) + goto error; + + return out; +error: + tracecmd_output_close(out); + return NULL; +} + static struct tracecmd_msg_handle * setup_connection(struct buffer_instance *instance, struct common_record_context *ctx) { @@ -3700,7 +3719,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 = create_net_output(ctx, msg_handle); if (!network_handle) goto error; tracecmd_set_quiet(network_handle, quiet); @@ -3718,10 +3737,11 @@ 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_output_allocate(msg_handle->fd); if (!network_handle) goto error; + if (tracecmd_output_write_headers(network_handle, listed_events)) + goto error; tracecmd_set_quiet(network_handle, quiet); } @@ -4067,8 +4087,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 = create_net_output(ctx, instance->msg_handle); add_options(network_handle, ctx); tracecmd_write_cmdlines(network_handle); tracecmd_write_cpus(network_handle, instance->cpu_count); @@ -4437,6 +4456,30 @@ static void write_guest_file(struct buffer_instance *instance) free(temp_files); } +static struct tracecmd_output *create_output(struct common_record_context *ctx) +{ + struct tracecmd_output *out; + int fd; + + fd = open(ctx->output, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + if (fd < 0) + return NULL; + + out = tracecmd_output_allocate(fd); + if (!out) + goto error; + if (tracecmd_output_write_headers(out, listed_events)) + goto error; + return out; +error: + if (out) + tracecmd_output_close(out); + else + close(fd); + unlink(ctx->output); + return NULL; +} + static void record_data(struct common_record_context *ctx) { struct tracecmd_option **buffer_options; @@ -4491,7 +4534,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 = create_output(ctx); 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..8d2fcae8 100644 --- a/tracecmd/trace-restore.c +++ b/tracecmd/trace-restore.c @@ -22,6 +22,35 @@ #include "trace-local.h" +static struct tracecmd_output *create_output(const char *file, + const char *tracing_dir, const char *kallsyms) +{ + struct tracecmd_output *out; + int fd; + + fd = open(file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); + if (fd < 0) + return NULL; + + out = tracecmd_output_allocate(fd); + if (!out) + goto error; + if (tracing_dir && tracecmd_output_set_trace_dir(out, tracing_dir)) + goto error; + if (kallsyms && tracecmd_output_set_kallsyms(out, kallsyms)) + goto error; + if (tracecmd_output_write_headers(out, NULL)) + goto error; + return out; +error: + if (out) + tracecmd_output_close(out); + else + close(fd); + unlink(file); + return NULL; +} + void trace_restore (int argc, char **argv) { struct tracecmd_output *handle; @@ -90,8 +119,7 @@ void trace_restore (int argc, char **argv) usage(argv); } - handle = tracecmd_create_init_file_override(output, tracing_dir, - kallsyms); + handle = create_output(output, tracing_dir, kallsyms); if (!handle) die("Unabled to create output file %s", output); if (tracecmd_write_cmdlines(handle) < 0) From patchwork Fri Oct 8 04:13:21 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: 12544231 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 862DBC433EF for ; Fri, 8 Oct 2021 04:13:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67D4560F6E for ; Fri, 8 Oct 2021 04:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237403AbhJHEPa (ORCPT ); Fri, 8 Oct 2021 00:15:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbhJHEP3 (ORCPT ); Fri, 8 Oct 2021 00:15:29 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6051C061570 for ; Thu, 7 Oct 2021 21:13:34 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id g10so30323827edj.1 for ; Thu, 07 Oct 2021 21:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CbYlw/3BiN/+et7fiQViKHmUzdeGz+I8l6jpMvYbiy4=; b=mcbrJq5JMm87sBjNLvBvHNXsdepjzaOlCSRQihvRsLYgSgzlv0G5T0K62kASR03NPu UPQaPJWPH/jxsDTc11JwqoBgDBxkkgOpWUD0PY8Qyz05Zy54zV/d7F1t9ScEGo+lN7G9 GrrnHYBtl1plAsAFN1s3n/yqCQHxNdOt31e5JtKqhlgbKBK3t/sP5yXBxQIOywqW7C+G nuaqRGBlUuOUI+3RuGzuofVnL1nSBlskfNOkm5fJOc6fZ1tOEbNYEYpervUV0dlI39Ym bAyYjHA9SqoX/RKL3Xoc32rwmMlMp/Rqae162YosyeBD3ouq0QisNq28V9DLTJApuI6O p+0g== 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=CbYlw/3BiN/+et7fiQViKHmUzdeGz+I8l6jpMvYbiy4=; b=luwif87TiGvsD+DRDEuZHydPnOk0llsw7EJAGogNZK6xmqmZSueit2vWQjeoQD+kPC Ahvp6TYq4hBWUMXb/Uz3JWDdHr+9oaPP4uR56AoVBLQrtE+4w5P789uVU9W97EJoLALm qdrMaVP3O1gqI6zR8DeY8zD4yKms0wnpPI6+ixwetU5tDvgLdEzMUT7m3pFSyWVkbE5C 48JDVxN+GuNKD+8iPAFcuOGXWTASrFuL3biHEDExvFV50hPNx4QLUlRzPZDPOO0y+CwO eXxar3opkqLd14EKfGBl9FdR5xxGa/22g1nX/8I33hpQ/hJ+dZ0N+7oUlXSy5bF294G3 WPww== X-Gm-Message-State: AOAM5328sdw3jYBBQh46iV7Odx4mWO6Gf22oOJum9OFsLRPGoE806UUn MKsbtZLUAPZuB+r/cmwjj7v/DrHl7gS4Rw== X-Google-Smtp-Source: ABdhPJx2IDAR7KpXtz/sY2d65iCRQm1VlvVAXXlu+fEMQidXLhWCbghLIDJWRPTFNYfKoI2m43icsw== X-Received: by 2002:a17:907:98f9:: with SMTP id ke25mr1230838ejc.381.1633666413456; Thu, 07 Oct 2021 21:13:33 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id lb12sm465740ejc.28.2021.10.07.21.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 21:13:33 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 10/10] trace-cmd library: Remove deprecated APIs for creating an output handler Date: Fri, 8 Oct 2021 07:13:21 +0300 Message-Id: <20211008041321.973755-11-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211008041321.973755-1-tz.stoyanov@gmail.com> References: <20211008041321.973755-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org With the introduction of the new output handler creation flow, some of the old APIs are not used any more. Removed unused APIs: tracecmd_create_init_file_glob() tracecmd_create_init_fd_glob() tracecmd_create_init_fd_msg() tracecmd_create_init_file_override() Signed-off-by: Tzvetomir Stoyanov (VMware) --- .../include/private/trace-cmd-private.h | 12 +- lib/trace-cmd/trace-output.c | 165 ------------------ 2 files changed, 1 insertion(+), 176 deletions(-) diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h index 086e6906..167f3804 100644 --- a/lib/trace-cmd/include/private/trace-cmd-private.h +++ b/lib/trace-cmd/include/private/trace-cmd-private.h @@ -280,19 +280,9 @@ int tracecmd_output_write_headers(struct tracecmd_output *handler, struct tracecmd_event_list *list); struct tracecmd_output *tracecmd_create_file_latency(const char *output_file, int cpus); -struct tracecmd_output * -tracecmd_create_init_file_glob(const char *output_file, - struct tracecmd_event_list *list); struct tracecmd_output *tracecmd_create_init_fd(int fd); -struct tracecmd_output * -tracecmd_create_init_fd_glob(int fd, struct tracecmd_event_list *list); -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_output *tracecmd_create_init_file_override(const char *output_file, - const char *tracing_dir, - const char *kallsyms); 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 9ea85b1c..27f296dd 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -31,11 +31,6 @@ typedef unsigned long long tsize_t; typedef long long stsize_t; -static struct tracecmd_event_list all_event_list = { - .next = NULL, - .glob = "all" -}; - struct tracecmd_option { unsigned short id; int size; @@ -1119,139 +1114,6 @@ int tracecmd_output_write_headers(struct tracecmd_output *handler, return 0; } -static int select_file_version(struct tracecmd_output *handle, - struct tracecmd_input *ihandle) -{ - if (ihandle) - handle->file_version = tracecmd_get_in_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, - const char *kallsyms, - struct tracecmd_event_list *list, - struct tracecmd_msg_handle *msg_handle) -{ - struct tracecmd_output *handle; - struct tep_handle *pevent; - char buf[BUFSIZ]; - int endian4; - - handle = malloc(sizeof(*handle)); - if (!handle) - return NULL; - memset(handle, 0, sizeof(*handle)); - - list_head_init(&handle->options); - - handle->fd = fd; - if (tracing_dir) { - handle->tracing_dir = strdup(tracing_dir); - if (!handle->tracing_dir) - goto out_free; - } - - handle->msg_handle = msg_handle; - - if (select_file_version(handle, ihandle)) - goto out_free; - - buf[0] = 23; - buf[1] = 8; - buf[2] = 68; - memcpy(buf + 3, "tracing", 7); - - if (do_write_check(handle, buf, 10)) - goto out_free; - - sprintf(buf, "%lu", handle->file_version); - if (do_write_check(handle, buf, strlen(buf) + 1)) - goto out_free; - - /* get endian and page size */ - if (ihandle) { - pevent = tracecmd_get_tep(ihandle); - /* Use the pevent of the ihandle for later writes */ - handle->pevent = tracecmd_get_tep(ihandle); - tep_ref(pevent); - if (tep_is_file_bigendian(pevent)) - buf[0] = 1; - else - buf[0] = 0; - handle->page_size = tracecmd_page_size(ihandle); - } else { - if (tracecmd_host_bigendian()) - buf[0] = 1; - else - buf[0] = 0; - handle->page_size = getpagesize(); - } - - if (do_write_check(handle, buf, 1)) - goto out_free; - - /* save size of long (this may not be what the kernel is) */ - buf[0] = sizeof(long); - if (do_write_check(handle, buf, 1)) - goto out_free; - - endian4 = convert_endian_4(handle, handle->page_size); - if (do_write_check(handle, &endian4, 4)) - goto out_free; - handle->file_state = TRACECMD_FILE_INIT; - - if (ihandle) - return handle; - - if (read_header_files(handle)) - goto out_free; - - if (read_ftrace_files(handle)) - goto out_free; - - if (read_event_files(handle, list)) - goto out_free; - - if (read_proc_kallsyms(handle)) - goto out_free; - - if (read_ftrace_printk(handle)) - goto out_free; - - return handle; - - out_free: - tracecmd_output_close(handle); - return NULL; -} - -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_output *handle; - int fd; - - fd = open(output_file, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, 0644); - if (fd < 0) - return NULL; - - handle = create_file_fd(fd, ihandle, tracing_dir, kallsyms, list, NULL); - if (!handle) { - close(fd); - unlink(output_file); - } - - return handle; -} - /** * tracecmd_add_option_v - add options to the file * @handle: the output file handle name @@ -1825,26 +1687,6 @@ error: return NULL; } -struct tracecmd_output * -tracecmd_create_init_fd_msg(struct tracecmd_msg_handle *msg_handle, - struct tracecmd_event_list *list) -{ - return create_file_fd(msg_handle->fd, NULL, NULL, NULL, list, msg_handle); -} - -struct tracecmd_output * -tracecmd_create_init_fd_glob(int fd, struct tracecmd_event_list *list) -{ - return create_file_fd(fd, NULL, NULL, NULL, list, NULL); -} - -struct tracecmd_output * -tracecmd_create_init_file_glob(const char *output_file, - struct tracecmd_event_list *list) -{ - return create_file(output_file, NULL, NULL, NULL, list); -} - struct tracecmd_output *tracecmd_create_init_file(const char *output_file) { struct tracecmd_output *handle; @@ -1863,13 +1705,6 @@ struct tracecmd_output *tracecmd_create_init_file(const char *output_file) return handle; } -struct tracecmd_output *tracecmd_create_init_file_override(const char *output_file, - const char *tracing_dir, - const char *kallsyms) -{ - return create_file(output_file, NULL, tracing_dir, kallsyms, &all_event_list); -} - /** * tracecmd_copy - copy the headers of one trace.dat file for another * @ihandle: input handle of the trace.dat file to copy