Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422770AbbEOHxw (ORCPT ); Fri, 15 May 2015 03:53:52 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:62848 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934256AbbEOHxu (ORCPT ); Fri, 15 May 2015 03:53:50 -0400 From: Wang Nan To: , , , , , , , , , , , CC: , , , Subject: [RFC PATCH v2 30/37] tools perf: collect all bpf programs. Date: Fri, 15 May 2015 07:51:23 +0000 Message-ID: <1431676290-1230-31-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: 1884 Lines: 71 This patch collects 'struct bpf_prog_handler *' after opening an object file. Handlers are stored into an array of MAX_PROBES slots. Signed-off-by: Wang Nan --- tools/perf/util/bpf-loader.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 17cd2b6..67bfb62 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -8,6 +8,7 @@ #include "perf.h" #include "debug.h" #include "bpf-loader.h" +#include "probe-finder.h" // for MAX_PROBES #define DEFINE_PRINT_FN(name, level) \ static int libbpf_##name(const char *fmt, ...) \ @@ -32,11 +33,17 @@ static bool libbpf_inited = false; struct { struct bpf_object *objects[MAX_OBJECTS]; size_t nr_objects; + + struct { + struct bpf_prog_handler *prog; + } progs[MAX_PROBES]; + size_t nr_progs; } params; int bpf_prepare_load(const char *filename) { struct bpf_object *obj; + struct bpf_prog_handler *prog; if (!libbpf_inited) libbpf_set_print(libbpf_warning, @@ -57,6 +64,24 @@ int bpf_prepare_load(const char *filename) } params.objects[params.nr_objects++] = obj; + + bpf_obj_for_each_prog(obj, prog) { + const char *title; + + if (params.nr_progs + 1 > MAX_PROBES) { + pr_err("Too many programs. " + "Increase MAX_PROBES\n"); + return -EMFILE; + } + + params.progs[params.nr_progs++].prog = prog; + + if (bpf_prog_get_title(prog, &title, false)) { + pr_err("Unable to get title of a program\n"); + return -EINVAL; + } + pr_debug("bpf: add program '%s'\n", title); + } return 0; } -- 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/