From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
linux-kernel@vger.kernel.org,
Adrian Hunter <adrian.hunter@intel.com>,
Ingo Molnar <mingo@redhat.com>, Paul Mackerras <paulus@samba.org>,
Jiri Olsa <jolsa@kernel.org>, Borislav Petkov <bp@suse.de>,
Hemant Kumar <hemant@linux.vnet.ibm.com>
Subject: Re: Re: [RFC PATCH perf/core v2 03/16] perf probe: Use strbuf for making strings in probe-event.c
Date: Fri, 17 Jul 2015 19:16:55 +0900 [thread overview]
Message-ID: <55A8D617.2050803@hitachi.com> (raw)
In-Reply-To: <20150717074205.GB25386@sejong>
On 2015/07/17 16:42, Namhyung Kim wrote:
> Hi Masami,
>
> On Wed, Jul 15, 2015 at 06:14:14PM +0900, Masami Hiramatsu wrote:
>> Replace many fixed-length char array with strbuf to
>> stringify perf_probe_event and probe_trace_event etc. in
>> util/probe-event.c.
>>
>> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
>> ---
>
> [SNIP]
>
>> + ret = strbuf_detach(&buf, NULL);
>> + strbuf_release(&buf);
>
> It seems that strbuf_release() is meaningless after strbuf_detach().
Ah, right! I'll remove those redundant strbuf_release.
Thanks!
>
>
>>
>> - return tmp - buf;
>> -error:
>> - pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
>> return ret;
>> }
>>
>> /* Compose only probe point (not argument) */
>> static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
>> {
>> - char *buf, *tmp;
>> - char offs[32] = "", line[32] = "", file[32] = "";
>> - int ret, len;
>> -
>> - buf = zalloc(MAX_CMDLEN);
>> - if (buf == NULL) {
>> - ret = -ENOMEM;
>> - goto error;
>> - }
>> - if (pp->offset) {
>> - ret = e_snprintf(offs, 32, "+%lu", pp->offset);
>> - if (ret <= 0)
>> - goto error;
>> - }
>> - if (pp->line) {
>> - ret = e_snprintf(line, 32, ":%d", pp->line);
>> - if (ret <= 0)
>> - goto error;
>> + struct strbuf buf;
>> + char *tmp;
>> + int len;
>> +
>> + strbuf_init(&buf, 64);
>> + if (pp->function) {
>> + strbuf_addstr(&buf, pp->function);
>> + if (pp->offset)
>> + strbuf_addf(&buf, "+%lu", pp->offset);
>> + else if (pp->line)
>> + strbuf_addf(&buf, ":%d", pp->line);
>> + else if (pp->retprobe)
>> + strbuf_addstr(&buf, "%return");
>> }
>> if (pp->file) {
>> tmp = pp->file;
>> @@ -1633,25 +1616,14 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
>> tmp = strchr(pp->file + len - 30, '/');
>> tmp = tmp ? tmp + 1 : pp->file + len - 30;
>> }
>> - ret = e_snprintf(file, 32, "@%s", tmp);
>> - if (ret <= 0)
>> - goto error;
>> + strbuf_addf(&buf, "@%s", tmp);
>> + if (!pp->function && pp->line)
>> + strbuf_addf(&buf, ":%d", pp->line);
>> }
>>
>> - if (pp->function)
>> - ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
>> - offs, pp->retprobe ? "%return" : "", line,
>> - file);
>> - else
>> - ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
>> - if (ret <= 0)
>> - goto error;
>> -
>> - return buf;
>> -error:
>> - pr_debug("Failed to synthesize perf probe point: %d\n", ret);
>> - free(buf);
>> - return NULL;
>> + tmp = strbuf_detach(&buf, NULL);
>> + strbuf_release(&buf);
>
> Ditto.
>
>
>> + return tmp;
>> }
>
>
> [SNIP]
>> char *synthesize_probe_trace_command(struct probe_trace_event *tev)
>> {
>> struct probe_trace_point *tp = &tev->point;
>> - char *buf;
>> - int i, len, ret;
>> -
>> - buf = zalloc(MAX_CMDLEN);
>> - if (buf == NULL)
>> - return NULL;
>> -
>> - len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
>> - tev->group, tev->event);
>> - if (len <= 0)
>> - goto error;
>> + struct strbuf buf;
>> + char *ret = NULL;
>> + int i;
>>
>> /* Uprobes must have tp->address and tp->module */
>> if (tev->uprobes && (!tp->address || !tp->module))
>> - goto error;
>> + return NULL;
>> +
>> + strbuf_init(&buf, 32);
>> + strbuf_addf(&buf, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
>> + tev->group, tev->event);
>>
>> /* Use the tp->address for uprobes */
>> if (tev->uprobes)
>> - ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx",
>> - tp->module, tp->address);
>> + strbuf_addf(&buf, "%s:0x%lx", tp->module, tp->address);
>> else
>> - ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu",
>> - tp->module ?: "", tp->module ? ":" : "",
>> - tp->symbol, tp->offset);
>> -
>> - if (ret <= 0)
>> - goto error;
>> - len += ret;
>> + strbuf_addf(&buf, "%s%s%s+%lu", tp->module ?: "",
>> + tp->module ? ":" : "", tp->symbol, tp->offset);
>>
>> for (i = 0; i < tev->nargs; i++) {
>> - ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
>> - MAX_CMDLEN - len);
>> - if (ret <= 0)
>> + if (synthesize_probe_trace_arg(&tev->args[i], &buf) < 0)
>> goto error;
>> - len += ret;
>> }
>>
>> - return buf;
>> + ret = strbuf_detach(&buf, NULL);
>> error:
>> - free(buf);
>> - return NULL;
>> + strbuf_release(&buf);
>
> This is necessary for the error path.
>
>
>> + return ret;
>> }
>>
>> static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
>> @@ -1883,7 +1812,7 @@ static int convert_to_perf_probe_point(struct probe_trace_point *tp,
>> static int convert_to_perf_probe_event(struct probe_trace_event *tev,
>> struct perf_probe_event *pev, bool is_kprobe)
>> {
>> - char buf[64] = "";
>> + struct strbuf buf = STRBUF_INIT;
>> int i, ret;
>>
>> /* Convert event/group name */
>> @@ -1906,9 +1835,10 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
>> if (tev->args[i].name)
>> pev->args[i].name = strdup(tev->args[i].name);
>> else {
>> - ret = synthesize_probe_trace_arg(&tev->args[i],
>> - buf, 64);
>> - pev->args[i].name = strdup(buf);
>> + strbuf_init(&buf, 32);
>> + ret = synthesize_probe_trace_arg(&tev->args[i], &buf);
>> + pev->args[i].name = strbuf_detach(&buf, NULL);
>> + strbuf_release(&buf);
>
> Ditto.
>
> Thanks,
> Namhyung
>
>> }
>> if (pev->args[i].name == NULL && ret >= 0)
>> ret = -ENOMEM;
> --
> 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/
>
--
Masami HIRAMATSU
Linux Technology Research Center, System Productivity Research Dept.
Center for Technology Innovation - Systems Engineering
Hitachi, Ltd., Research & Development Group
E-mail: masami.hiramatsu.pt@hitachi.com
next prev parent reply other threads:[~2015-07-17 10:17 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-15 9:13 [RFC PATCH perf/core v2 00/16] perf-probe --cache and SDT support Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 01/16] perf probe: Simplify __add_probe_trace_events code Masami Hiramatsu
2015-07-21 9:34 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 02/16] perf probe: Move ftrace probe-event operations to probe-file.c Masami Hiramatsu
2015-07-21 9:35 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 03/16] perf probe: Use strbuf for making strings in probe-event.c Masami Hiramatsu
2015-07-17 7:42 ` Namhyung Kim
2015-07-17 10:16 ` Masami Hiramatsu [this message]
2015-07-15 9:14 ` [RFC PATCH perf/core v2 04/16] perf-buildid-cache: Use path/to/bin/buildid/elf instead of path/to/bin/buildid Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 05/16] perf buildid: Use SBUILD_ID_SIZE macro Masami Hiramatsu
2015-07-20 18:47 ` Arnaldo Carvalho de Melo
2015-07-21 9:35 ` [tip:perf/core] " tip-bot for Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 06/16] perf buildid: Introduce sysfs/filename__sprintf_build_id Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 07/16] perf: Add lsdir to read a directory Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 08/16] perf-buildid-cache: Use lsdir for looking up buildid caches Masami Hiramatsu
2015-07-15 9:14 ` [RFC PATCH perf/core v2 09/16] perf probe: Add --cache option to cache the probe definitions Masami Hiramatsu
2015-07-15 9:15 ` [RFC PATCH perf/core v2 10/16] perf probe: Use cache entry if possible Masami Hiramatsu
2015-07-15 9:15 ` [RFC PATCH perf/core v2 11/16] perf probe: Show all cached probes Masami Hiramatsu
2015-07-15 9:15 ` [RFC PATCH perf/core v2 12/16] perf probe: Remove caches when --cache is given Masami Hiramatsu
2015-07-15 9:15 ` [RFC PATCH perf/core v2 13/16] perf/sdt: ELF support for SDT Masami Hiramatsu
2015-07-15 9:15 ` [RFC PATCH perf/core v2 14/16] perf probe: Add group name support Masami Hiramatsu
2015-07-19 10:16 ` Namhyung Kim
2015-07-20 4:48 ` Masami Hiramatsu
2015-07-20 15:31 ` Namhyung Kim
2015-07-15 9:15 ` [RFC PATCH perf/core v2 15/16] perf buildid-cache: Scan and import user SDT events to probe cache Masami Hiramatsu
2015-07-19 10:46 ` Namhyung Kim
2015-07-20 3:19 ` Masami Hiramatsu
2015-07-20 15:52 ` Namhyung Kim
2015-07-21 10:42 ` Masami Hiramatsu
2015-07-15 9:15 ` [RFC PATCH perf/core v2 16/16] perf probe: Accept %sdt and %cached event name Masami Hiramatsu
2015-07-19 10:53 ` Namhyung Kim
2015-07-20 3:03 ` Masami Hiramatsu
2015-07-16 3:13 ` [RFC PATCH perf/core v2 00/16] perf-probe --cache and SDT support Hemant Kumar
2015-07-17 3:21 ` Masami Hiramatsu
2015-07-19 4:24 ` Namhyung Kim
2015-07-20 5:47 ` Brendan Gregg
2015-07-20 16:20 ` Namhyung Kim
2015-07-21 10:34 ` Masami Hiramatsu
2015-07-22 14:12 ` Hemant Kumar
2015-07-23 13:13 ` Masami Hiramatsu
2015-07-23 14:01 ` Arnaldo Carvalho de Melo
2015-07-23 16:24 ` Masami Hiramatsu
2015-07-23 16:42 ` Arnaldo Carvalho de Melo
2015-07-24 7:55 ` Namhyung Kim
2015-07-24 15:52 ` Arnaldo Carvalho de Melo
2015-07-25 0:51 ` Masami Hiramatsu
2015-07-27 14:03 ` Re: " Namhyung Kim
2015-07-27 15:16 ` Arnaldo Carvalho de Melo
2015-07-28 0:42 ` Masami Hiramatsu
2015-07-28 13:45 ` Arnaldo Carvalho de Melo
2015-07-20 18:36 ` Arnaldo Carvalho de Melo
2015-07-20 18:42 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55A8D617.2050803@hitachi.com \
--to=masami.hiramatsu.pt@hitachi.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=bp@suse.de \
--cc=hemant@linux.vnet.ibm.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).