Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf probe: List probes in stdout

Since commit 5e17b28f1e24 ("perf probe: Add --quiet option to
suppress output result message") have replaced printf with pr_info,
perf probe -l outputs its result in stderr. However, that is not
what the commit expected.

E.g.:

# perf probe -l > /dev/null
probe:vfs_read (on vfs_read@ksrc/linux-3/fs/read_write.c)

With this fix:

# perf probe -l > list
# cat list
probe:vfs_read (on vfs_read@ksrc/linux-3/fs/read_write.c)

Of course, --quiet(-q) still works on --add/--del.

# perf probe -q vfs_write
# perf probe -l
probe:vfs_read (on vfs_read@ksrc/linux-3/fs/read_write.c)
probe:vfs_write (on vfs_write@ksrc/linux-3/fs/read_write.c)
-----

Reported-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150613013116.24402.2923.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Masami Hiramatsu and committed by
Arnaldo Carvalho de Melo
ba7ecb02 a35489a6

+35 -14
+35 -14
tools/perf/util/probe-event.c
··· 2126 2126 return NULL; 2127 2127 } 2128 2128 2129 - /* Show an event */ 2130 - static int show_perf_probe_event(struct perf_probe_event *pev, 2131 - const char *module) 2129 + static int perf_probe_event__sprintf(struct perf_probe_event *pev, 2130 + const char *module, 2131 + struct strbuf *result) 2132 2132 { 2133 2133 int i, ret; 2134 2134 char buf[128]; ··· 2141 2141 2142 2142 ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event); 2143 2143 if (ret < 0) 2144 - return ret; 2144 + goto out; 2145 2145 2146 - pr_info(" %-20s (on %s", buf, place); 2146 + strbuf_addf(result, " %-20s (on %s", buf, place); 2147 2147 if (module) 2148 - pr_info(" in %s", module); 2148 + strbuf_addf(result, " in %s", module); 2149 2149 2150 2150 if (pev->nargs > 0) { 2151 - pr_info(" with"); 2151 + strbuf_addstr(result, " with"); 2152 2152 for (i = 0; i < pev->nargs; i++) { 2153 2153 ret = synthesize_perf_probe_arg(&pev->args[i], 2154 2154 buf, 128); 2155 2155 if (ret < 0) 2156 - break; 2157 - pr_info(" %s", buf); 2156 + goto out; 2157 + strbuf_addf(result, " %s", buf); 2158 2158 } 2159 2159 } 2160 - pr_info(")\n"); 2160 + strbuf_addch(result, ')'); 2161 + out: 2161 2162 free(place); 2163 + return ret; 2164 + } 2165 + 2166 + /* Show an event */ 2167 + static int show_perf_probe_event(struct perf_probe_event *pev, 2168 + const char *module, bool use_stdout) 2169 + { 2170 + struct strbuf buf = STRBUF_INIT; 2171 + int ret; 2172 + 2173 + ret = perf_probe_event__sprintf(pev, module, &buf); 2174 + if (ret >= 0) { 2175 + if (use_stdout) 2176 + printf("%s\n", buf.buf); 2177 + else 2178 + pr_info("%s\n", buf.buf); 2179 + } 2180 + strbuf_release(&buf); 2181 + 2162 2182 return ret; 2163 2183 } 2164 2184 ··· 2220 2200 goto next; 2221 2201 ret = convert_to_perf_probe_event(&tev, &pev, 2222 2202 is_kprobe); 2223 - if (ret >= 0) 2224 - ret = show_perf_probe_event(&pev, 2225 - tev.point.module); 2203 + if (ret < 0) 2204 + goto next; 2205 + ret = show_perf_probe_event(&pev, tev.point.module, 2206 + true); 2226 2207 } 2227 2208 next: 2228 2209 clear_perf_probe_event(&pev); ··· 2489 2468 group = pev->group; 2490 2469 pev->event = tev->event; 2491 2470 pev->group = tev->group; 2492 - show_perf_probe_event(pev, tev->point.module); 2471 + show_perf_probe_event(pev, tev->point.module, false); 2493 2472 /* Trick here - restore current event/group */ 2494 2473 pev->event = (char *)event; 2495 2474 pev->group = (char *)group;