perf probe: Add --quiet option to suppress output result message
[firefly-linux-kernel-4.4.55.git] / tools / perf / util / probe-event.c
index bf39c23b275ddee156cfcb972b30c2e5f5491e08..28eb1417cb2a3fc5d3acebc2280cf37ac79ad778 100644 (file)
@@ -184,7 +184,8 @@ static struct dso *kernel_get_module_dso(const char *module)
        const char *vmlinux_name;
 
        if (module) {
-               list_for_each_entry(dso, &host_machine->kernel_dsos, node) {
+               list_for_each_entry(dso, &host_machine->kernel_dsos.head,
+                                   node) {
                        if (strncmp(dso->short_name + 1, module,
                                    dso->short_name_len - 2) == 0)
                                goto found;
@@ -573,7 +574,7 @@ static int get_real_path(const char *raw_path, const char *comp_dir,
 
 static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
 {
-       char buf[LINEBUF_SIZE];
+       char buf[LINEBUF_SIZE], sbuf[STRERR_BUFSIZE];
        const char *color = show_num ? "" : PERF_COLOR_BLUE;
        const char *prefix = NULL;
 
@@ -593,7 +594,8 @@ static int __show_one_line(FILE *fp, int l, bool skip, bool show_num)
        return 1;
 error:
        if (ferror(fp)) {
-               pr_warning("File read error: %s\n", strerror(errno));
+               pr_warning("File read error: %s\n",
+                          strerror_r(errno, sbuf, sizeof(sbuf)));
                return -1;
        }
        return 0;
@@ -626,6 +628,7 @@ static int __show_line_range(struct line_range *lr, const char *module)
        FILE *fp;
        int ret;
        char *tmp;
+       char sbuf[STRERR_BUFSIZE];
 
        /* Search a line range */
        dinfo = open_debuginfo(module, false);
@@ -662,7 +665,7 @@ static int __show_line_range(struct line_range *lr, const char *module)
        fp = fopen(lr->path, "r");
        if (fp == NULL) {
                pr_warning("Failed to open %s: %s\n", lr->path,
-                          strerror(errno));
+                          strerror_r(errno, sbuf, sizeof(sbuf)));
                return -errno;
        }
        /* Skip to starting line number */
@@ -695,11 +698,11 @@ end:
        return ret;
 }
 
-int show_line_range(struct line_range *lr, const char *module)
+int show_line_range(struct line_range *lr, const char *module, bool user)
 {
        int ret;
 
-       ret = init_symbol_maps(false);
+       ret = init_symbol_maps(user);
        if (ret < 0)
                return ret;
        ret = __show_line_range(lr, module);
@@ -774,7 +777,7 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs,
        int i, ret = 0;
        struct debuginfo *dinfo;
 
-       ret = init_symbol_maps(false);
+       ret = init_symbol_maps(pevs->uprobes);
        if (ret < 0)
                return ret;
 
@@ -820,7 +823,8 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev,
 }
 
 int show_line_range(struct line_range *lr __maybe_unused,
-                   const char *module __maybe_unused)
+                   const char *module __maybe_unused,
+                   bool user __maybe_unused)
 {
        pr_warning("Debuginfo-analysis is not supported.\n");
        return -ENOSYS;
@@ -1410,8 +1414,7 @@ int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
 
        return tmp - buf;
 error:
-       pr_debug("Failed to synthesize perf probe argument: %s\n",
-                strerror(-ret));
+       pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
        return ret;
 }
 
@@ -1460,8 +1463,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
 
        return buf;
 error:
-       pr_debug("Failed to synthesize perf probe point: %s\n",
-                strerror(-ret));
+       pr_debug("Failed to synthesize perf probe point: %d\n", ret);
        free(buf);
        return NULL;
 }
@@ -1787,7 +1789,7 @@ static void clear_probe_trace_event(struct probe_trace_event *tev)
 
 static void print_open_warning(int err, bool is_kprobe)
 {
-       char sbuf[128];
+       char sbuf[STRERR_BUFSIZE];
 
        if (err == -ENOENT) {
                const char *config;
@@ -1817,7 +1819,7 @@ static void print_both_open_warning(int kerr, int uerr)
                pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
                           "or/and CONFIG_UPROBE_EVENTS.\n");
        else {
-               char sbuf[128];
+               char sbuf[STRERR_BUFSIZE];
                pr_warning("Failed to open kprobe events: %s.\n",
                           strerror_r(-kerr, sbuf, sizeof(sbuf)));
                pr_warning("Failed to open uprobe events: %s.\n",
@@ -1908,21 +1910,21 @@ static int show_perf_probe_event(struct perf_probe_event *pev,
        if (ret < 0)
                return ret;
 
-       printf("  %-20s (on %s", buf, place);
+       pr_info("  %-20s (on %s", buf, place);
        if (module)
-               printf(" in %s", module);
+               pr_info(" in %s", module);
 
        if (pev->nargs > 0) {
-               printf(" with");
+               pr_info(" with");
                for (i = 0; i < pev->nargs; i++) {
                        ret = synthesize_perf_probe_arg(&pev->args[i],
                                                        buf, 128);
                        if (ret < 0)
                                break;
-                       printf(" %s", buf);
+                       pr_info(" %s", buf);
                }
        }
-       printf(")\n");
+       pr_info(")\n");
        free(place);
        return ret;
 }
@@ -2038,6 +2040,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
 {
        int ret = 0;
        char *buf = synthesize_probe_trace_command(tev);
+       char sbuf[STRERR_BUFSIZE];
 
        if (!buf) {
                pr_debug("Failed to synthesize probe trace event.\n");
@@ -2049,7 +2052,7 @@ static int write_probe_trace_event(int fd, struct probe_trace_event *tev)
                ret = write(fd, buf, strlen(buf));
                if (ret <= 0)
                        pr_warning("Failed to write event: %s\n",
-                                  strerror(errno));
+                                  strerror_r(errno, sbuf, sizeof(sbuf)));
        }
        free(buf);
        return ret;
@@ -2063,7 +2066,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
        /* Try no suffix */
        ret = e_snprintf(buf, len, "%s", base);
        if (ret < 0) {
-               pr_debug("snprintf() failed: %s\n", strerror(-ret));
+               pr_debug("snprintf() failed: %d\n", ret);
                return ret;
        }
        if (!strlist__has_entry(namelist, buf))
@@ -2079,7 +2082,7 @@ static int get_new_event_name(char *buf, size_t len, const char *base,
        for (i = 1; i < MAX_EVENT_INDEX; i++) {
                ret = e_snprintf(buf, len, "%s_%d", base, i);
                if (ret < 0) {
-                       pr_debug("snprintf() failed: %s\n", strerror(-ret));
+                       pr_debug("snprintf() failed: %d\n", ret);
                        return ret;
                }
                if (!strlist__has_entry(namelist, buf))
@@ -2121,7 +2124,7 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
        }
 
        ret = 0;
-       printf("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
+       pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
        for (i = 0; i < ntevs; i++) {
                tev = &tevs[i];
                if (pev->event)
@@ -2176,8 +2179,8 @@ static int __add_probe_trace_events(struct perf_probe_event *pev,
 
        if (ret >= 0) {
                /* Show how to use the event. */
-               printf("\nYou can now use it in all perf tools, such as:\n\n");
-               printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
+               pr_info("\nYou can now use it in all perf tools, such as:\n\n");
+               pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
                         tev->event);
        }
 
@@ -2441,10 +2444,11 @@ static int __del_trace_probe_event(int fd, struct str_node *ent)
                goto error;
        }
 
-       printf("Removed event: %s\n", ent->s);
+       pr_info("Removed event: %s\n", ent->s);
        return 0;
 error:
-       pr_warning("Failed to delete event: %s\n", strerror(-ret));
+       pr_warning("Failed to delete event: %s\n",
+                  strerror_r(-ret, buf, sizeof(buf)));
        return ret;
 }