From patchwork Wed Aug 14 08:47:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093513 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB6F9184E for ; Wed, 14 Aug 2019 08:47:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9770C28606 for ; Wed, 14 Aug 2019 08:47:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BBCF287C1; Wed, 14 Aug 2019 08:47:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4599128606 for ; Wed, 14 Aug 2019 08:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725265AbfHNIrS (ORCPT ); Wed, 14 Aug 2019 04:47:18 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38172 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbfHNIrR (ORCPT ); Wed, 14 Aug 2019 04:47:17 -0400 Received: by mail-wm1-f67.google.com with SMTP id m125so3706755wmm.3 for ; Wed, 14 Aug 2019 01:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QvmxyWqmUQd8fxBfL1GhY95N+po7FL6ZZAgEaHx8R/4=; b=p2At8EAICj+u+HpR9brP2SVCJGa+kZfiNIwiNzDoInNJchAWDFDx1yaZR1HULSYkGs XJlVd++mYGySDHArqg2yTb+cahtlc27DTzkyB1+SJQGetDTzcCz97LhnX++Ow8rIDYNy 6ibblgfYy/+ohH2DXpVzvqwHUS7A4urvnRMtqiELYn7M6oN8IkmnM+YLegzBWjsbGJOR +KAMlJWTObfQBI70IvNyIy8Ab+ic4A4h9FB8WH1kvBMJNAnfs5LFu96RU15VLYHBEObi zdkR8h6GnuVZ8ZD6eJPQLlnDi2gKxzdsRMgBJ9LeELSiAkZmaayd/zwcDde/9xnlp+Ms 0Stw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QvmxyWqmUQd8fxBfL1GhY95N+po7FL6ZZAgEaHx8R/4=; b=keHkY19Hog+RaX0fF/Uob6+VeMGPcxBGY+uHYWZYbtBQtKUiFImSW8ug9gn1t6sktp RJD0/A+irY5gtqD5zlUH3TSgeFuA6FbrzNvcr19TBXB02/lDE+LmsackjeTO5Ce78US3 S0nZCgZDbiORGqDtzTqHIgm+oPhyF3BSywzE1Lb+CguILzAfP6HsmdBzi2NGYmLOMFEF 40vaftKgnmHRAiylm4ZVAzluL0+SXoL3iAeIHdd+OgaBWDU20GjFRABpQZ6wvF1R3TgM K3LlDN5YanBuyEtAaPdwGDbzQ3phORVk3pWXYRQECOxLDzFu0oeqOKfOTJe/dZnPD5Sn QNkA== X-Gm-Message-State: APjAAAWJGQXecTUNRXCXpWM7lmBK5Cmlz8jYF1CQ7DsUu5PnRE8khms8 PQhnCguOMurHBj6z6Lya5pafIIz4+3I= X-Google-Smtp-Source: APXvYqweLugiBZRcaiNSSaseG5AV08l4iXpQIsImxX8P5lulk2GQLtl7yheXVMOO2VnKiOJLj27GVg== X-Received: by 2002:a05:600c:144:: with SMTP id w4mr7553237wmm.94.1565772436553; Wed, 14 Aug 2019 01:47:16 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:15 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 1/8] trace-cmd: Move trace-cmd-local.h from the application to the library Date: Wed, 14 Aug 2019 11:47:01 +0300 Message-Id: <20190814084712.28188-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The trace-cmd-local.h file is used by trace-input.c, trace-output.c and trace-msg.c files. The first one is part of the libtracecmd library. The others will be moved to the same library, so this header file should be part of the library too. Signed-off-by: Tzvetomir Stoyanov (VMware) --- {tracecmd => lib/trace-cmd}/include/trace-cmd-local.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {tracecmd => lib/trace-cmd}/include/trace-cmd-local.h (100%) diff --git a/tracecmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h similarity index 100% rename from tracecmd/include/trace-cmd-local.h rename to lib/trace-cmd/include/trace-cmd-local.h From patchwork Wed Aug 14 08:47:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093515 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A92614DB for ; Wed, 14 Aug 2019 08:47:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9AA428606 for ; Wed, 14 Aug 2019 08:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDC5C287C1; Wed, 14 Aug 2019 08:47:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 741B428606 for ; Wed, 14 Aug 2019 08:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725955AbfHNIrU (ORCPT ); Wed, 14 Aug 2019 04:47:20 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34232 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbfHNIrU (ORCPT ); Wed, 14 Aug 2019 04:47:20 -0400 Received: by mail-wm1-f68.google.com with SMTP id e8so2823254wme.1 for ; Wed, 14 Aug 2019 01:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BzpyXnjPBi5Md5sppUmcV5UzhBMiyw6EOIYqgcZkdNw=; b=axSJYPhQ2uRbWgX2w3SipaMF2PHyTurXdwIiXXATMdc4ngAoT/dIjXi9xnKrx3AUpv smLQcF4paoO3Z/R6mgmu9HsBAwxHvDEp9o/C0qD1EFhMnaMTSzJ2haDaidxPWQwkJugb qTNQreiQDxWDHYHLwITnDwy4d1qsc2fjD+WgOXsDkUvbl8e4q40+UCaGwmXqnyAlLjLA 2uiudtna0lYjVB0gJOKt/3Q/Wt8cqxh7VbjXuyP0M/cTEfeRpObsAxOmAun7VLCbYU/O WE8oobLpTHmxb1IWDHW14hS5SAFohz933f+qKt6M74dPGhBmxwngYNPUhu76gf7XUzu2 PA5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BzpyXnjPBi5Md5sppUmcV5UzhBMiyw6EOIYqgcZkdNw=; b=MbgxTvOhTKG7uAdBQt88pz1CQIVmfPCLJzLLsiYlVJISY5KhsKMZcMktqT8M6CuT3Z u1O9HHw9f2AliIWI9DjykA3mwlSAWj1k9WrFik7NYlUO9mTE3nYvXv2i7+kkFFEoRZio GWE1eKxpsiHa28ffemHEVCdh5bUGCCh4kTNVJoZHzhKWVcHb8QiVWP6DKGvCWI0H/5Jm zuh/0GX7uPNzKW3nWO00CxuJYFzER+DacQ0AfLloSqtId439vu6KmKenppqsYT4VOFW/ i9weMbXxWdwlTVQubcE5Ou933NxNkBGbcRJyIVu3D9EMeuy9Wrik7HHgTcbxF/GxQCY3 0VvA== X-Gm-Message-State: APjAAAU0XCWMLLqZ1o5JN3BG8mMAZzhs5Vk7qdcXKyDXMLUDfyv8fPhv Nbvtlx0GmIADfWHKpc7tm0c= X-Google-Smtp-Source: APXvYqwiCJ825F/QYGW4HcNwKRMoqJUa7p+k09GbpGlaCWk5HIFsHPcK/kdoTgr8+l9Ry313wfY7Zg== X-Received: by 2002:a1c:f418:: with SMTP id z24mr7135818wma.80.1565772437894; Wed, 14 Aug 2019 01:47:17 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:17 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 2/8] trace-cmd: Move trace-output.c into the library code Date: Wed, 14 Aug 2019 11:47:02 +0300 Message-Id: <20190814084712.28188-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Functions, implemented in trace-output.c file, do not depend on trace-cmd application context and can be used standalone. The file is moved from trace-cmd to libtracecmd. It also fixes a warning while loading python modules from kernelshark: ImportError: ctracecmd.so: undefined symbol: tracecmd_append_cpu_data Since in trace-output.c is the only code, that uses FILE_VERSION_STRING define (the version of trace.dat file format), this define is moved from version.h in trace-cmd-local.h. Signed-off-by: Tzvetomir Stoyanov (VMware) --- [ v2 changes: - Removed trace-output.c dependency of version.h. Moved FILE_VERSION_STRING define from top Makefile to trace-cmd-local.h. ] Makefile | 3 --- include/version.h | 5 ----- lib/trace-cmd/Makefile | 1 + lib/trace-cmd/include/trace-cmd-local.h | 7 +++++++ {tracecmd => lib/trace-cmd}/trace-output.c | 1 - tracecmd/Makefile | 1 - 6 files changed, 8 insertions(+), 10 deletions(-) rename {tracecmd => lib/trace-cmd}/trace-output.c (99%) diff --git a/Makefile b/Makefile index d34c615..a848394 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,6 @@ export TC_PATCHLEVEL export TC_EXTRAVERSION export TRACECMD_VERSION -# file format version -FILE_VERSION = 6 - MAKEFLAGS += --no-print-directory # Makefiles suck: This macro sets a default value of $(2) for the diff --git a/include/version.h b/include/version.h index 68ce79e..fcf7ba0 100644 --- a/include/version.h +++ b/include/version.h @@ -9,9 +9,4 @@ #include "tc_version.h" #endif -#define _STR(x) #x -#define STR(x) _STR(x) - -#define FILE_VERSION_STRING STR(FILE_VERSION) - #endif /* _VERSION_H */ diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile index 44c1332..0543b91 100644 --- a/lib/trace-cmd/Makefile +++ b/lib/trace-cmd/Makefile @@ -10,6 +10,7 @@ OBJS = OBJS += trace-hash.o OBJS += trace-hooks.o OBJS += trace-input.o +OBJS += trace-output.o OBJS += trace-recorder.o OBJS += trace-util.o OBJS += trace-filter-hash.o diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index fa96d4f..bad325f 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -11,6 +11,13 @@ #include "trace-cmd.h" #include "event-utils.h" +/* trace.dat file format version */ +#define FILE_VERSION 6 + +#define _STR(x) #x +#define STR(x) _STR(x) +#define FILE_VERSION_STRING STR(FILE_VERSION) + extern int quiet; static ssize_t __do_write(int fd, const void *data, size_t size) diff --git a/tracecmd/trace-output.c b/lib/trace-cmd/trace-output.c similarity index 99% rename from tracecmd/trace-output.c rename to lib/trace-cmd/trace-output.c index 33d6ce3..1f94346 100644 --- a/tracecmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -23,7 +23,6 @@ #include "trace-cmd-local.h" #include "list.h" #include "trace-msg.h" -#include "version.h" /* We can't depend on the host size for size_t, all must be 64 bit */ typedef unsigned long long tsize_t; diff --git a/tracecmd/Makefile b/tracecmd/Makefile index bcd437a..6968f83 100644 --- a/tracecmd/Makefile +++ b/tracecmd/Makefile @@ -29,7 +29,6 @@ TRACE_CMD_OBJS += trace-restore.o TRACE_CMD_OBJS += trace-check-events.o TRACE_CMD_OBJS += trace-show.o TRACE_CMD_OBJS += trace-list.o -TRACE_CMD_OBJS += trace-output.o TRACE_CMD_OBJS += trace-usage.o TRACE_CMD_OBJS += trace-msg.o From patchwork Wed Aug 14 08:47:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093517 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37D361823 for ; Wed, 14 Aug 2019 08:47:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2331D28606 for ; Wed, 14 Aug 2019 08:47:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17EE7287C1; Wed, 14 Aug 2019 08:47:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA62628606 for ; Wed, 14 Aug 2019 08:47:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725996AbfHNIrV (ORCPT ); Wed, 14 Aug 2019 04:47:21 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50414 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725954AbfHNIrV (ORCPT ); Wed, 14 Aug 2019 04:47:21 -0400 Received: by mail-wm1-f67.google.com with SMTP id v15so3841863wml.0 for ; Wed, 14 Aug 2019 01:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WKJd7vwppU2A3MhUVsiKoIJntC1IGKSnIaai8zjmnpg=; b=Wijpw8w9gDzB09oCkMsQTXGuwoLBLBqu7OqpA6gtHIW4jUPIcmzDKW7ApmNysKJkbg MTE47zNYpcmFTrxR5MmG3sbqiuTeAVcVOQgP03rt3rR12UIQAmLVK1WWZMfTPqjd7mlE yl2a7Pxycx04YLqmZZMUEdAR5Eu0VkXCfHINJdo/YEa7OomBIXj/Cg92VguGE5Q7M1CD Cdnr4ttAdXy8Pz5Eci0elj56bWQ0nqkBNuzBE4/RmTyG+T/m4rgon4R6mn9wirXN6ijy kNOtU0TnisjRFXoP2zmW1YAE2qqcUmPDbBRBRM7NSKuzUoV+9igWRykkneZMD4RWXHuo 1J2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WKJd7vwppU2A3MhUVsiKoIJntC1IGKSnIaai8zjmnpg=; b=c0lm+afEa4sFc1R7kdWd9K8dJ97OFIJ+Y0p/b5eJGDZFF3Ye3vl+U2E9xiIh6MeXpB A7QWvM1HAptFiHW7qboATAvgmB0B90DiUwGf4lUiQDMdufUZ/L4ee0Va7R2Pjf2Xxoo9 h71Ep7fjWr/CJ6m4t3QrhWgrvBcjexCNCYMQaoli8rXon/OVRAZ4nT7x4fNq7r63kIlU kwjzGPyfOEswjTyE0N36Qez+btEkyrkqjax1zoVeCiTem6l/g5gFwgLNd6Dn0h/DIQhB eM4Imizn4+OjqVl4hw73aleyL2286vkW6S5h/MF45kST1l7mwpTwR2MzXytZMxEIPvBJ GtFw== X-Gm-Message-State: APjAAAUVmYAaW2XlKB1nB+whgKOTH8JlgSpD+Ya9+JSmL6+VWbvawcOL gOKbX9xStwmJSWq/RG7ouNU= X-Google-Smtp-Source: APXvYqzSgFkruHabqlq/eEq6ZZlEyYqA5S6rucNywDWNgYo5/GycZ8oexrzctB2oLzzRNG89AAjlwg== X-Received: by 2002:a1c:9ec5:: with SMTP id h188mr2152692wme.176.1565772439145; Wed, 14 Aug 2019 01:47:19 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:18 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 3/8] trace-cmd: Move trace-msg.c into the library. Date: Wed, 14 Aug 2019 11:47:03 +0300 Message-Id: <20190814084712.28188-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Functions, implemented in trace-msg.c file, do not depend on trace-cmd application context and can be used standalone. The file is moved from trace-cmd to libtracecmd. Signed-off-by: Tzvetomir Stoyanov (VMware) --- {tracecmd/include => include/trace-cmd}/trace-msg.h | 0 lib/trace-cmd/Makefile | 1 + {tracecmd => lib/trace-cmd}/trace-msg.c | 0 tracecmd/Makefile | 1 - 4 files changed, 1 insertion(+), 1 deletion(-) rename {tracecmd/include => include/trace-cmd}/trace-msg.h (100%) rename {tracecmd => lib/trace-cmd}/trace-msg.c (100%) diff --git a/tracecmd/include/trace-msg.h b/include/trace-cmd/trace-msg.h similarity index 100% rename from tracecmd/include/trace-msg.h rename to include/trace-cmd/trace-msg.h diff --git a/lib/trace-cmd/Makefile b/lib/trace-cmd/Makefile index 0543b91..78875e4 100644 --- a/lib/trace-cmd/Makefile +++ b/lib/trace-cmd/Makefile @@ -14,6 +14,7 @@ OBJS += trace-output.o OBJS += trace-recorder.o OBJS += trace-util.o OBJS += trace-filter-hash.o +OBJS += trace-msg.o # Additional util objects OBJS += trace-blk-hack.o diff --git a/tracecmd/trace-msg.c b/lib/trace-cmd/trace-msg.c similarity index 100% rename from tracecmd/trace-msg.c rename to lib/trace-cmd/trace-msg.c diff --git a/tracecmd/Makefile b/tracecmd/Makefile index 6968f83..d491aae 100644 --- a/tracecmd/Makefile +++ b/tracecmd/Makefile @@ -30,7 +30,6 @@ TRACE_CMD_OBJS += trace-check-events.o TRACE_CMD_OBJS += trace-show.o TRACE_CMD_OBJS += trace-list.o TRACE_CMD_OBJS += trace-usage.o -TRACE_CMD_OBJS += trace-msg.o ALL_OBJS := $(TRACE_CMD_OBJS:%.o=$(bdir)/%.o) From patchwork Wed Aug 14 08:47:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093519 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 523C01823 for ; Wed, 14 Aug 2019 08:47:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C8F028606 for ; Wed, 14 Aug 2019 08:47:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D52287C1; Wed, 14 Aug 2019 08:47:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFD1E28606 for ; Wed, 14 Aug 2019 08:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726132AbfHNIrX (ORCPT ); Wed, 14 Aug 2019 04:47:23 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34111 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbfHNIrX (ORCPT ); Wed, 14 Aug 2019 04:47:23 -0400 Received: by mail-wr1-f66.google.com with SMTP id 31so110334873wrm.1 for ; Wed, 14 Aug 2019 01:47:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BOlQQC/LhTmortr7wCI14Q4XMaaRk4LvFnhRPQhaeVk=; b=EDALI7cXlM1JvJoswI1dx2cG2cyiwYIkSo2T75/WROgk1yxA9fXliYPOSVbHYSJTdI CxiyBlt4tIwqnqSffrVW10ZcuYUxaVdtKs/a5gvK5F1BZTcXX+A0VIa5rumHnYlOMP7P DhXbMr8dS/mQwGIUqv3rtLudZsaPw6/1FwOP61tGj3PpdKwduXGLcd8wuguH+zlyuNfO VmE9FVh+9glzEL66ZvPXJDgmlyNRe8ODdjB2EjLMxAdFlj0gPawuFj1579j4VRyM+6Vh Z++5G7TQgtc+7Da7W0wlEg5aS9jMVHEkXhe013v7MC3pmsEprrY/hRBBP5+ed1Do6Qjc jDog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BOlQQC/LhTmortr7wCI14Q4XMaaRk4LvFnhRPQhaeVk=; b=tP4V/twrHze+5z2gckk6qhgHWCU18uZNedzMQIg0rENK/0fKo2y3vMibG1dKBlJYf4 u9IhiB1RG483qnQOHKXWnmcCOhVxsliyQC/mMdx5qsseaO6t6sWANLrHzdZvPZvhmOpS R4EpIaImyomhGNmnhfloO+NUG+8GWuy4AnXtMgnNBQwJrdtL/dWkVx4jGAZ5w513MurC RgLsZuu8RO7rwXDESCpqG4lgq0u1nDWnf5FXhC8Ywpg8YETNUk/Th8NIGwqe8T4LBMSR E5Ku2VjepNcrzhrJzTYQJIm7Syb1dRfHzIh5L+EADHAMCg+6X3OKsnW62WTBadC+YSe5 2djA== X-Gm-Message-State: APjAAAVpi9pWoH4C+JdjC0jAfynUKvUzrSQ6u98kT83aXp15bB0BU95B LQbZ5jkWBMZkySioGOrFHxgA+1k/wrU= X-Google-Smtp-Source: APXvYqzU+2oCsMER6tFnSAEHfTXRuSMVyMNo62fX229Dw0BdcPatjjvxi1ZKqhdjt4FuWPvL2k9q/A== X-Received: by 2002:a5d:4490:: with SMTP id j16mr24142596wrq.335.1565772440223; Wed, 14 Aug 2019 01:47:20 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:19 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 4/8] trace-cmd: Move trace-cmd global variable "quiet" to libtracecmd Date: Wed, 14 Aug 2019 11:47:04 +0300 Message-Id: <20190814084712.28188-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A trace-cmd global variable "quiet" is used from libtracecmd and should be defined there. A new library APIs are implemented to access it: void tracecmd_set_quiet(int quiet); int tracecmd_get_quiet(void); Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 3 +++ lib/trace-cmd/include/trace-cmd-local.h | 2 -- lib/trace-cmd/trace-output.c | 4 ++-- lib/trace-cmd/trace-util.c | 21 +++++++++++++++++++++ tracecmd/include/trace-local.h | 1 - tracecmd/trace-cmd.c | 1 - tracecmd/trace-record.c | 6 +++--- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index c4a437a..5ce8fb3 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -49,6 +49,9 @@ enum { void tracecmd_record_ref(struct tep_record *record); void free_record(struct tep_record *record); +void tracecmd_set_quiet(int quiet); +int tracecmd_get_quiet(void); + struct tracecmd_input; struct tracecmd_output; struct tracecmd_recorder; diff --git a/lib/trace-cmd/include/trace-cmd-local.h b/lib/trace-cmd/include/trace-cmd-local.h index bad325f..09574db 100644 --- a/lib/trace-cmd/include/trace-cmd-local.h +++ b/lib/trace-cmd/include/trace-cmd-local.h @@ -18,8 +18,6 @@ #define STR(x) _STR(x) #define FILE_VERSION_STRING STR(FILE_VERSION) -extern int quiet; - static ssize_t __do_write(int fd, const void *data, size_t size) { ssize_t tot = 0; diff --git a/lib/trace-cmd/trace-output.c b/lib/trace-cmd/trace-output.c index 1f94346..35252ef 100644 --- a/lib/trace-cmd/trace-output.c +++ b/lib/trace-cmd/trace-output.c @@ -1157,7 +1157,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle, goto out_free; for (i = 0; i < cpus; i++) { - if (!quiet) + if (!tracecmd_get_quiet()) fprintf(stderr, "CPU%d data recorded at offset=0x%llx\n", i, (unsigned long long) offsets[i]); offset = lseek64(handle->fd, offsets[i], SEEK_SET); @@ -1172,7 +1172,7 @@ int tracecmd_write_cpu_data(struct tracecmd_output *handle, check_size, sizes[i]); goto out_free; } - if (!quiet) + if (!tracecmd_get_quiet()) fprintf(stderr, " %llu bytes in size\n", (unsigned long long)check_size); } diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 7c74bae..26b9a18 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -28,6 +28,7 @@ int tracecmd_disable_sys_plugins; int tracecmd_disable_plugins; +static int tracecmd_quiet; static struct registered_plugin_options { struct registered_plugin_options *next; @@ -96,6 +97,26 @@ char **trace_util_list_plugin_options(void) return list; } +/** + * tracecmd_set_quiet - Set if to print output to the screen + * @quiet: If non zero, print no output to the screen + * + */ +void tracecmd_set_quiet(int quiet) +{ + tracecmd_quiet = quiet; +} + +/** + * tracecmd_get_quiet - Get if to print output to the screen + * Returns non zero, if no output to the screen should be printed + * + */ +int tracecmd_get_quiet(void) +{ + return tracecmd_quiet; +} + void trace_util_free_plugin_options_list(char **list) { tracecmd_free_list(list); diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 78c52dc..23a3a29 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -13,7 +13,6 @@ #include "event-utils.h" extern int debug; -extern int quiet; /* fix stupid glib guint64 typecasts and printf formats */ typedef unsigned long long u64; diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c index 797b303..5283ba7 100644 --- a/tracecmd/trace-cmd.c +++ b/tracecmd/trace-cmd.c @@ -17,7 +17,6 @@ int silence_warnings; int show_status; int debug; -int quiet; void warning(const char *fmt, ...) { diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index b2ed6bf..b25b659 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3387,7 +3387,7 @@ static void print_stat(struct buffer_instance *instance) { int cpu; - if (quiet) + if (tracecmd_get_quiet()) return; if (!is_top_instance(instance)) @@ -4207,7 +4207,7 @@ static void check_plugin(const char *plugin) } die ("Plugin '%s' does not exist", plugin); out: - if (!quiet) + if (!tracecmd_get_quiet()) fprintf(stderr, " plugin '%s'\n", plugin); free(buf); } @@ -5154,7 +5154,7 @@ static void parse_record_options(int argc, break; case OPT_quiet: case 'q': - quiet = 1; + tracecmd_set_quiet(1); break; default: usage(argv); From patchwork Wed Aug 14 08:47:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093529 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 520D418B7 for ; Wed, 14 Aug 2019 08:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37E3428606 for ; Wed, 14 Aug 2019 08:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C121287C1; Wed, 14 Aug 2019 08:47:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B9C8287C2 for ; Wed, 14 Aug 2019 08:47:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726119AbfHNIr1 (ORCPT ); Wed, 14 Aug 2019 04:47:27 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43429 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725954AbfHNIrY (ORCPT ); Wed, 14 Aug 2019 04:47:24 -0400 Received: by mail-wr1-f67.google.com with SMTP id y8so4352733wrn.10 for ; Wed, 14 Aug 2019 01:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ATHkTl64dc+PwT9K6GwGHhzgZwXlEQJYJ3ZCQRQ0c4c=; b=RySAleaE9dFDw6rM0dQyzsE9o1JISoR3Pk3HW9ecEkzWmujAiA8MeJycOSgsNrZ/3m eUA+4pNUedTh3Bmgf+xD++GEBn9eSAQI1Bk0VFGWkMeZ91NoGzWlUAFaejJytkdYp2Zb 805wImL8474Mu+asSDrgIjfqXSHZkKWEl/mcQBGikYNxDfsvyIHrJxTnGuj7LCp3WAlk 1kiv2C8jbWrIqaayHOkhInz9kvPQrRhM7NahcXXjNADQ0MIcs4OlGE9VtL6Ug32qB4lZ HmgDd8eN4ePkAJOEZuwpcgmku2XVRFQ4W6TuDqNNhbCnQYPGgl8WeZMyeiQFQKH2OGwc 3jnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ATHkTl64dc+PwT9K6GwGHhzgZwXlEQJYJ3ZCQRQ0c4c=; b=pQsf0Z6nm0LUdNwkszS0M9vziItvKQ3gEbT/4iUgDVh2FWQf/hRwHkMSx6a8+XZnYM 2HSugkhhaTEDnlrr6esNLinV7lGKoJNJyW4ht6tq+7Kxg77Stf8T1RfzpJr+BxakdzGj qRhW9j20MBMlZ2pxWlBijCGaDpl+XS8hJWXrGZ1PwG8rzjPfjfqXkNTWI91QaBmrhsGG 2mzVHnw2bkKQN3p38Efvap/tUbegUKtXqtoLWVmTw5lNiBUhqPgmE3cGs2Q2XiWhlonZ 2Ltk58PNWzukHmvy/C55wR3EwM8gHb+TCXA6F4m4/WPFHGMCkOQ3be0Lox+6ZfLSDZP6 EMZQ== X-Gm-Message-State: APjAAAVti9WTuhmmBpjIJCCC05r+9LaXWZhpbHTICXTsC9kk3jgBIDFQ v5zqd2/zR7CRZx2Py0dMtWU= X-Google-Smtp-Source: APXvYqy+Sci8USWc9yVqHOKLwsskcDKSkFS4X7KDEckbPXa1Xpsw/B7KxL4ByhHcTyMdmd09KxNAeA== X-Received: by 2002:a5d:6b84:: with SMTP id n4mr42589226wrx.118.1565772441413; Wed, 14 Aug 2019 01:47:21 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:20 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 5/8] trace-cmd: Move trace-cmd global variable "debug" to libtracecmd Date: Wed, 14 Aug 2019 11:47:05 +0300 Message-Id: <20190814084712.28188-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A trace-cmd global variable "debug" is used from libtracecmd and should be defined there. A new library APIs are implemented to access it: void tracecmd_set_debug(bool debug); bool tracecmd_get_debug(void); Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 3 +++ lib/trace-cmd/trace-msg.c | 4 ++-- lib/trace-cmd/trace-util.c | 21 +++++++++++++++++++++ tracecmd/include/trace-local.h | 2 -- tracecmd/trace-cmd.c | 2 -- tracecmd/trace-list.c | 2 +- tracecmd/trace-listen.c | 8 ++++---- tracecmd/trace-read.c | 8 ++++---- tracecmd/trace-record.c | 2 +- 9 files changed, 36 insertions(+), 16 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 5ce8fb3..b96de04 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -51,6 +51,9 @@ void free_record(struct tep_record *record); void tracecmd_set_quiet(int quiet); int tracecmd_get_quiet(void); +void tracecmd_set_debug(bool debug); +bool tracecmd_get_debug(void); + struct tracecmd_input; struct tracecmd_output; diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c index e2dd188..92562c7 100644 --- a/lib/trace-cmd/trace-msg.c +++ b/lib/trace-cmd/trace-msg.c @@ -32,7 +32,7 @@ static inline void dprint(const char *fmt, ...) { va_list ap; - if (!debug) + if (!tracecmd_get_debug()) return; va_start(ap, fmt); @@ -351,7 +351,7 @@ static int tracecmd_msg_recv_wait(int fd, struct tracecmd_msg *msg) pfd.fd = fd; pfd.events = POLLIN; - ret = poll(&pfd, 1, debug ? -1 : msg_wait_to); + ret = poll(&pfd, 1, tracecmd_get_debug() ? -1 : msg_wait_to); if (ret < 0) return -errno; else if (ret == 0) diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 26b9a18..b5ce84f 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -29,6 +29,7 @@ int tracecmd_disable_sys_plugins; int tracecmd_disable_plugins; static int tracecmd_quiet; +static bool tracecmd_debug; static struct registered_plugin_options { struct registered_plugin_options *next; @@ -117,6 +118,26 @@ int tracecmd_get_quiet(void) return tracecmd_quiet; } +/** + * tracecmd_set_quiet - Set if to print output to the screen + * @quiet: If non zero, print no output to the screen + * + */ +void tracecmd_set_debug(bool debug) +{ + tracecmd_debug = debug; +} + +/** + * tracecmd_get_quiet - Get if to print output to the screen + * Returns non zero, if no output to the screen should be printed + * + */ +bool tracecmd_get_debug(void) +{ + return tracecmd_debug; +} + void trace_util_free_plugin_options_list(char **list) { tracecmd_free_list(list); diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 23a3a29..e2d5506 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -12,8 +12,6 @@ #include "trace-cmd.h" #include "event-utils.h" -extern int debug; - /* fix stupid glib guint64 typecasts and printf formats */ typedef unsigned long long u64; diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c index 5283ba7..30691b6 100644 --- a/tracecmd/trace-cmd.c +++ b/tracecmd/trace-cmd.c @@ -16,8 +16,6 @@ int silence_warnings; int show_status; -int debug; - void warning(const char *fmt, ...) { va_list ap; diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c index 00c6073..832540e 100644 --- a/tracecmd/trace-list.c +++ b/tracecmd/trace-list.c @@ -427,7 +427,7 @@ void trace_list(int argc, char **argv) break; case '-': if (strcmp(argv[i], "--debug") == 0) { - debug = true; + tracecmd_set_debug(true); break; } fprintf(stderr, "list: invalid option -- '%s'\n", diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index 3106022..3cbee67 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -717,7 +717,7 @@ static int do_fork(int cfd) pid_t pid; /* in debug mode, we do not fork off children */ - if (debug) + if (tracecmd_get_debug()) return 0; pid = fork(); @@ -769,7 +769,7 @@ static int do_connection(int cfd, struct sockaddr_storage *peer_addr, tracecmd_msg_handle_close(msg_handle); - if (!debug) + if (!tracecmd_get_debug()) exit(0); return 0; @@ -910,7 +910,7 @@ static void do_listen(char *port) struct addrinfo *result, *rp; int sfd, s; - if (!debug) + if (!tracecmd_get_debug()) signal_setup(SIGCHLD, sigstub); make_pid_file(); @@ -1009,7 +1009,7 @@ void trace_listen(int argc, char **argv) daemon = 1; break; case OPT_debug: - debug = 1; + tracecmd_set_debug(true); break; default: usage(argv); diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index d22c723..12b8b3d 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -782,10 +782,10 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record) cpu, record->missed_events); else if (record->missed_events < 0) trace_seq_printf(&s, "CPU:%d [EVENTS DROPPED]\n", cpu); - if (buffer_breaks || debug) { + if (buffer_breaks || tracecmd_get_debug()) { if (tracecmd_record_at_buffer_start(handle, record)) { trace_seq_printf(&s, "CPU:%d [SUBBUFFER START]", cpu); - if (debug) + if (tracecmd_get_debug()) trace_seq_printf(&s, " [%lld:0x%llx]", tracecmd_page_ts(handle, record), record->offset & ~(page_size - 1)); @@ -816,7 +816,7 @@ void trace_show_data(struct tracecmd_input *handle, struct tep_record *record) tep_print_event(pevent, &s, record, use_trace_clock); if (s.len && *(s.buffer + s.len - 1) == '\n') s.len--; - if (debug) { + if (tracecmd_get_debug()) { struct kbuffer *kbuf; struct kbuffer_raw_info info; void *page; @@ -1616,7 +1616,7 @@ void trace_report (int argc, char **argv) break; case OPT_debug: buffer_breaks = 1; - debug = 1; + tracecmd_set_debug(true); break; case OPT_profile: profile = 1; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index b25b659..32793b3 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -5143,7 +5143,7 @@ static void parse_record_options(int argc, no_filter = true; break; case OPT_debug: - debug = 1; + tracecmd_set_debug(true); break; case OPT_module: if (ctx->instance->filter_mod) From patchwork Wed Aug 14 08:47:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093521 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BAF714DB for ; Wed, 14 Aug 2019 08:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 470C6287BE for ; Wed, 14 Aug 2019 08:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AA55287C2; Wed, 14 Aug 2019 08:47:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AC61287BE for ; Wed, 14 Aug 2019 08:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbfHNIrZ (ORCPT ); Wed, 14 Aug 2019 04:47:25 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50422 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbfHNIrY (ORCPT ); Wed, 14 Aug 2019 04:47:24 -0400 Received: by mail-wm1-f68.google.com with SMTP id v15so3842022wml.0 for ; Wed, 14 Aug 2019 01:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OfmrHsw/n5pWeUgOxMZHawQnFAMFmi7VSXKAYNDnGJ8=; b=cE7RThAT6Il4ISFcmt7ND7L7KhxsMoZxtanE7OiGKaxwqH3jm9RGSHp7P1BIfXsZc4 Mrjx83rjEOaFGKGo5vNRMk5HH9k3ocI5/nowNRA4QX2qDKkP4ODYPcDIJlv8xNz8ZayG ggs2hah8kQH8DUnicb6jOLJuYhpd2eQWBGToIDBIaFL/7ASxqnUWfJDCMcnKzQzDFoHW ui8H7ipktuiPMI+4yM2GiMlMgzhePgCFEtW8vfOaFR7gVNPtEbp9yPgqcYZ2KIWZ7c2f 6bjBBNZyu0cRMSjic2xRmRhSXj7WCeFaHdagn80V9X3SAYiHcvgYqMaoPpYVj0OLCcYx ibjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OfmrHsw/n5pWeUgOxMZHawQnFAMFmi7VSXKAYNDnGJ8=; b=oWRXwjORWyYOBy0o2qP/iqNoeTtCjWvlvL4z/xncPIKtJrTlJ9JqREiNgA8OM0v3Y+ +X9AVPxY1c387qt/Iad2gvtf4Tw2eS+ZKWY9tXQtEbjUPpvgDzS+EIPDASc2HxgnUwj4 AQmVlfzQB9780AMy4MmlaPwBZys36cleekHPgCRAPow/OiL8pNBChfd4PfyAeHVglS9M ltTXVfmKJQZ7m8bA8OOiZi0f7JJYq6PzYzRFgVDudcsqsiTyKNWTM8xsulwExwFsYzsM ELLr+j7ZEzpvs4i5WVYZLHFVjLhqW/fw15aoNlvukzeBNZoYZ5JZ/JASvwDW4vW1BpqK C4cg== X-Gm-Message-State: APjAAAW3Kyl4ve7pCgItqc+zYrs7rJ7cQn8e1oXDRCNPPdgok6R2w0mL 7KHE2CbjgIhyVI/oRln60os0JMaT91c= X-Google-Smtp-Source: APXvYqyRvkE8qW6xLMw1czi+zHd7D39U6fOw6oRzHuzu72EBAokQGXrrTfXWNEO/yIkd7B9jLux/JQ== X-Received: by 2002:a1c:4e10:: with SMTP id g16mr7474395wmh.67.1565772442457; Wed, 14 Aug 2019 01:47:22 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:21 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 6/8] trace-cmd: Move plog() function to libtracecmd. Date: Wed, 14 Aug 2019 11:47:06 +0300 Message-Id: <20190814084712.28188-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP plog() function writes logs into a log file. It is used in libtracecmd and its implementation should be there. The function is moved from trace-cmd into the library, and 2 additional APIs are implemented: int trace_set_log_file(char *logfile); - use it to set the log file. void plog_error(const char *fmt, ...); - use it to log an error message into the file. The plog() function is used also from pdie() in trace-cmd. pdie() depends on trace-cmd context and cannot be moved to the library. It is reimplemented as macros, in order to utilize the new plog() library function. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 4 ++ include/trace-cmd/trace-msg.h | 3 -- lib/trace-cmd/trace-util.c | 71 +++++++++++++++++++++++++++++++++++ tracecmd/trace-listen.c | 69 ++++------------------------------ 4 files changed, 83 insertions(+), 64 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index b96de04..8db0686 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -398,6 +398,10 @@ struct hook_list { struct hook_list *tracecmd_create_event_hook(const char *arg); void tracecmd_free_hooks(struct hook_list *hooks); +void plog(const char *fmt, ...); +void plog_error(const char *fmt, ...); +int trace_set_log_file(char *logfile); + /* --- Hack! --- */ int tracecmd_blk_hack(struct tracecmd_input *handle); diff --git a/include/trace-cmd/trace-msg.h b/include/trace-cmd/trace-msg.h index b7fe10b..aab8a69 100644 --- a/include/trace-cmd/trace-msg.h +++ b/include/trace-cmd/trace-msg.h @@ -12,7 +12,4 @@ extern unsigned int page_size; -void plog(const char *fmt, ...); -void pdie(const char *fmt, ...); - #endif /* _TRACE_MSG_H_ */ diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index b5ce84f..8c1a0a0 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -31,6 +31,8 @@ int tracecmd_disable_plugins; static int tracecmd_quiet; static bool tracecmd_debug; +static FILE *trace_logfp; + static struct registered_plugin_options { struct registered_plugin_options *next; struct tep_plugin_option *options; @@ -1716,3 +1718,72 @@ void __weak *malloc_or_die(unsigned int size) die("malloc"); return data; } + +#define LOG_BUF_SIZE 1024 +static void __plog(const char *prefix, const char *fmt, va_list ap, FILE *fp) +{ + static int newline = 1; + char buf[LOG_BUF_SIZE]; + int r; + + r = vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); + + if (r > LOG_BUF_SIZE) + r = LOG_BUF_SIZE; + + if (trace_logfp) { + if (newline) + fprintf(trace_logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); + else + fprintf(trace_logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); + newline = buf[r - 1] == '\n'; + fflush(trace_logfp); + return; + } + + fprintf(fp, "%.*s", r, buf); +} + +void plog(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __plog("", fmt, ap, stdout); + va_end(ap); + /* Make sure it gets to the screen, in case we crash afterward */ + fflush(stdout); +} + +void plog_error(const char *fmt, ...) +{ + va_list ap; + char *str = ""; + + va_start(ap, fmt); + __plog("Error: ", fmt, ap, stderr); + va_end(ap); + if (errno) + str = strerror(errno); + if (trace_logfp) + fprintf(trace_logfp, "\n%s\n", str); + else + fprintf(stderr, "\n%s\n", str); +} + +/** + * trace_set_log_file - Set file for logging + * @logfile: Name of the log file + * + * Returns 0 on successful completion or -1 in case of error + */ +int trace_set_log_file(char *logfile) +{ + if (trace_logfp) + fclose(trace_logfp); + trace_logfp = fopen(logfile, "w"); + if (!trace_logfp) + return -1; + return 0; +} + diff --git a/tracecmd/trace-listen.c b/tracecmd/trace-listen.c index 3cbee67..e0dcd71 100644 --- a/tracecmd/trace-listen.c +++ b/tracecmd/trace-listen.c @@ -34,8 +34,6 @@ static char *output_dir; static char *default_output_file = "trace"; static char *output_file; -static FILE *logfp; - static int backlog = 5; static int do_daemon; @@ -44,6 +42,13 @@ static int do_daemon; static struct tracecmd_msg_handle *stop_msg_handle; static bool done; +#define pdie(fmt, ...) \ + do { \ + plog_error(fmt, ##__VA_ARGS__); \ + remove_pid_file(); \ + exit(-1); \ + } while (0) + #define TEMP_FILE_STR "%s.%s:%s.cpu%d", output_file, host, port, cpu static char *get_temp_file(const char *host, const char *port, int cpu) { @@ -114,43 +119,6 @@ static void finish(int sig) done = true; } -#define LOG_BUF_SIZE 1024 -static void __plog(const char *prefix, const char *fmt, va_list ap, - FILE *fp) -{ - static int newline = 1; - char buf[LOG_BUF_SIZE]; - int r; - - r = vsnprintf(buf, LOG_BUF_SIZE, fmt, ap); - - if (r > LOG_BUF_SIZE) - r = LOG_BUF_SIZE; - - if (logfp) { - if (newline) - fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); - else - fprintf(logfp, "[%d]%s%.*s", getpid(), prefix, r, buf); - newline = buf[r - 1] == '\n'; - fflush(logfp); - return; - } - - fprintf(fp, "%.*s", r, buf); -} - -void plog(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - __plog("", fmt, ap, stdout); - va_end(ap); - /* Make sure it gets to the screen, in case we crash afterward */ - fflush(stdout); -} - static void make_pid_name(int mode, char *buf) { snprintf(buf, PATH_MAX, VAR_RUN_DIR "/trace-cmd-net.pid"); @@ -169,26 +137,6 @@ static void remove_pid_file(void) unlink(buf); } -void pdie(const char *fmt, ...) -{ - va_list ap; - char *str = ""; - - va_start(ap, fmt); - __plog("Error: ", fmt, ap, stderr); - va_end(ap); - if (errno) - str = strerror(errno); - if (logfp) - fprintf(logfp, "\n%s\n", str); - else - fprintf(stderr, "\n%s\n", str); - - remove_pid_file(); - - exit(-1); -} - static int process_udp_child(int sfd, const char *host, const char *port, int cpu, int page_size, int use_tcp) { @@ -1030,8 +978,7 @@ void trace_listen(int argc, char **argv) if (logfile) { /* set the writes to a logfile instead */ - logfp = fopen(logfile, "w"); - if (!logfp) + if (trace_set_log_file(logfile) < 0) die("creating log file %s", logfile); } From patchwork Wed Aug 14 08:47:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093523 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACCEE14DB for ; Wed, 14 Aug 2019 08:47:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 976C5287BE for ; Wed, 14 Aug 2019 08:47:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B760287C6; Wed, 14 Aug 2019 08:47:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 621DB287BE for ; Wed, 14 Aug 2019 08:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726126AbfHNIr0 (ORCPT ); Wed, 14 Aug 2019 04:47:26 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36057 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbfHNIrZ (ORCPT ); Wed, 14 Aug 2019 04:47:25 -0400 Received: by mail-wm1-f65.google.com with SMTP id g67so3721733wme.1 for ; Wed, 14 Aug 2019 01:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WWBma2i/7R+AkcFwiG7RkXUxMWv7vVicg0twE9szBsk=; b=rRKJa06aLIauT0rnqdXJNRRhvf1vCGWbEcJ9SMZpOsKPPyOgT4wmN/ECOYdIFLkm9B Sse5gQpdQsgAtviC2tGSupWhjxSwl+eOX0gFu/BdY/tPMI5VQKZPQO/w6N7QI0l/CPqq IulzVw/qvLIU3fwPgsUd3z5qMVfYzGn3mzYo/twZD8i2DEFcjF+6iONw4/5FEI2l/2Xy CWtBB8n4jLWU02kM/vvCNHY2imyvS7iviqXp4+L4pJnlxmi4zniUbzV1c9qtbQpm9JUH pkVwrWlYn9Cbk0ZqA/XWORueG6Ry+09gaBHkD80fi2b043LopnbjqxKfOjcASMXQ4nMn YxaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WWBma2i/7R+AkcFwiG7RkXUxMWv7vVicg0twE9szBsk=; b=h/1gTJ0G9f/TYQtSEFA8G83XMf/xPfgX2n/FJO+N+JoPEyS7Bc6azriQgl9tChISXR KWaIBtGJqeCLWfcmEvuAL+bIAWymRT68qcHbHBm7R1JNZskyXRrt4o8bwAHeU4e0iosp D5NnifgIdTX32l36RD7HSIxRSeG0XWAFcsfcWt/EuSy4odNdSiCkohrLQ54w8w9P/hWr /UfsTDPrtOn1rYW5pHjEt8go+qwZvixDlXQV5ObZxGH2WUr+IeC35+G+dbrCTgQ69Kwl F4awtCCIL61VWXwyyM0z1A2uGXnlLPjDWXYGxpjY/m7GFvcKIZDvseS0MkwoTxJXA4uK qr6Q== X-Gm-Message-State: APjAAAXpLwQbSX5eOsyiA338kShDi2XDccLr7RkaevQfrVKHD/FfHK95 qfCdGNjlY7Pbdx67MS+KzDg= X-Google-Smtp-Source: APXvYqwxMTy2jVKFNvOZGa8DSVA4ily89+mzUyTwcdssaAgjQGVLh64hRnNhxSSUnStTZgvF5fjOlQ== X-Received: by 2002:a05:600c:40f:: with SMTP id q15mr7438174wmb.88.1565772443415; Wed, 14 Aug 2019 01:47:23 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:22 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 7/8] trace-cmd: Move trace-cmd APIs from trace-cmd.h to trace-local.h Date: Wed, 14 Aug 2019 11:47:07 +0300 Message-Id: <20190814084712.28188-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP These APIs depend on trace-cmd context and cannot be used standalone: tracecmd_create_top_instance() tracecmd_remove_instances() tracecmd_filter_pid() tracecmd_add_event() tracecmd_enable_events() tracecmd_disable_all_tracing() tracecmd_disable_tracing() tracecmd_enable_tracing() tracecmd_stat_cpu() They are implemented in trace-cmd application, but declared as APIs in trace-cmd.h. The declarations are moved from trace-cmd.h to trace-local.h, local header file visible only to trace-cmd application. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 9 --------- tracecmd/include/trace-local.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 8db0686..2c8d798 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -137,8 +137,6 @@ int tracecmd_buffer_instances(struct tracecmd_input *handle); const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx); struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx); int tracecmd_is_buffer_instance(struct tracecmd_input *handle); -void tracecmd_create_top_instance(char *name); -void tracecmd_remove_instances(void); void tracecmd_set_ts_offset(struct tracecmd_input *handle, unsigned long long offset); void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz); @@ -304,14 +302,7 @@ struct tracecmd_recorder *tracecmd_create_buffer_recorder_maxkb(const char *file int tracecmd_start_recording(struct tracecmd_recorder *recorder, unsigned long sleep); void tracecmd_stop_recording(struct tracecmd_recorder *recorder); -void tracecmd_stat_cpu(struct trace_seq *s, int cpu); long tracecmd_flush_recording(struct tracecmd_recorder *recorder); -void tracecmd_filter_pid(int pid, int exclude); -int tracecmd_add_event(const char *event_str, int stack); -void tracecmd_enable_events(void); -void tracecmd_disable_all_tracing(int disable_tracer); -void tracecmd_disable_tracing(void); -void tracecmd_enable_tracing(void); enum tracecmd_msg_flags { TRACECMD_MSG_FL_USE_TCP = 1 << 0, diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index e2d5506..05760d8 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -216,6 +216,17 @@ void show_instance_file(struct buffer_instance *instance, const char *name); int count_cpus(void); +/* moved from trace-cmd.h */ +void tracecmd_create_top_instance(char *name); +void tracecmd_remove_instances(void); +void tracecmd_filter_pid(int pid, int exclude); +int tracecmd_add_event(const char *event_str, int stack); +void tracecmd_enable_events(void); +void tracecmd_disable_all_tracing(int disable_tracer); +void tracecmd_disable_tracing(void); +void tracecmd_enable_tracing(void); +void tracecmd_stat_cpu(struct trace_seq *s, int cpu); + /* No longer in event-utils.h */ void __noreturn die(const char *fmt, ...); /* Can be overriden */ void *malloc_or_die(unsigned int size); /* Can be overridden */ From patchwork Wed Aug 14 08:47:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11093525 X-Patchwork-Delegate: rostedt@goodmis.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17F311823 for ; Wed, 14 Aug 2019 08:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0040C287C9 for ; Wed, 14 Aug 2019 08:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8A26287C6; Wed, 14 Aug 2019 08:47:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A1AB287C1 for ; Wed, 14 Aug 2019 08:47:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726347AbfHNIr1 (ORCPT ); Wed, 14 Aug 2019 04:47:27 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37041 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726119AbfHNIr0 (ORCPT ); Wed, 14 Aug 2019 04:47:26 -0400 Received: by mail-wr1-f66.google.com with SMTP id z11so8362632wrt.4 for ; Wed, 14 Aug 2019 01:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bQBV9G+B2hAmMg3gfg98ZAsN206h3AQ53nVV5eoKMtE=; b=mEzva+8qdXSEJG8GpJ/+RDde8LxacdkBEcnOeqKhteXqkNH4ImsUngu8XvYNIPt+lv EV1JSW7aDNjQhzh00vVbFHaH8h5peuONt8EMuzSbkFOZaatP/t7KYSkU9/waXpP9BBqk Krpt5stLEBCTLwOo7aNPswTd3hWGHNOx57PMR65G5fzOgw7bt2j1/6DGJD9nBGR8weay ZX8VOYL//ty7PSgTdZO8hCN8IsvAwLz0X5iQWh8S6TxN+Aezd4Axk6KUgZmBP16NmVCQ bisZVxeVZeC1RGDtLz5hCdavN1mAx/maPkMUlfDJ8P0fH3ZmtrbekoLvSzfq1B5YHePZ yA7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bQBV9G+B2hAmMg3gfg98ZAsN206h3AQ53nVV5eoKMtE=; b=kQrydbwCo9iw50OVrfs7eKtIMAPZ1dVmlmZUdDZQrvyWASqLxmOtGXH7upTypE42UM HJhx1qGEG95kSslOEigLnXV6cS0xVQoH6I9cZ2XjFP+XW/BbyBk/559QRv6IFF1x/9qI cGW0pAxTHgC2u1Y6EN4M2xverhcqw9J5LMGsps0SQEQjQiXPLhebkZniY4PJMWXgVt/K uF0z03JWEPqu0S+IcqHmMfpc/FbzVdPCJjrdH45PCB9OC5ucgDRhbxjHLYVmqsCKnpa6 kfAfTHzpaRZMm/oPJ1MCjcgv9ps0iSbsbdhUOZX2WMHraqyjCqK+o2KfkiG5qVNk5bzs Ab0g== X-Gm-Message-State: APjAAAV3FWwaIeiud1X7G8Lig6FtsuqAA8gBHAuAdKiJkheDqyMJ7COy 2p/j3G50SEFfNrUtt/0hvyFFW3hzqx0= X-Google-Smtp-Source: APXvYqwFz61Zy8hhYZ6SKKJmCzSZNtp/H2Lnspj+K1l8wmttZmM3QBudB5ZnjVQ7z2Y1J8POMVFhPA== X-Received: by 2002:adf:ec0d:: with SMTP id x13mr52958181wrn.240.1565772444503; Wed, 14 Aug 2019 01:47:24 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id c19sm2897481wml.13.2019.08.14.01.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2019 01:47:23 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 8/8] trace-cmd: Move tracecmd_stack_tracer_status() function to libtracecmd Date: Wed, 14 Aug 2019 11:47:08 +0300 Message-Id: <20190814084712.28188-9-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190814084712.28188-1-tz.stoyanov@gmail.com> References: <20190814084712.28188-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP tracecmd_stack_tracer_status() function reads the stack tracer status from the proc file system. It does not depend on trace-cmd context and can be used standalone. The function is moved from trace-cmd application into libtracecmd. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-util.c | 49 +++++++++++++++++++++++++++++++++ tracecmd/trace-stack.c | 56 ++------------------------------------ 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index 8c1a0a0..d16a018 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -25,6 +25,7 @@ #define LOCAL_PLUGIN_DIR ".trace-cmd/plugins" #define TRACEFS_PATH "/sys/kernel/tracing" #define DEBUGFS_PATH "/sys/kernel/debug" +#define PROC_STACK_FILE "/proc/sys/kernel/stack_tracer_enabled" int tracecmd_disable_sys_plugins; int tracecmd_disable_plugins; @@ -1787,3 +1788,51 @@ int trace_set_log_file(char *logfile) return 0; } +/** + * tracecmd_stack_tracer_status - Check stack trace status + * @status: Returned stack trace status: + * 0 - not configured, disabled + * non 0 - enabled + * + * Returns -1 in case of an error, 0 if file does not exist + * (stack tracer not enabled) or 1 on successful completion. + */ +int tracecmd_stack_tracer_status(int *status) +{ + struct stat stat_buf; + char buf[64]; + long num; + int fd; + int n; + + if (stat(PROC_STACK_FILE, &stat_buf) < 0) { + /* stack tracer not configured on running kernel */ + *status = 0; /* not configured means disabled */ + return 0; + } + + fd = open(PROC_STACK_FILE, O_RDONLY); + + if (fd < 0) + return -1; + + n = read(fd, buf, sizeof(buf)); + close(fd); + + if (n <= 0) + return -1; + + if (n >= sizeof(buf)) + return -1; + + buf[n] = 0; + errno = 0; + num = strtol(buf, NULL, 10); + + /* Check for various possible errors */ + if (num > INT_MAX || num < INT_MIN || (!num && errno)) + return -1; + + *status = num; + return 1; /* full success */ +} diff --git a/tracecmd/trace-stack.c b/tracecmd/trace-stack.c index 34b3b58..bb002c0 100644 --- a/tracecmd/trace-stack.c +++ b/tracecmd/trace-stack.c @@ -36,58 +36,6 @@ static void test_available(void) die("stack tracer not configured on running kernel"); } -/* - * Returns: - * -1 - Something went wrong - * 0 - File does not exist (stack tracer not enabled) - * 1 - Success - */ -static int read_proc(int *status) -{ - struct stat stat_buf; - char buf[64]; - long num; - int fd; - int n; - - if (stat(PROC_FILE, &stat_buf) < 0) { - /* stack tracer not configured on running kernel */ - *status = 0; /* not configured means disabled */ - return 0; - } - - fd = open(PROC_FILE, O_RDONLY); - - if (fd < 0) - return -1; - - n = read(fd, buf, sizeof(buf)); - close(fd); - - if (n <= 0) - return -1; - - if (n >= sizeof(buf)) - return -1; - - buf[n] = 0; - errno = 0; - num = strtol(buf, NULL, 10); - - /* Check for various possible errors */ - if (num > INT_MAX || num < INT_MIN || (!num && errno)) - return -1; - - *status = num; - return 1; /* full success */ -} - -/* Public wrapper of read_proc() */ -int tracecmd_stack_tracer_status(int *status) -{ - return read_proc(status); -} - /* NOTE: this implementation only accepts new_status in the range [0..9]. */ static void change_stack_tracer_status(unsigned new_status) { @@ -102,7 +50,7 @@ static void change_stack_tracer_status(unsigned new_status) return; } - ret = read_proc(&status); + ret = tracecmd_stack_tracer_status(&status); if (ret < 0) die("error reading %s", PROC_FILE); @@ -160,7 +108,7 @@ static void read_trace(void) size_t n; int r; - if (read_proc(&status) <= 0) + if (tracecmd_stack_tracer_status(&status) <= 0) die("Invalid stack tracer state"); if (status > 0)