From patchwork Sat Nov 26 07:03:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 84235 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp386299qgi; Fri, 25 Nov 2016 23:08:25 -0800 (PST) X-Received: by 10.98.192.148 with SMTP id g20mr11629878pfk.36.1480144105613; Fri, 25 Nov 2016 23:08:25 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 84si47837298pgg.198.2016.11.25.23.08.25; Fri, 25 Nov 2016 23:08:25 -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 S1752252AbcKZHIF (ORCPT + 25 others); Sat, 26 Nov 2016 02:08:05 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:19083 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbcKZHHN (ORCPT ); Sat, 26 Nov 2016 02:07:13 -0500 Received: from 172.24.1.36 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CLX90708; Sat, 26 Nov 2016 15:06:25 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Sat, 26 Nov 2016 15:06:17 +0800 From: Wang Nan To: , CC: , , , , , Wang Nan , Jiri Olsa Subject: [PATCH v3 30/30] perf clang jit: Export getpid() to perf hook Date: Sat, 26 Nov 2016 07:03:54 +0000 Message-ID: <20161126070354.141764-31-wangnan0@huawei.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161126070354.141764-1-wangnan0@huawei.com> References: <20161126070354.141764-1-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After this patch perf hooks can retrive pid of perf itself by calling getpid. It is important for excluding event from perf. This commit is also an example to show how to export more helpers to hooked script. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: He Kuang Cc: Jiri Olsa Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/c++/bpf-helper-str.c | 1 + tools/perf/util/c++/clang.cpp | 1 + 2 files changed, 2 insertions(+) -- 2.10.1 diff --git a/tools/perf/util/c++/bpf-helper-str.c b/tools/perf/util/c++/bpf-helper-str.c index f4d6d57..1ad6ec0 100644 --- a/tools/perf/util/c++/bpf-helper-str.c +++ b/tools/perf/util/c++/bpf-helper-str.c @@ -12,6 +12,7 @@ const char clang_builtin_bpf_helper_str[] = "#define SEC(NAME) __attribute__((section(NAME), used))\n" "extern int printf(const char *, ...);\n" "extern int puts(const char *);\n" +"extern int getpid(void);\n" "extern int perf_map_update_elem(void *, void *, void *, void *, unsigned long);\n" "extern int perf_map_lookup_elem(void *, void *, void *, void *);\n" "extern int perf_map_get_next_key(void *, void *, void *, void *);\n" diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp index 5c1efe8..213c58f 100644 --- a/tools/perf/util/c++/clang.cpp +++ b/tools/perf/util/c++/clang.cpp @@ -236,6 +236,7 @@ static std::map exported_funcs = EXPORT(test__clang_callback), EXPORT(printf), EXPORT(puts), + EXPORT(getpid), EXPORT(JIT_HELPER_FUNC_NAME(map_update_elem)), EXPORT(JIT_HELPER_FUNC_NAME(map_lookup_elem)), EXPORT(JIT_HELPER_FUNC_NAME(map_get_next_key)),