Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422951AbbEOHyA (ORCPT ); Fri, 15 May 2015 03:54:00 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:62910 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422716AbbEOHxt (ORCPT ); Fri, 15 May 2015 03:53:49 -0400 From: Wang Nan To: , , , , , , , , , , , CC: , , , Subject: [RFC PATCH v2 37/37] tools perf bpf: passes generated arguments to cmd_record. Date: Fri, 15 May 2015 07:51:30 +0000 Message-ID: <1431676290-1230-38-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1431676290-1230-1-git-send-email-wangnan0@huawei.com> References: <1431676290-1230-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.200] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2064 Lines: 72 This patch utilizes previous introduced bpf_load_gen_argv() to generate arguments for cmd_record. We should try to avoid triggering atexit() unprobe handler because the state of the process is uncommon. For example, stdio and stderr are closed. Moreover, we are unable to ensure atexit() handler will be called at every situations. Signed-off-by: Wang Nan --- tools/perf/builtin-bpf.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/tools/perf/builtin-bpf.c b/tools/perf/builtin-bpf.c index 94978c7..c818c9f 100644 --- a/tools/perf/builtin-bpf.c +++ b/tools/perf/builtin-bpf.c @@ -78,36 +78,20 @@ static int add_bpf_object_file(const struct option *opt, static int start_bpf_record(int argc, const char **argv) { - int i, new_argc, err, pos = 0; + int new_argc, err; const char **new_argv; - new_argc = argc + 1; - new_argv = malloc((new_argc + 1) * sizeof(const char *)); - if (!new_argv) { - pr_err("malloc failed\n"); - return -ENOMEM; - } - bzero(new_argv, sizeof(const char *) * (new_argc + 1)); - - new_argv[pos++] = strdup("bpf record --"); - - for (i = 0; i < argc; i++) { - new_argv[pos++] = strdup(argv[i]); - if (!new_argv[pos - 1]) { - pr_err("strdup failed\n"); - err = -ENOMEM; - goto errout; - } + if ((err = bpf_load_gen_argv(&new_argc, &new_argv, + argc, argv, + "bpf record --"))) + { + pr_err("Failed to generate arguments for record\n"); + return err; } - return cmd_record(new_argc, new_argv, NULL); - -errout: - if (new_argv) { - for (i = 0; i < pos; i++) - free((void *)new_argv[i]); - free(new_argv); - } + /* new_argv won't be freed because cmd_record may change it. */ + err = cmd_record(new_argc, new_argv, NULL); + bpf_unprobe(); return err; } -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/