From patchwork Thu Nov 11 15:03: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: 12614991 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 06FE3C433F5 for ; Thu, 11 Nov 2021 15:03:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC47961284 for ; Thu, 11 Nov 2021 15:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232823AbhKKPGR (ORCPT ); Thu, 11 Nov 2021 10:06:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233828AbhKKPGP (ORCPT ); Thu, 11 Nov 2021 10:06:15 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E3E8C061766 for ; Thu, 11 Nov 2021 07:03:26 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id x15so25408399edv.1 for ; Thu, 11 Nov 2021 07:03:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GE/ZhNuVOFMt61b2oYmfytP7w1fdYjceKUJeGml5guE=; b=jScqC7YR/nPPz8jNDyKmgVyzItcCpbvBCgwP9TNolYzn+IpQm3crLpIkpvetlWlb5c ruQ2nncwFnd5svXiVnqt7ZVM36AFsLPzogHIGMByG2u4z/CzocN9Ov7ydS62/pVeqDpB FhiZemHeui5PMAGP/vvCe4sCJ4LfeE2P+I6GuXN0VvTEgNvVinHyi3G5YKgt60nw5THQ rB2OXmfKhhHsiBAxf2JhW6udpjJRJVp9fH0XUbouGZ8MWQrB2/yns/kSjBN6hU47dqXQ Fq1Dl84duaOy4d3VHk8GaZO8Y7BcpXeLFTIokuG9yRsiHhFlGJFl4fyVrJtW+34KxOPZ NDyw== 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=GE/ZhNuVOFMt61b2oYmfytP7w1fdYjceKUJeGml5guE=; b=EcgnwX+XpWVILNLh9VMFOMJm0hmqWd4RDRq2AVPnIFtbQ1ySRpjRA/eZHRAt4UYptn lmoaUYv4lDPpwNfMaZxcOVK+xN2hry7kcEf3sIglZ2XsPg4gMv+ciX0MVgIQD7asQSrp nTGu2YleYz1vQ3jAAyp2o8uGOb1hfTegTta/B8esHiAPWG5bUhlHsJH2Oh9o5d9hmdBQ 50jRFOlYix0F4gqk/sNwWKDYg47y8QvmBF1G0CMAy1I0Em1jTCx949yG0gjvg8dPicLB FU9tBBoV9VfEhUiu/C1m0++fRH2UMEcbi/HBEqiV5PUCklI9D5DZLmr279KXOM3Fxbzn cplA== X-Gm-Message-State: AOAM531xEr8/AmiFQnjiMbbametHLZrYIU9NcFRIi/N/45/PO48FBwFs E8ndAO0gs9CEW5VP5YIhgOE= X-Google-Smtp-Source: ABdhPJwmWIoH3sAS/hkOtfxl371u0a4yOEoBbmsslHW1GUtb2JvoPcoInu81EPzDMWgqH2ZHQKTfvQ== X-Received: by 2002:a17:907:7785:: with SMTP id ky5mr9842586ejc.247.1636643004131; Thu, 11 Nov 2021 07:03:24 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d13sm1656128edv.29.2021.11.11.07.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:03:23 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 01/10] trace-cmd library: New API for allocating an output handler Date: Thu, 11 Nov 2021 17:03:12 +0200 Message-Id: <20211111150321.85979-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111150321.85979-1-tz.stoyanov@gmail.com> References: <20211111150321.85979-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 f40babef..bed96657 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 Thu Nov 11 15:03: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: 12614993 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 342C2C433FE for ; Thu, 11 Nov 2021 15:03:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B4A16152A for ; Thu, 11 Nov 2021 15:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233828AbhKKPGR (ORCPT ); Thu, 11 Nov 2021 10:06:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233847AbhKKPGP (ORCPT ); Thu, 11 Nov 2021 10:06:15 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CF44C061767 for ; Thu, 11 Nov 2021 07:03:26 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id v11so25370906edc.9 for ; Thu, 11 Nov 2021 07:03:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7c7gV8CFoiWVKIvqBxrEnbh/EH4bh0MmnyVB/FyIe80=; b=fgsQn9/kCDSfyowMAGcFeAatMKaKJKcI2aEh/zXSCeXEzzC/FlSRLr0kNI4+FvhXPs 6dcIOMAOGaS7nELpiXNPIqGsSIvB6ah1sCPZQGTj+7hBIqzORJ3MdQWNzv9c6gY1dJpw NrWScuMfNR09BJ5MGAyuuZhfDgOd14QP1X5+Ocd31Sxi9bZkJP58CV1rTRvHekJuU9PU Qmq/ylRC0rj76hYjFw4w1YURnrgN3FKB1BONXtdt673dSmFe5m4daTYohJ/VDFU37s6F yarm1IX/jEOehJJnvZjVNlyfrryTuR3hyYLbBEa4WpKdd6Q8ruBKmGU1aqGxpy3b4h6x dmzw== 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=7c7gV8CFoiWVKIvqBxrEnbh/EH4bh0MmnyVB/FyIe80=; b=F9dP468tGHUNAwnLZgFb+j8CDyA0MUdiYNcedAeA/24c5mpANS84XeHtjxH1bDwLB0 TfN/blBfB7L6Fqqlkz01yBeoRSjnSsrtchsqXnHAyalql3dHbOKijUcky1E8cC6J1MHb Rbt+LZT1TOT7UyWW2UcJGIpVxFkZdjw6oWtil5lDQjz7HtcPEhBWx+Rey3PAUkqmT3UD uPJXbLP3Dhob/6uppqbWGqUHthxnq2q4JC6hbUKBHb1DBS8tlkrosAD7KCOyEra7PpLI Jh4kTWQUl5sK59LQleLmsXrl95AEiD3Kp0VkQGgZbU6/W+7QvkWA+7/jp6WV2MqwImbd iwDA== X-Gm-Message-State: AOAM530wRmauhSkG3geDshatbjpNVelsYYaaMYV8HOTFRkXzxEQhDQs/ 2V6ONUf3AHaEPvJyTUflYAs= X-Google-Smtp-Source: ABdhPJzDAreQyeaFxZN6bUTcfDZpBU3e8mMAMZWmoixzl4DxbG9VgEuBYxfWEVeumSf2pru+k6pABQ== X-Received: by 2002:a17:907:948a:: with SMTP id dm10mr9982243ejc.455.1636643004960; Thu, 11 Nov 2021 07:03:24 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d13sm1656128edv.29.2021.11.11.07.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:03:24 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 02/10] trace-cmd library: New API for setting a message context to an output handler Date: Thu, 11 Nov 2021 17:03:13 +0200 Message-Id: <20211111150321.85979-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111150321.85979-1-tz.stoyanov@gmail.com> References: <20211111150321.85979-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 bed96657..49c8c138 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 Thu Nov 11 15:03: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: 12614995 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 B8F00C433EF for ; Thu, 11 Nov 2021 15:03:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A260761284 for ; Thu, 11 Nov 2021 15:03:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233075AbhKKPGS (ORCPT ); Thu, 11 Nov 2021 10:06:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233833AbhKKPGR (ORCPT ); Thu, 11 Nov 2021 10:06:17 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E110C061766 for ; Thu, 11 Nov 2021 07:03:28 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id m14so25638058edd.0 for ; Thu, 11 Nov 2021 07:03:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6bW3IZBFCvSsUaHSwJ6OSA7Q0lEX3Nls6B+DugLLbvQ=; b=fjn3LYI8Nc/eC0yZavEH3+2VyZONIwJNbLzXhB1oJiHi4Ssk1SwIewTDYvSzNvTfsr 3jKj/bSYBeKzsJmSck2YKvmEi/pFDUX1YBQo1cUNPgU55lgh1QwFs8KD+zyNK8Oh/SKB fP35hqfazdgaKjJXdQDhqkKOByeGMthk4RDQyQn/AHj5We1iJAEY8F8Uj9jdiOGkXvrO 7MDvyOpJrFQTv7+BW5BPhgN6UHfrweNXc+0CTpYcXJ4ZoMTX367TI+2wYoRU0clImHut mq29/hB/RE+izOk7DHTPDTamPpmK2yjO3alLEIUeZO0ZDm+Q/cBlUFxOK4P5VbKoReEc 8jOA== 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=6bW3IZBFCvSsUaHSwJ6OSA7Q0lEX3Nls6B+DugLLbvQ=; b=kMbD0nJoY62UyKnfT3Jt747W0ug8Lisi+wifFhqS58f3JYihH2dcqLCsmpnC71glrj L2fqfMO+giaBRpMYTDk3zqMz5V1mkFCRcbXOA5vzguaqabhLKNLX/eBAu1FD4mGSry12 5Q/+C3BYpbcZ7Wf1PUK0/WF5CmUQnjXFbRb+cPR+Z6LCwvLh7hLj9GGVuZrRm9LgCGCj if+copQEPytMJ+qZwbUFv26oTRVJKHnqW2UR0XxecsX2GVuzVRVNCopLxXviRnM19let tZEiTg0UZ/8XRPFgl5bmcY3+qsYFiSSfiAvoCe8WJljUIdifKOhdri0fIx8iIMqQ9UuS JFEA== X-Gm-Message-State: AOAM531ZwmMwOoCiAFK43o+ZSnHUVxEyi2tdlPQrCRlqYYm7xhIqsdyt yq0/sIUi90cZW1Crd3H46kY= X-Google-Smtp-Source: ABdhPJxIqfQKkzz/zM83GfwHBVOC9VXnRawowR5XEkteptXuD6LPu4qIVUwXDde+nu2Wszi5BDtDWw== X-Received: by 2002:a17:907:3e11:: with SMTP id hp17mr10146241ejc.243.1636643005978; Thu, 11 Nov 2021 07:03:25 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d13sm1656128edv.29.2021.11.11.07.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:03:25 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 03/10] trace-cmd library: New API for setting a custom trace directory to an output handler Date: Thu, 11 Nov 2021 17:03:14 +0200 Message-Id: <20211111150321.85979-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211111150321.85979-1-tz.stoyanov@gmail.com> References: <20211111150321.85979-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 49c8c138..eb173a39 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 Thu Nov 11 15:06:58 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: 12615001 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 AC6BCC433EF for ; Thu, 11 Nov 2021 15:07:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9652A61284 for ; Thu, 11 Nov 2021 15:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233798AbhKKPJv (ORCPT ); Thu, 11 Nov 2021 10:09:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233817AbhKKPJu (ORCPT ); Thu, 11 Nov 2021 10:09:50 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E60D6C061766 for ; Thu, 11 Nov 2021 07:07:00 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id f8so25584951edy.4 for ; Thu, 11 Nov 2021 07:07:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=t2RTbigUu8hgnrUlUjYIspTrn/p5f4JzJAqGjWL0i9M=; b=atTBCozxyaHN6zaF0vaPI5WIewjaCBWyOAL9yp/YVbh4hGcn+bneWCIHlmisTgDoI/ 8GRFqJxfqL2iVdrEF0zU+hIYheyzn/Wmr1OSKU+BMWtM5sXqh5C+c7P2bPo0RoApGj54 F3Txc45EmpmA99qN7DlDP0MY/UboOKtxOwfBW/UUUTpRV0leXfmpTZGQXjPkQkBGOyGo ZpwlKth4EWg9MpcSMfDqgYPrHUOmUJK4yKTd51SFI1nsSTAhIZtiQ3JlxgiDJHcN8dpz spkurYHnnQ9mAxMpWN51K+R4wPRtSkyimAMDcPk8M5AYj4ipM2MMEygyhWNaA+DdulAw 0aRw== 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:mime-version :content-transfer-encoding; bh=t2RTbigUu8hgnrUlUjYIspTrn/p5f4JzJAqGjWL0i9M=; b=mQsH4LoWJuxSJVzAukU0ttBMNLKIpNU60ThVfiGDEpb3nphb92ido3nNq2mfXD9aBD JXGS5nt/C/EdJB3Jct/w1kKkSS9ld52zPWT14JDrHLHFjwKLGB1RSYtOEh83nv1VftxV Eogfr9I+/8KlNBeZUCmM9SGVukCSfGLWbwlI7CwV3+yN7VUNRyOfkOUyZ3vpExr4Qn4v ed+Pk5Ij+grM+t9nDmTuEWpwkQhKB73hOpI2Wmaabq1ZjXik18nL5vukvV1jnXer1Lll Be9nCJcNUuonQy5Mux0JmlMyfBfRwkVGpz3G9aTTE4fZtj70L6d4Vn9LIdm22rErV5Ve b0vg== X-Gm-Message-State: AOAM532TC0tisxxxKyAJA4ScpTkY1x5rgTxrkzbEyEWPVXHq9a6FWy8i OaexVjZCdEkBunZbpJGG1lTzg4aURE/5wA== X-Google-Smtp-Source: ABdhPJzIfXsPrt7UtoajnICxRZHCDjPFD3l4pxN0pyu2xnZcqn7/MrccT3iwAT44naUyAyn31pv8Sw== X-Received: by 2002:a05:6402:26ce:: with SMTP id x14mr10726091edd.326.1636643219498; Thu, 11 Nov 2021 07:06:59 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id h7sm1665678edt.37.2021.11.11.07.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:06:59 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 04/10] trace-cmd library: New API for setting a custom kallsyms to an output handler Date: Thu, 11 Nov 2021 17:06:58 +0200 Message-Id: <20211111150658.86228-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 eb173a39..23e86107 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 Thu Nov 11 15:07:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12615003 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 8DC8DC433EF for ; Thu, 11 Nov 2021 15:07:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65D3560524 for ; Thu, 11 Nov 2021 15:07:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbhKKPJ5 (ORCPT ); Thu, 11 Nov 2021 10:09:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233801AbhKKPJ5 (ORCPT ); Thu, 11 Nov 2021 10:09:57 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2684DC061766 for ; Thu, 11 Nov 2021 07:07:08 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id f4so25288376edx.12 for ; Thu, 11 Nov 2021 07:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZLSYG5xkYhVxtFiECSo1k52prJHONQdfcXmfEM5nkWc=; b=JCA5Vnrx1lKIqrVHIj7ftJ7urKxWXZ/8KqNThswwfHXH7sVoCaFMWRw4Oker63PNw0 rdDE47bQ9MikW+ogtVPgTqXMKTzo7RuQajDKDq274NaPB5pLJkVr/5EPwcEq4Ui/4/CU ZRU2Z9tLYpprweoMrQvnESJfxYwmT4zRz3TCjS7z5TMCQvokguffwF3/irfOtcCTjHbG /VJaS/y5tu9FlW04lf2THheh1H8vaN1oWc+zVJgHJX4u3J71SkXFM7JIcaNiATU1p2uA r5e6t7DjJJY7DPLc71Yy2kFDVTlCFWc+6cUCgAHaboDjaD8bRmilXV3m/W2lSw1VBZSw C23Q== 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:mime-version :content-transfer-encoding; bh=ZLSYG5xkYhVxtFiECSo1k52prJHONQdfcXmfEM5nkWc=; b=pJdbSgrZ0Axkk2kdK85D1sofCQ0R3cyXtG3B4x0zmKj39w8iDb0AM+dYfOa4/Vrq1P 5m5gCGO8ue2VpmiJfDoiNl3PBI97n1MBhE1F4fp3P31mYE4hz02VCM6MpV8zD3vYX3O5 Pdtqj7vRoba+mJ3bpZf9u9nYVcaar/ZWYs/IEbwSOuAnBFuGROOsVEt0h24PhPMacZwB OsLho3EBc1TB0qgZKHQgJEvVW8+sPryeLc+RlyO2emjcRnP5a3XHIbCCXTOASuyCjk5e akPD0RytXdLQgWvRR7chSpnRiVc+aiViS6t58gcMNyJ62mQ5ochQppvOhNWn9jY8Hpf2 EXlg== X-Gm-Message-State: AOAM531gQ1kRNn/edLYEwhhc7Y0KJP5PkPEWQEuxH+f8nRgF1/GyiCm7 rZgEHwFo8saZ7tn6rM04DQf8F1om1Gvswg== X-Google-Smtp-Source: ABdhPJzCVNZqOT7bBXRzwVN3EdYERk+azn7u9HxjyA6suhO7yUx90IQyVFi0lGWdgNbJ2qsv6E+0SA== X-Received: by 2002:a17:907:d90:: with SMTP id go16mr10008456ejc.137.1636643226724; Thu, 11 Nov 2021 07:07:06 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id hq33sm1695310ejc.119.2021.11.11.07.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:07:06 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 05/10] trace-cmd library: New API to inherit parameters from an existing trace file Date: Thu, 11 Nov 2021 17:07:05 +0200 Message-Id: <20211111150705.86248-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 23e86107..41876195 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 Thu Nov 11 15:07:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12615005 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 B1F9CC433EF for ; Thu, 11 Nov 2021 15:07:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91839610A2 for ; Thu, 11 Nov 2021 15:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233809AbhKKPKF (ORCPT ); Thu, 11 Nov 2021 10:10:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233801AbhKKPKF (ORCPT ); Thu, 11 Nov 2021 10:10:05 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A3ACC061766 for ; Thu, 11 Nov 2021 07:07:16 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id x15so25456424edv.1 for ; Thu, 11 Nov 2021 07:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tvq6a/OQ56vcQvBgTJWgo8iKYz9h21O+PziFclMbNMQ=; b=TyeaWEp58cmd/309U/xulHahqcpRHQzmKOXioYKuHO1H/mYmhA92uHv18M6V3q1jqo DF0XsxQ3GpaGGpQI5spa6AFE7A/SEQT1YJlVUCIfcTCeP9U7BdNXSCGA3y0S5aewsTyN nmB+skQbVNcTeQGMHU+JzugjAXV1XrT2KpNKktSIDE98CEIyTIlQLLbtuG/42LckIe8G T0RFASrsKNqmUvn2bCeRv+PdlIbelmrBp6wRiaCD/JK3c3ctlgAKE/MUAY/rpiibEAbH taAV5RJ28tdizKwer/dMyPBX2GCAlfVIsJHNslTFYHNhy4zKz7SAhfBsJND0ADXgsI3F zEIw== 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:mime-version :content-transfer-encoding; bh=tvq6a/OQ56vcQvBgTJWgo8iKYz9h21O+PziFclMbNMQ=; b=6DgT5dnTf34RwxWlHoqIMxhqX7xxLR/ImfEDtlM+8DiDnGTlIL3O5jBqODiaGD8/YA 3F0Ig2C6pR1ePP+M1QJ3yJEYO29JRJrbuJZo/N43wTSm0ZVkp501FrErrWf3h49JeUM+ nV+8VzWp84gtlYzKLdIuyM/dogHEi6jcLHK1BHQS+sVicBy1XffHMhVFzozISkRVl6mM yo1ymRTgTgIM1eU8/uXQVUBkuZAjxS6Xn4uksEVlFSv55xRxEAzTXkg+YstSnMw8DdX5 MVySVpk76UVBhmsYhzq1HKU/sHuS/OYn3iA7rvUrCo5pkNnHMzAZlC2m0LQmI4TRgPOh EFlQ== X-Gm-Message-State: AOAM533SdrogVRQ2fHS8CQiCMGYeG0cC10bTrvCMZkXYobcFcl1dMNJR yM5RbyqW3iPNhyux55o/iIJKS7Jn0aq8Ow== X-Google-Smtp-Source: ABdhPJx1In8i+5xFduCERXQGElroOMNZ9Tgpc+Nrsxd+qUJm/UMUIR7vT55ExYMeV2dDbei+Giaqqw== X-Received: by 2002:a17:907:d94:: with SMTP id go20mr10198269ejc.78.1636643233386; Thu, 11 Nov 2021 07:07:13 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id e12sm1510598ejs.86.2021.11.11.07.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:07:12 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 06/10] trace-cmd library: New API tracecmd_output_write_init Date: Thu, 11 Nov 2021 17:07:11 +0200 Message-Id: <20211111150711.86266-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 41876195..2a5ce996 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 Thu Nov 11 15:07: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: 12615007 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 F3C1DC433F5 for ; Thu, 11 Nov 2021 15:07:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA578610A2 for ; Thu, 11 Nov 2021 15:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233818AbhKKPKL (ORCPT ); Thu, 11 Nov 2021 10:10:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233801AbhKKPKK (ORCPT ); Thu, 11 Nov 2021 10:10:10 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04867C061766 for ; Thu, 11 Nov 2021 07:07:21 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id j21so25165377edt.11 for ; Thu, 11 Nov 2021 07:07:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JZIz9Le2ldkZezE594obPY9U9Co86sAzYvTBxXbFeH8=; b=ggkQPtQ1IG8yTHiVE3olRA6I4dXpNfW7BzIao5q1v0+ouWOFZS+3COtpfhjkCETzhb BoomVpib298u/vxSh46RG0Mdf/CbjJ+OQn0qefJSSlRcPbdJcnsM9f8MLQrnkahqI1dt e+IMQw3+2g5a9vl6r0l8rGc1P8VlgGdecMzOgwqRFFsSGzcEggkyK85L5NXY6zTJwSSg R9rhIdmWVJpC9ef6e+KqQ81cA7M/M8zRfxlvqCOV9/4ydvKOrF2B5/h+ncr2tXdMYwFW PuCFdSRyDPx8oglnCz5x7s277G3Duxu5JWnDnhxhC1f7Qr1a/a/zGv+fz0rXToHGi6l0 f+jA== 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:mime-version :content-transfer-encoding; bh=JZIz9Le2ldkZezE594obPY9U9Co86sAzYvTBxXbFeH8=; b=pejJD3F/RbS85fbXbdGVSCq8mKD1m8VeFrEUeGZLmTOrpfCb5vLlOMEUy97CS1zjsQ sCQOV88tfmfJAVRRxVMSC7I7olQzxzyaT1nRBE7Bd51+T1FJxfCOsB22uT+2+sWRZ44K ZNuu416TyL0I/+PeRxOkKPkjwPDd4lIxoomN5W0HdIAdDfbyY413oGGlvq4kKZRdTCl5 9PKpU0q/47l5NzxMrYwnQrfJ658FRyPilriZgUw3g6HIfTqZpWUL2tH30tpe/P6AOo7x ori+BsLESLNBk1LOFpfnMusYWNH9n1irvwOC+QsyQimjNb0hUlPlJyI8JaDUlrPlCQW5 g4+g== X-Gm-Message-State: AOAM533ZQHkMUTueTsTIswMG7OPcP13eN9cg7qf95dD/SEtsJNCN8JXI gzVooxfbskF0hS7xMvwItt8= X-Google-Smtp-Source: ABdhPJxwWZoYvjb9nyvnygQDodyspRuk+c5HvlFYcR+K7RHq4jGMGP+5S28qSZrZb6sKiFfLlK8HSg== X-Received: by 2002:a50:da0a:: with SMTP id z10mr10547028edj.298.1636643239601; Thu, 11 Nov 2021 07:07:19 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id d18sm963695edj.23.2021.11.11.07.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:07:19 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 07/10] trace-cmd library: New API to write headers of a trace file Date: Thu, 11 Nov 2021 17:07:18 +0200 Message-Id: <20211111150718.86285-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 2a5ce996..f148d520 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 Thu Nov 11 15:07:24 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: 12615009 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 4C6ABC433EF for ; Thu, 11 Nov 2021 15:07:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 332F261058 for ; Thu, 11 Nov 2021 15:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233801AbhKKPKR (ORCPT ); Thu, 11 Nov 2021 10:10:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233799AbhKKPKQ (ORCPT ); Thu, 11 Nov 2021 10:10:16 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F122C061766 for ; Thu, 11 Nov 2021 07:07:27 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id g14so25425968edz.2 for ; Thu, 11 Nov 2021 07:07:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=TU1BhuiDlEROr6TrgpWz7vlQmFpSa5IVdhHp5EhPeXQ=; b=hJPKImFXEZN3JJnt6XQAEqfE/HCyX7qOdbS3Wl9jh2eP+7yfo3/tiG3VdR2Ri8/pln 0D3x9gGMODm2otDJvCxf3RNbSfPnBhxI7td4qHuVGxLFz0biy6YL4q4lcbcmIkAEBNqt KaANEhDFq8grtc4E82AMXPydQDVCwpS0qclG5fAWQyZovpzrjm5LvN8VznSONKIdQrZA IYNnuc9DOdklLH0nhXJGxcGW3ZDGzbBJJWgzosOpIoLVDg4l71W5S5navWnvMatjhT6v TiYLWOzD/OLwJdJcjlvi9qSdYDC5Y5Dmivxz6Df8CzNVwGTG31X7OJvYTu1SmfR8YQbV bwIQ== 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:mime-version :content-transfer-encoding; bh=TU1BhuiDlEROr6TrgpWz7vlQmFpSa5IVdhHp5EhPeXQ=; b=jT6AJvBzeISl7gWeiNWRHCV2NQWwdbrLlqUolF0/D462iZZ+Ayz1zcW5u5pcx4SwIT Rt2QEh43IrDJDNKAVJqPXeRJZtOfZERdT5oNhb3e/PeKJd4S7WYzqseIt2vQ78jw1lu7 oTjFmB5F+//wJjKbDjzfD3xMUEaULsKa5l60hDV+iO+s/FmSDGXF77gdNsJB6YiTAa/2 9+FIe064/8UXoZwNCxDKfUrPzsRHFMs9C3O2bazXfcXewAGB1gQ7NzUAl14r6fbRl4Cw AIW/gMEimiwiU4iuFaIrv9SMlz8iGEQlj34FWDW3EQ4M4peqJ2KNG0Za7bDTCLwZjtmM VgRA== X-Gm-Message-State: AOAM531kR5BJ8Zh9vFURIq6s9Zvp2lsvOnQB0LxrV3P4L61tQXkjMRbs vbA2B+kONEvmnyaYcLx68Hwei6U+0ciA0Q== X-Google-Smtp-Source: ABdhPJykmuBZ1ETvD21/QnhYayzRSvRd8HGyzYEBoG/4zRNHG2k81xvW2C2HdoqpVqQ4bgwx/vmpjQ== X-Received: by 2002:a17:906:390:: with SMTP id b16mr10180568eja.522.1636643245870; Thu, 11 Nov 2021 07:07:25 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id k16sm497422edq.77.2021.11.11.07.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:07:25 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 08/10] trace-cmd library: Use the new flow when creating output handler Date: Thu, 11 Nov 2021 17:07:24 +0200 Message-Id: <20211111150724.86304-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 Thu Nov 11 15:07:30 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: 12615011 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 CAEE3C433F5 for ; Thu, 11 Nov 2021 15:07:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3176610A0 for ; Thu, 11 Nov 2021 15:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232126AbhKKPKX (ORCPT ); Thu, 11 Nov 2021 10:10:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233820AbhKKPKX (ORCPT ); Thu, 11 Nov 2021 10:10:23 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC538C061766 for ; Thu, 11 Nov 2021 07:07:33 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id b15so25172592edd.7 for ; Thu, 11 Nov 2021 07:07:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Tba+Yb5RYVhhCDCM3O4kwPlU8dN/zlm3I15f52ZJxvI=; b=CLo84iQIvMBSAv5LtX5Q+sg9iTk2NGkCudtoNoMnnAbdUSaHCyi0Q69LJWKSwAwl7h lZvPZu/FM70KzWC+4R93frXiR/BoFsnrLAPq1qgEJt5wXOLn+eBxcI3+qQbB8UB2AZ+X hlwDPbNS2MifX2jMcNbgy9P8Fe6pb0cVTIbGhTvNQ6TpuMOg4hSJkoE/pnP1HqXVwsmb xLrVBl481QJ+yX15hQktmLI8ZHoJN1ji2smT7/IjhSXOBb9e7sf9v4GxdsmcSeYj0icP ABNGhNCdAX6OExjy5P4qd/b71BaVhSJEEPBejRe+IwJwCUlblQdDmHrzN9rFSdQkvZxt i0Vw== 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:mime-version :content-transfer-encoding; bh=Tba+Yb5RYVhhCDCM3O4kwPlU8dN/zlm3I15f52ZJxvI=; b=kiKBjsPRy7lWlgv3dWnbwm/cs5H1qh60M8N5X2ktqb/GLfyQsjuKRm1y/+BtUfKVUo 12E0scxNWg5nuyhz8AMVTe4LlZbMRuQ+i5DAdmXzM93g2gz1LV5llzQKOfK0mL72KasG OgPGEHYebNPvprfX4k6y6fArApgDDZALIA0rL4JbimDmVb/G2kSSxEayySlWtmw76OCn hXUBIWB5eO06twPebBbF86NWba87lSfdOAovjnJoXJY727tjnNUmO2scre2gMm/D8Bl3 jOW4D+y5K0tEoQTAPp/HAf7IUEtawpnXIGSjSPp8nDf1hFL9DKWqnoMLmU6PG1BcRwW9 cWkw== X-Gm-Message-State: AOAM533e49YzVYTup/tS04RMm/aYWpuw3/5QqB4dIYyNv4aOoeHebv5A CHsD8K4GUqIE431o1lB/nabNH1uv/2c+2A== X-Google-Smtp-Source: ABdhPJxIZO/PGgyXck8j13YW74X0IQja1548ltezhFxFsl5qTXxVzvR03tRF2/DAwgQqabcyAg+0JQ== X-Received: by 2002:a17:907:c0e:: with SMTP id ga14mr10252946ejc.26.1636643252095; Thu, 11 Nov 2021 07:07:32 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id gv34sm1492792ejc.104.2021.11.11.07.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:07:31 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 09/10] trace-cmd: Use the new flow when creating output handler Date: Thu, 11 Nov 2021 17:07:30 +0200 Message-Id: <20211111150730.86323-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 Thu Nov 11 15:07:37 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: 12615013 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 0C7C5C433EF for ; Thu, 11 Nov 2021 15:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E26B461108 for ; Thu, 11 Nov 2021 15:07:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233823AbhKKPKa (ORCPT ); Thu, 11 Nov 2021 10:10:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233820AbhKKPK3 (ORCPT ); Thu, 11 Nov 2021 10:10:29 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1D4C061766 for ; Thu, 11 Nov 2021 07:07:40 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id v11so25424964edc.9 for ; Thu, 11 Nov 2021 07:07:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Yzxwt32tMeaSZtC1D53SQQaG1YQXlxemDnOqDMvhfA=; b=PD0xmtQ/ZNf5h0s7jlDhBQyVE6YFPI9sme0AgYxKeRRHXybyzTu2QPrP9djjDlit/D 2PZibSuhh0ZlM3+yUXHfhv2DLQKlp5fnUYx6aotLMD92WnkpFvAG4nThKV0sqEWPugxk PwTtFEYbxZwPDJ1sqINoFqbD4H8IL2obq3GhEPqxHd8RxXA+TgZPIq/1ii6bDzvn/0S7 LZx1mxUWAiy2MIlRuRWI/Y+K1X+HJL1/8wdpPe3s8QP64bcyF5p5YdLwkPimDYcA72jd /L78c/Ln2acKqAPuIX38p2Aw1xoEgxdFPuhi6XXMHH8JVjzplq/mfS6h/Zay2Mbd7h3Y kj/Q== 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:mime-version :content-transfer-encoding; bh=6Yzxwt32tMeaSZtC1D53SQQaG1YQXlxemDnOqDMvhfA=; b=KRMBaeeVKratxjweDkQHUEZUG60ftqw9y3iPbIMlHf4z8/VcXE6E5egxHnq/eJbPh2 IrjSsjN/6mu8CpViL+dtCYXeU1IOYxINa4qp3qpnzNFH4K9LPAKdPVPD89CoZPD2FyDc rb1aohuF8idPWGBkP4dBGHu3GSZ7wcKN/HfmgX45KecsAtgg95GDWlF9VGyJoMoe6GVp US7U6xZBZ0FOxZwGeZFU+E3KjDottR2FPg++b20fsUkC4a1HD0/wQk5lxtkIVo7lH+MZ i1+CuVrw370lKBoDqzBGMP4Kfi8QMqpfQdXHVIGi5awlaEih4V+EixgjWH6toDMUxKOk QqCw== X-Gm-Message-State: AOAM531wG2qUdG77JHhq1YcRGYJH9KeuhIq0uga8n5rHBTKulDT3lGRS s9GbqkGJC8eqIA96g+xwarcVktTzbXAy+Q== X-Google-Smtp-Source: ABdhPJyr97h/VqqfcxBfjT7dvHKAEJ5Vh4pChby5xuQOTeeSUGcWSPbEUpgBNXTtazKwCbN9JbxOKQ== X-Received: by 2002:a17:906:b090:: with SMTP id x16mr10052964ejy.438.1636643258630; Thu, 11 Nov 2021 07:07:38 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id t6sm1763496edj.27.2021.11.11.07.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 07:07:38 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 10/10] trace-cmd library: Remove deprecated APIs for creating an output handler Date: Thu, 11 Nov 2021 17:07:37 +0200 Message-Id: <20211111150737.86339-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 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 f148d520..fb050671 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