From patchwork Mon Mar 11 08:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10846873 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 E3F8A1823 for ; Mon, 11 Mar 2019 08:33:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D18AB28F78 for ; Mon, 11 Mar 2019 08:33:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5C9C28F7A; Mon, 11 Mar 2019 08:33:44 +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=-7.9 required=2.0 tests=BAYES_00,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 5313628F79 for ; Mon, 11 Mar 2019 08:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725839AbfCKIdo (ORCPT ); Mon, 11 Mar 2019 04:33:44 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38093 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfCKIdo (ORCPT ); Mon, 11 Mar 2019 04:33:44 -0400 Received: by mail-wm1-f67.google.com with SMTP id a188so3313541wmf.3 for ; Mon, 11 Mar 2019 01:33:42 -0700 (PDT) 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=B0LSgheigQKYDNu87C/yhSfypvVN6mgElsvHHKqMVDU=; b=qrNUmNx8cSilGZ8JQfoTIzSHO47Js8oC/M8cqiyzuP85+2qHMuIzTMordVkCIrMlmj zoZVJlJkUbOn6JWfd916XVmSnQwIu7zfKVFUbfem9EZYQsQYC2XIAbwmzy55fI76rIvj XZgCZKzX9qeGkgp02Jp058iyTg9NbC97X1mFYjFR5WxTj45lwV+PUs3AGOO36BHDDNnY VyHQsKu7Ri4T61fInr2VbqUdBh7KphD3P8ZBRkNyBuTXEu23rOKBzkrkGIW7QMpa8Mc7 xJP2ubGztxwc1hpGRRmoT8uEvoucZcb4O8NyI2/lV5hHFsEniKa/UB9nEhKAW7EvhhUf pZQg== X-Gm-Message-State: APjAAAUD4lLRHz5iawWlXE3FinqSZdKDMkpemnNJ989JtYN5jQ1RE4Fy tsoHNv4hrcqvD0RaC/AjFs1bLKZr X-Google-Smtp-Source: APXvYqyPjsVAwKE9+CEeCfz6y5XCjffKxCpkPswpLg0GfchLYT6SrFWvCAKMcoLYbwyPxm9cOTMQug== X-Received: by 2002:a7b:c017:: with SMTP id c23mr16082787wmb.50.1552293222272; Mon, 11 Mar 2019 01:33:42 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x17sm19683835wrd.95.2019.03.11.01.33.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 01:33:41 -0700 (PDT) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 1/6] trace-cmd: Fix "trace-cmd reset" command to restore "tracng_on" Date: Mon, 11 Mar 2019 10:33:34 +0200 Message-Id: <20190311083339.21581-2-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311083339.21581-1-tstoyanov@vmware.com> References: <20190311083339.21581-1-tstoyanov@vmware.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 reset" command should restore ftrace to its default state. By default, "tracing/current_tracer" is "nop" and "tracing/tracing_on" is "1". This patch sets "tracing/tracing_on" to 1, when the command "trace-cmd reset" is executed. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 8beefab..fc658b2 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4496,6 +4496,8 @@ void trace_reset(int argc, char **argv) clear_triggers(); tracecmd_remove_instances(); clear_func_filters(); + /* restore tracing_on to 1 */ + tracecmd_enable_tracing(); exit(0); } From patchwork Mon Mar 11 08:33:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10846875 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 1853714DE for ; Mon, 11 Mar 2019 08:33:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05EE728F78 for ; Mon, 11 Mar 2019 08:33:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE80A28F7A; Mon, 11 Mar 2019 08:33:45 +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=-7.9 required=2.0 tests=BAYES_00,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 9DEE028F78 for ; Mon, 11 Mar 2019 08:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbfCKIdp (ORCPT ); Mon, 11 Mar 2019 04:33:45 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38439 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfCKIdp (ORCPT ); Mon, 11 Mar 2019 04:33:45 -0400 Received: by mail-wr1-f67.google.com with SMTP id g12so4014472wrm.5 for ; Mon, 11 Mar 2019 01:33:44 -0700 (PDT) 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=Qn3Ovm26CMQF4CDJU/28ZXQFBZMpgXkLqaLJM18hw5E=; b=CHm/Hzyb9uHt7Cjr0fjbUx37MjABrAWbwuuZK0GsZ+iOfIi0JV2kOyaFgdW0sEPsMK qc1XYlGbz0gskwrK4bnw3NGKcxme3/xj1hSlhiRqUtX3ZzW+Sir3yZk7SO0372+8vrlc FBZL+VCfYjR+TgrhLEr5uJ/64SLuJlUNfq6OJctk6gx3Gmnf78tfG1elrT4WkQHDW8zH wd+cINYmrbZgdcAylu76qZt065fKjyna+3WgxZqjsnYpq3HkKJzEfoO9wlF8PT5QYWQv pLCzsUMfyVtPWqBRe82qIFABiVQJCW1dG3D/E70KDPSClKMMLsPP2FfscgpvYnapAUsU UXcQ== X-Gm-Message-State: APjAAAVq3LanLxNMuyhSIppSBWcs4qdrjW7DUGflgUF0paut5L1WlPF5 oTDd5Z2j8f9t6OPLwkHKWCc= X-Google-Smtp-Source: APXvYqypAg+OMiGpF9jMVSE2fuO42spKkUkoADsgvUck8F6X0iNjNGHcXhtOl3HMpFpChKjhPKo/og== X-Received: by 2002:a5d:4583:: with SMTP id p3mr4996810wrq.114.1552293223181; Mon, 11 Mar 2019 01:33:43 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x17sm19683835wrd.95.2019.03.11.01.33.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 01:33:42 -0700 (PDT) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 2/6] trace-cmd: Fix "trace-cmd reset -a -d" segfault Date: Mon, 11 Mar 2019 10:33:35 +0200 Message-Id: <20190311083339.21581-3-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311083339.21581-1-tstoyanov@vmware.com> References: <20190311083339.21581-1-tstoyanov@vmware.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 This patch fixes a segfault when "trace-cmd reset -a -d" is executed and there is at least one ftrace instance created. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index fc658b2..d7267fe 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -4472,14 +4472,14 @@ void trace_reset(int argc, char **argv) case 'a': last_specified_all = 1; add_all_instances(); - for_each_instance(instance) { - instance->flags |= BUFFER_FL_KEEP; + for_each_instance(inst) { + inst->flags |= BUFFER_FL_KEEP; } break; case 'd': if (last_specified_all) { for_each_instance(inst) { - instance->flags &= ~BUFFER_FL_KEEP; + inst->flags &= ~BUFFER_FL_KEEP; } } else { if (is_top_instance(instance)) From patchwork Mon Mar 11 08:33:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10846877 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 C61C217DF for ; Mon, 11 Mar 2019 08:33:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2F9028F78 for ; Mon, 11 Mar 2019 08:33:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A77BD28F7A; Mon, 11 Mar 2019 08:33:46 +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=-7.9 required=2.0 tests=BAYES_00,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 4752828F78 for ; Mon, 11 Mar 2019 08:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726897AbfCKIdq (ORCPT ); Mon, 11 Mar 2019 04:33:46 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54500 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbfCKIdq (ORCPT ); Mon, 11 Mar 2019 04:33:46 -0400 Received: by mail-wm1-f67.google.com with SMTP id f3so3423162wmj.4 for ; Mon, 11 Mar 2019 01:33:44 -0700 (PDT) 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=HjgYILSVk6MYR5w1Q9TxlsvwEb/cp6vZNW3Z/pHTu9g=; b=F8FgSOaM9pchGOpLr/bMujImkSiXlg+AHFw9rCfwyt8opnb/qnRNvVS0Il/dIpUCGJ hO5t9XQwcdDRKKu4XW760d1l3ZsfcU5OuTNC6Bgleeuo87vGhMcc8xGMulwvMV/DZOOp rfs2tVjI/koVYk4b04rdwmSfvqG9yFwTLQBrOUweTffVB+5saGar51H3Ld56hn7gqsax /DAgZS1/PVHFEI5gtYHPudbZiVIxd5xcCGXjOmgdKot6eM1DqBWAFSphlBqm2P4fvaC4 I8zcPk7kxdAv9ymIILkC17hU7NlZLNVdic46m9JURMpWqy94Q6g1HloyasmBhg2MoSRz SINA== X-Gm-Message-State: APjAAAV/bej+e7oesm0+n0otwkUh/XW5MwMWwYvb2NzWthZV8ZA4L/sN l2gvQHpbv1ngSEj4jSK5NgCDF1yr X-Google-Smtp-Source: APXvYqxvoifdyGhpkwA9MFb4T8AGFkdHRlZfhpTCEr0eXw/HphBg5NhOL/vv75bolUFzHEp3V5TYZw== X-Received: by 2002:a1c:6506:: with SMTP id z6mr15916594wmb.153.1552293224271; Mon, 11 Mar 2019 01:33:44 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x17sm19683835wrd.95.2019.03.11.01.33.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 01:33:43 -0700 (PDT) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 3/6] trace-cmd: Fix "trace-cmd reset" command to restore default clock Date: Mon, 11 Mar 2019 10:33:36 +0200 Message-Id: <20190311083339.21581-4-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311083339.21581-1-tstoyanov@vmware.com> References: <20190311083339.21581-1-tstoyanov@vmware.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 reset" command should restore ftrace to its default state. This patch sets "tracing/trace_clock" to its default value "local", when the "trace-cmd reset" command is executed. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index d7267fe..6972b9f 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3793,6 +3793,14 @@ static void clear_filters(void) clear_instance_filters(instance); } +static void reset_clock(void) +{ + struct buffer_instance *instance; + + for_all_instances(instance) + write_instance_file(instance, "trace_clock", "local", "clock"); +} + static void clear_triggers(void) { struct buffer_instance *instance; @@ -4494,6 +4502,8 @@ void trace_reset(int argc, char **argv) set_buffer_size(); clear_filters(); clear_triggers(); + /* set clock to "local" */ + reset_clock(); tracecmd_remove_instances(); clear_func_filters(); /* restore tracing_on to 1 */ From patchwork Mon Mar 11 08:33:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10846879 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 EDAB717DF for ; Mon, 11 Mar 2019 08:33:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAA8528F78 for ; Mon, 11 Mar 2019 08:33:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE18328F7C; Mon, 11 Mar 2019 08:33:48 +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=-7.9 required=2.0 tests=BAYES_00,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 6526A28F78 for ; Mon, 11 Mar 2019 08:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726921AbfCKIds (ORCPT ); Mon, 11 Mar 2019 04:33:48 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35997 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfCKIds (ORCPT ); Mon, 11 Mar 2019 04:33:48 -0400 Received: by mail-wm1-f67.google.com with SMTP id j125so3345656wmj.1 for ; Mon, 11 Mar 2019 01:33:45 -0700 (PDT) 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=3uXkHmgoem1W6QSbvVaB2yCFnWFJS+wkZ5OZzrrk0Tw=; b=jqPm0xTilHUlXAFkaIJBmNu2SqfIlYf4yjCpFkXD3ASCppLAf6ouqTSyHS842+RXuI e8vuB2sAO05jSizettK2AYlqFhpd4SEECWAY2wM91/sKVwsJ8oriz19o0mC0IHFsw2dZ mymItqPr7rUg/JhHvgPENH5dcNJkl+5dAVgXmILF88rySOjpOQPUpyPfxH8DoFaWdYCK bLt8CCNu1IaXuf38rgsLPhTaFaak1J81CFyTV5XbgXY+JqVd3cb/QyMrObvCihV7GH2L 20LNHxXKoIOGUAC+EGZOiCI/1gHZ7NSd30eUPIxkxbTD1E/YyoloO80TfBKTNF9uszCD QLcQ== X-Gm-Message-State: APjAAAXXpcXBvFty81UzgN70HlpQoMupqiNuYHBkRSZP99gQBCiuvnDO YsySWt/nnVE9woakIz+2l90= X-Google-Smtp-Source: APXvYqxO5dUvxd4DrLVOIQOntjlMAOoYCmrdPFdGnsrT6DfSUNP1QP0Acn0GR0XP1u1EIXLl5QrK4Q== X-Received: by 2002:a1c:c60b:: with SMTP id w11mr16271786wmf.39.1552293225199; Mon, 11 Mar 2019 01:33:45 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x17sm19683835wrd.95.2019.03.11.01.33.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 01:33:44 -0700 (PDT) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 4/6] trace-cmd: Reafctored add_event_pid()to utilize write_instance_file() Date: Mon, 11 Mar 2019 10:33:37 +0200 Message-Id: <20190311083339.21581-5-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311083339.21581-1-tstoyanov@vmware.com> References: <20190311083339.21581-1-tstoyanov@vmware.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 This patch changes add_event_pid() to utilize write_instance_file() for writing set_event_pid instance file, instead of directly opening it. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 89 +++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 6972b9f..a398723 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -1094,30 +1094,64 @@ static void update_sched_events(struct buffer_instance *instance, int pid) static int open_instance_fd(struct buffer_instance *instance, const char *file, int flags); -static void add_event_pid(const char *buf, int len) +static int write_file(const char *file, const char *str, const char *type) { - struct buffer_instance *instance; + char buf[BUFSIZ]; int fd; + int ret; - for_all_instances(instance) { - fd = open_instance_fd(instance, "set_event_pid", O_WRONLY); - write(fd, buf, len); + fd = open(file, O_WRONLY | O_TRUNC); + if (fd < 0) + die("opening to '%s'", file); + ret = write(fd, str, strlen(str)); + close(fd); + if (ret < 0 && type) { + /* write failed */ + fd = open(file, O_RDONLY); + if (fd < 0) + die("writing to '%s'", file); + /* the filter has the error */ + while ((ret = read(fd, buf, BUFSIZ)) > 0) + fprintf(stderr, "%.*s", ret, buf); + die("Failed %s of %s\n", type, file); close(fd); } + return ret; +} + +static int +write_instance_file(struct buffer_instance *instance, + const char *file, const char *str, const char *type) +{ + char *path; + int ret; + + path = get_instance_file(instance, file); + ret = write_file(path, str, type); + tracecmd_put_tracing_file(path); + + return ret; +} + +static void add_event_pid(const char *buf) +{ + struct buffer_instance *instance; + + for_all_instances(instance) + write_instance_file(instance, "set_event_pid", buf, "event_pid"); } static void add_new_filter_pid(int pid) { struct buffer_instance *instance; char buf[100]; - int len; add_filter_pid(pid, 0); - len = sprintf(buf, "%d", pid); + sprintf(buf, "%d", pid); update_ftrace_pid(buf, 0); if (have_set_event_pid) - return add_event_pid(buf, len); + return add_event_pid(buf); common_pid_filter = append_pid_filter(common_pid_filter, "common_pid", pid); @@ -1596,45 +1630,6 @@ static void reset_events(void) reset_events_instance(instance); } -static int write_file(const char *file, const char *str, const char *type) -{ - char buf[BUFSIZ]; - int fd; - int ret; - - fd = open(file, O_WRONLY | O_TRUNC); - if (fd < 0) - die("opening to '%s'", file); - ret = write(fd, str, strlen(str)); - close(fd); - if (ret < 0 && type) { - /* write failed */ - fd = open(file, O_RDONLY); - if (fd < 0) - die("writing to '%s'", file); - /* the filter has the error */ - while ((ret = read(fd, buf, BUFSIZ)) > 0) - fprintf(stderr, "%.*s", ret, buf); - die("Failed %s of %s\n", type, file); - close(fd); - } - return ret; -} - -static int -write_instance_file(struct buffer_instance *instance, - const char *file, const char *str, const char *type) -{ - char *path; - int ret; - - path = get_instance_file(instance, file); - ret = write_file(path, str, type); - tracecmd_put_tracing_file(path); - - return ret; -} - enum { STATE_NEWLINE, STATE_SKIP, From patchwork Mon Mar 11 08:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10846881 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 087C414DE for ; Mon, 11 Mar 2019 08:33:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA62928F79 for ; Mon, 11 Mar 2019 08:33:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF08028F7F; Mon, 11 Mar 2019 08:33:48 +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=-7.9 required=2.0 tests=BAYES_00,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 8DBAC28F79 for ; Mon, 11 Mar 2019 08:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725850AbfCKIds (ORCPT ); Mon, 11 Mar 2019 04:33:48 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35998 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbfCKIds (ORCPT ); Mon, 11 Mar 2019 04:33:48 -0400 Received: by mail-wm1-f67.google.com with SMTP id j125so3345701wmj.1 for ; Mon, 11 Mar 2019 01:33:47 -0700 (PDT) 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=Hx45oLWm3cO7y7qj3wq6+r7jPLgvW5RIhXHj5w/9PtQ=; b=JA1xu2IIaFDqOAMLElqsNFLBmGaIvMN+js91geUlvCvjB/MWCbd5vuVCEKbnc7ECG+ CRXWRIS7Kof8EO9E+RapJ1f6SvZC0W5RZaY/Pc3Aa7Hkqh47c0u3jayBIZRvyFxs4avp 5v3Pw9+qNKbJbo1fZLt78UaeMDlTflVIHIBrv93T+UkOGr+IVL+OwRqhFrrDAu21Zght bfGYMAx4M6iaSMiPlqmQ3jbdSMzZA3IcwGo6JWHzeZb118sgy20yGzIIgINKebSoIrQJ nW4gfcpZN4Swoo6R7H4Gl2k8QI2ozhXyj8U6stFTlstxVdK4FkRkvH4cd3bO0gMBbb5G 377g== X-Gm-Message-State: APjAAAU3t4qPWKnx6W8/PZblCpsw7Xrbq7bwhYdFdW+vkmc0FP3Ro27p Js1vvqLmG9uiwcc29NnDNMd6RbPR X-Google-Smtp-Source: APXvYqw9NFwSu6WNbazfb2sxpnJsDnFo9CZlsCWdJpj+E3Ewqdq8u3n/DOmG/jAoY7huSMKTHMuT7g== X-Received: by 2002:a1c:2097:: with SMTP id g145mr15823311wmg.81.1552293226356; Mon, 11 Mar 2019 01:33:46 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x17sm19683835wrd.95.2019.03.11.01.33.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 01:33:45 -0700 (PDT) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 5/6] trace-cmd: Fix "trace-cmd reset" command to restore the default value of set_event_pid Date: Mon, 11 Mar 2019 10:33:38 +0200 Message-Id: <20190311083339.21581-6-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311083339.21581-1-tstoyanov@vmware.com> References: <20190311083339.21581-1-tstoyanov@vmware.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 reset" command should restore ftrace to its default state. This patch sets "tracing/set_event_pid" to an empty string, when the "trace-cmd reset" command is executed. Signed-off-by: Tzvetomir Stoyanov --- tracecmd/trace-record.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index a398723..bdf0c02 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3796,6 +3796,12 @@ static void reset_clock(void) write_instance_file(instance, "trace_clock", "local", "clock"); } +static void reset_event_pid(void) +{ + add_event_pid(""); +} + + static void clear_triggers(void) { struct buffer_instance *instance; @@ -4499,6 +4505,7 @@ void trace_reset(int argc, char **argv) clear_triggers(); /* set clock to "local" */ reset_clock(); + reset_event_pid(); tracecmd_remove_instances(); clear_func_filters(); /* restore tracing_on to 1 */ From patchwork Mon Mar 11 08:33:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzvetomir Stoyanov X-Patchwork-Id: 10846883 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 87E8314DE for ; Mon, 11 Mar 2019 08:33:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 737FD28F78 for ; Mon, 11 Mar 2019 08:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6808A28F7A; Mon, 11 Mar 2019 08:33:50 +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=-7.9 required=2.0 tests=BAYES_00,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 ED96528F78 for ; Mon, 11 Mar 2019 08:33:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725869AbfCKIdt (ORCPT ); Mon, 11 Mar 2019 04:33:49 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33259 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726914AbfCKIdt (ORCPT ); Mon, 11 Mar 2019 04:33:49 -0400 Received: by mail-wr1-f66.google.com with SMTP id i8so4037862wrm.0 for ; Mon, 11 Mar 2019 01:33:48 -0700 (PDT) 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=mPynn1eM53ByCP+zSRSpTpmiYsR8i5WpVTZY9CcWqRg=; b=QtFwKrwpcFvfKzi33r08m7KqDqRldXdPIJfj26tdWqsEkbXbgtWkoyCFzZhU9CWWzY xB2CKGpSZcYgEL57itggj35G+Q9+dALbYAIZTezP4Sbkx/bXs1FyaI35KzRY/hzZf2Gr SYez2N9s7kkt8T9wcEHZP4/I63U5P7P2AFyjztPyaRvyxzKjjJPgd/Dso62ztibToRRS y77/K+L6/9mG4cBwtI6m5pV/wg8DF003q/KG84Njoc9KhaQXnk7qGHdBKVXO/M7dvso7 O9HgsggCKlxBnG+cFQYQrMrXNkG+8j4PvpYfjOOhG/apaVBx1BG6bBkoXqex9NrSbZvZ tvrg== X-Gm-Message-State: APjAAAWgItiRdAlYtRCVyaAwZSgZmrAPxwM/BmsOP0504bHukNHIsRl3 U2KLTW+yKccdvjj3shrt7BXeccPU X-Google-Smtp-Source: APXvYqyuco/yHjiA5csKAzbWw67Efh2cS5AUvamMKocf8SVqUpYdVKiwhxcS0WgTtIx8/Vg5cpdrJA== X-Received: by 2002:adf:e988:: with SMTP id h8mr5108747wrm.260.1552293227378; Mon, 11 Mar 2019 01:33:47 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x17sm19683835wrd.95.2019.03.11.01.33.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Mar 2019 01:33:46 -0700 (PDT) From: Tzvetomir Stoyanov To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v4 6/6] trace-cmd: Reafctored reset_max_latency() to utilize write_instance_file() Date: Mon, 11 Mar 2019 10:33:39 +0200 Message-Id: <20190311083339.21581-7-tstoyanov@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311083339.21581-1-tstoyanov@vmware.com> References: <20190311083339.21581-1-tstoyanov@vmware.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 This patch changes reset_max_latency() to utilize write_instance_file() for writing set_event_pid instance file, instead of directly opening it. It also changes the function to work per instance. Signed-off-by: Tzvetomir Stoyanov Signed-off-by: Steven Rostedt (VMware) --- tracecmd/trace-record.c | 99 ++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index bdf0c02..dfbb0cd 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -814,19 +814,49 @@ static void clear_trace(void) fclose(fp); } -static void reset_max_latency(void) +static int write_file(const char *file, const char *str, const char *type) +{ + char buf[BUFSIZ]; + int fd; + int ret; + + fd = open(file, O_WRONLY | O_TRUNC); + if (fd < 0) + die("opening to '%s'", file); + ret = write(fd, str, strlen(str)); + close(fd); + if (ret < 0 && type) { + /* write failed */ + fd = open(file, O_RDONLY); + if (fd < 0) + die("writing to '%s'", file); + /* the filter has the error */ + while ((ret = read(fd, buf, BUFSIZ)) > 0) + fprintf(stderr, "%.*s", ret, buf); + die("Failed %s of %s\n", type, file); + close(fd); + } + return ret; +} + +static int +write_instance_file(struct buffer_instance *instance, + const char *file, const char *str, const char *type) { - FILE *fp; char *path; + int ret; - /* reset the trace */ - path = tracecmd_get_tracing_file("tracing_max_latency"); - fp = fopen(path, "w"); - if (!fp) - die("writing to '%s'", path); + path = get_instance_file(instance, file); + ret = write_file(path, str, type); tracecmd_put_tracing_file(path); - fwrite("0", 1, 1, fp); - fclose(fp); + + return ret; +} + +static void reset_max_latency(struct buffer_instance *instance) +{ + write_instance_file(instance, + "tracing_max_latency", "0", "max_latency"); } static void add_filter_pid(int pid, int exclude) @@ -1094,45 +1124,6 @@ static void update_sched_events(struct buffer_instance *instance, int pid) static int open_instance_fd(struct buffer_instance *instance, const char *file, int flags); -static int write_file(const char *file, const char *str, const char *type) -{ - char buf[BUFSIZ]; - int fd; - int ret; - - fd = open(file, O_WRONLY | O_TRUNC); - if (fd < 0) - die("opening to '%s'", file); - ret = write(fd, str, strlen(str)); - close(fd); - if (ret < 0 && type) { - /* write failed */ - fd = open(file, O_RDONLY); - if (fd < 0) - die("writing to '%s'", file); - /* the filter has the error */ - while ((ret = read(fd, buf, BUFSIZ)) > 0) - fprintf(stderr, "%.*s", ret, buf); - die("Failed %s of %s\n", type, file); - close(fd); - } - return ret; -} - -static int -write_instance_file(struct buffer_instance *instance, - const char *file, const char *str, const char *type) -{ - char *path; - int ret; - - path = get_instance_file(instance, file); - ret = write_file(path, str, type); - tracecmd_put_tracing_file(path); - - return ret; -} - static void add_event_pid(const char *buf) { struct buffer_instance *instance; @@ -1931,6 +1922,14 @@ static int read_tracing_on(struct buffer_instance *instance) return ret; } +static void reset_max_latency_instance(void) +{ + struct buffer_instance *instance; + + for_all_instances(instance) + reset_max_latency(instance); +} + void tracecmd_enable_tracing(void) { struct buffer_instance *instance; @@ -1941,7 +1940,7 @@ void tracecmd_enable_tracing(void) write_tracing_on(instance, 1); if (latency) - reset_max_latency(); + reset_max_latency_instance(); } void tracecmd_disable_tracing(void) @@ -3801,7 +3800,6 @@ static void reset_event_pid(void) add_event_pid(""); } - static void clear_triggers(void) { struct buffer_instance *instance; @@ -4506,6 +4504,7 @@ void trace_reset(int argc, char **argv) /* set clock to "local" */ reset_clock(); reset_event_pid(); + reset_max_latency_instance(); tracecmd_remove_instances(); clear_func_filters(); /* restore tracing_on to 1 */