Received: by 10.223.185.116 with SMTP id b49csp660339wrg; Wed, 21 Feb 2018 05:01:11 -0800 (PST) X-Google-Smtp-Source: AH8x225x8HdR8a4wlxw9J49svR81kIS+AbQIW/qGUSoAbK+GePgRtWk79FeKou5kzTw3VqCUxWJ/ X-Received: by 2002:a17:902:51e9:: with SMTP id y96-v6mr3116297plh.344.1519218071211; Wed, 21 Feb 2018 05:01:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519218071; cv=none; d=google.com; s=arc-20160816; b=eGYDtKCYC+1Mwx3EnqwIHEUOqRtxIXRncF/4FQShNqC6TN9OKvcMmkbmSoHXXApqIB AGMLxpqEsR9u16NQ6N+KWw2k4SpKimu0yM9OxKRE1N7lRIJDZ5ox9GUXKDIZKb2SqUhk yJdl+GPHbeT7Q+H/9js3eUqSoj5gYtxw0CuSK4aMfqPuxZshY1j1wfueNJ3osXgjCMi8 7NhPpdlT3y0sU+6g4PwvgF2BsBxwJKoWPCX0ic/qZtaY1OtVruRA5S3bkvUUO8A4iyGC UUwr6wSD+AwfQYC6ANgKGKdTpg2vJEInoliFobb3CSWNQ/M7UOKHyzh0jSt5srkWPVbd 05pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=40gyYiWwbg1wIUodyY0id8s55e6mzYS5UkNLXe7gVLU=; b=swlLSYzx/XIj4qkh59fr0zEYTHqYJv2f4PjrOzErrFvYQBVEKe9xWyfMn7dw8mjy9Z GVfecSYkl6icZn+vnu1BQuMv6XZH1Nr35LwC1iJ/m8OJNJYY/SAvzcfL7HY/OWTuVrRV zKDZctA1SraDz1XACeEKQdAwevXnoLmWqVul2jTCeCv/ynQsBqOF0ZkNNvgIVfCKqXcR yIPvAJsCeurCU97dgDN7YkGX0vUVGFNp5ibvxk1/ycfs01VdyOHmvswX0Y8/5YIahX7U W3A4lHAAYBkW7n6ra4MRSGrtDLo3yOXIC5nXz53ZdyOj+SBApe9aJfV7s1e0UdgXbJWp Up6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c74si461366pfj.339.2018.02.21.05.00.56; Wed, 21 Feb 2018 05:01:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933065AbeBUK1T (ORCPT + 99 others); Wed, 21 Feb 2018 05:27:19 -0500 Received: from terminus.zytor.com ([198.137.202.136]:33509 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932807AbeBUK1P (ORCPT ); Wed, 21 Feb 2018 05:27:15 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1LAQAkG030484; Wed, 21 Feb 2018 02:26:10 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1LAQAan030478; Wed, 21 Feb 2018 02:26:10 -0800 Date: Wed, 21 Feb 2018 02:26:10 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Changbin Du Message-ID: Cc: namhyung@kernel.org, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, acme@redhat.com, jolsa@redhat.com, changbin.du@intel.com, peterz@infradead.org Reply-To: acme@redhat.com, peterz@infradead.org, changbin.du@intel.com, jolsa@redhat.com, linux-kernel@vger.kernel.org, namhyung@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org In-Reply-To: <1519007609-14551-1-git-send-email-changbin.du@intel.com> References: <1519007609-14551-1-git-send-email-changbin.du@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf ftrace: Append an EOL when write tracing files Git-Commit-ID: 63cd02d84be5f7b3bc4f8fbb93cc1f871f84ae1d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 63cd02d84be5f7b3bc4f8fbb93cc1f871f84ae1d Gitweb: https://git.kernel.org/tip/63cd02d84be5f7b3bc4f8fbb93cc1f871f84ae1d Author: Changbin Du AuthorDate: Mon, 19 Feb 2018 10:33:29 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 19 Feb 2018 09:49:12 -0300 perf ftrace: Append an EOL when write tracing files Before this change, the '--graph-funcs', '--nograph-funcs' and '--trace-funcs' options didn't work as expected when the doesn't exist. Because the kernel side hid possible errors. $ sudo ./perf ftrace -a --graph-depth 1 --graph-funcs abcdefg 0) 0.140 us | rcu_all_qs(); 3) 0.304 us | mutex_unlock(); 0) 0.153 us | find_vma(); 3) 0.088 us | __fsnotify_parent(); 0) 6.145 us | handle_mm_fault(); 3) 0.089 us | fsnotify(); 3) 0.161 us | __sb_end_write(); 3) 0.710 us | SyS_close(); 3) 7.848 us | exit_to_usermode_loop(); On the example above, I specified the function filter 'abcdefg' but all functions are enabled. The expected result is for all functions to be filtered, since there is no such function ('abcdefg') The original fix is to make the kernel support '\0' as end of string: https://lkml.org/lkml/2018/1/16/116 But above fix cannot be compatible with old kernels. Then Namhyung Kim suggest adding a space after function name. This patch will append an '\n' when write tracing file. After this fix, the perf will report correct error state. Also let it print an error if reset_tracing_files() fails. Committer testing: Now it prints: # perf ftrace -a --graph-depth 1 --graph-funcs abcdefg failed to set tracing filters # And for an existing function: # perf ftrace -a --graph-depth 1 --graph-funcs SyS_open 3) | SyS_open() { 3) ! 494.899 us | } 0) + 23.910 us | SyS_open(); 1) + 17.115 us | SyS_open(); 1) + 13.900 us | SyS_open(); ------------------------------------------ 3) qemu-sy-2817 => pickup-1290 ------------------------------------------ 3) + 20.021 us | SyS_open(); # Signed-off-by: Changbin Du Tested-by: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1519007609-14551-1-git-send-email-changbin.du@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-ftrace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 25a42ac..f42f228 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -72,6 +72,7 @@ static int __write_tracing_file(const char *name, const char *val, bool append) ssize_t size = strlen(val); int flags = O_WRONLY; char errbuf[512]; + char *val_copy; file = get_tracing_file(name); if (!file) { @@ -91,12 +92,23 @@ static int __write_tracing_file(const char *name, const char *val, bool append) goto out; } - if (write(fd, val, size) == size) + /* + * Copy the original value and append a '\n'. Without this, + * the kernel can hide possible errors. + */ + val_copy = strdup(val); + if (!val_copy) + goto out_close; + val_copy[size] = '\n'; + + if (write(fd, val_copy, size + 1) == size + 1) ret = 0; else pr_debug("write '%s' to tracing/%s failed: %s\n", val, name, str_error_r(errno, errbuf, sizeof(errbuf))); + free(val_copy); +out_close: close(fd); out: put_tracing_file(file); @@ -280,8 +292,10 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) signal(SIGCHLD, sig_handler); signal(SIGPIPE, sig_handler); - if (reset_tracing_files(ftrace) < 0) + if (reset_tracing_files(ftrace) < 0) { + pr_err("failed to reset ftrace\n"); goto out; + } /* reset ftrace buffer */ if (write_tracing_file("trace", "0") < 0)