[RFC PATCH v2 30/37] tools perf: collect all bpf programs.

From: Wang Nan
Date: Fri May 15 2015 - 03:55:50 EST


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 <wangnan0@xxxxxxxxxx>
---
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/