[RFC PATCH v2 37/37] tools perf bpf: passes generated arguments to cmd_record.

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


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