mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 04:03:58 +08:00
perf probe: Use strbuf for making strings
Replace many fixed-length char array with strbuf to stringify perf_probe_event and probe_trace_event etc. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com> Cc: Hemant Kumar <hemant@linux.vnet.ibm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20160427183713.23446.97377.stgit@devbox Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
81d64f46d4
commit
909b0360ae
@ -1673,69 +1673,51 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compose only probe arg */
|
/* Compose only probe arg */
|
||||||
int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
|
char *synthesize_perf_probe_arg(struct perf_probe_arg *pa)
|
||||||
{
|
{
|
||||||
struct perf_probe_arg_field *field = pa->field;
|
struct perf_probe_arg_field *field = pa->field;
|
||||||
int ret;
|
struct strbuf buf;
|
||||||
char *tmp = buf;
|
char *ret;
|
||||||
|
|
||||||
|
strbuf_init(&buf, 64);
|
||||||
if (pa->name && pa->var)
|
if (pa->name && pa->var)
|
||||||
ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var);
|
strbuf_addf(&buf, "%s=%s", pa->name, pa->var);
|
||||||
else
|
else
|
||||||
ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var);
|
strbuf_addstr(&buf, pa->name ?: pa->var);
|
||||||
if (ret <= 0)
|
|
||||||
goto error;
|
|
||||||
tmp += ret;
|
|
||||||
len -= ret;
|
|
||||||
|
|
||||||
while (field) {
|
while (field) {
|
||||||
if (field->name[0] == '[')
|
if (field->name[0] == '[')
|
||||||
ret = e_snprintf(tmp, len, "%s", field->name);
|
strbuf_addstr(&buf, field->name);
|
||||||
else
|
else
|
||||||
ret = e_snprintf(tmp, len, "%s%s",
|
strbuf_addf(&buf, "%s%s", field->ref ? "->" : ".",
|
||||||
field->ref ? "->" : ".", field->name);
|
field->name);
|
||||||
if (ret <= 0)
|
|
||||||
goto error;
|
|
||||||
tmp += ret;
|
|
||||||
len -= ret;
|
|
||||||
field = field->next;
|
field = field->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pa->type) {
|
if (pa->type)
|
||||||
ret = e_snprintf(tmp, len, ":%s", pa->type);
|
strbuf_addf(&buf, ":%s", pa->type);
|
||||||
if (ret <= 0)
|
|
||||||
goto error;
|
ret = strbuf_detach(&buf, NULL);
|
||||||
tmp += ret;
|
|
||||||
len -= ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmp - buf;
|
|
||||||
error:
|
|
||||||
pr_debug("Failed to synthesize perf probe argument: %d\n", ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compose only probe point (not argument) */
|
/* Compose only probe point (not argument) */
|
||||||
static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
|
static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
|
||||||
{
|
{
|
||||||
char *buf, *tmp;
|
struct strbuf buf;
|
||||||
char offs[32] = "", line[32] = "", file[32] = "";
|
char *tmp;
|
||||||
int ret, len;
|
int len;
|
||||||
|
|
||||||
buf = zalloc(MAX_CMDLEN);
|
strbuf_init(&buf, 64);
|
||||||
if (buf == NULL) {
|
if (pp->function) {
|
||||||
ret = -ENOMEM;
|
strbuf_addstr(&buf, pp->function);
|
||||||
goto error;
|
if (pp->offset)
|
||||||
}
|
strbuf_addf(&buf, "+%lu", pp->offset);
|
||||||
if (pp->offset) {
|
else if (pp->line)
|
||||||
ret = e_snprintf(offs, 32, "+%lu", pp->offset);
|
strbuf_addf(&buf, ":%d", pp->line);
|
||||||
if (ret <= 0)
|
else if (pp->retprobe)
|
||||||
goto error;
|
strbuf_addstr(&buf, "%return");
|
||||||
}
|
|
||||||
if (pp->line) {
|
|
||||||
ret = e_snprintf(line, 32, ":%d", pp->line);
|
|
||||||
if (ret <= 0)
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
if (pp->file) {
|
if (pp->file) {
|
||||||
tmp = pp->file;
|
tmp = pp->file;
|
||||||
@ -1744,25 +1726,12 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
|
|||||||
tmp = strchr(pp->file + len - 30, '/');
|
tmp = strchr(pp->file + len - 30, '/');
|
||||||
tmp = tmp ? tmp + 1 : pp->file + len - 30;
|
tmp = tmp ? tmp + 1 : pp->file + len - 30;
|
||||||
}
|
}
|
||||||
ret = e_snprintf(file, 32, "@%s", tmp);
|
strbuf_addf(&buf, "@%s", tmp);
|
||||||
if (ret <= 0)
|
if (!pp->function && pp->line)
|
||||||
goto error;
|
strbuf_addf(&buf, ":%d", pp->line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pp->function)
|
return strbuf_detach(&buf, NULL);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1791,45 +1760,30 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref,
|
static int __synthesize_probe_trace_arg_ref(struct probe_trace_arg_ref *ref,
|
||||||
char **buf, size_t *buflen,
|
struct strbuf *buf, int depth)
|
||||||
int depth)
|
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
if (ref->next) {
|
if (ref->next) {
|
||||||
depth = __synthesize_probe_trace_arg_ref(ref->next, buf,
|
depth = __synthesize_probe_trace_arg_ref(ref->next, buf,
|
||||||
buflen, depth + 1);
|
depth + 1);
|
||||||
if (depth < 0)
|
if (depth < 0)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
strbuf_addf(buf, "%+ld(", ref->offset);
|
||||||
ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset);
|
|
||||||
if (ret < 0)
|
|
||||||
depth = ret;
|
|
||||||
else {
|
|
||||||
*buf += ret;
|
|
||||||
*buflen -= ret;
|
|
||||||
}
|
|
||||||
out:
|
out:
|
||||||
return depth;
|
return depth;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
|
static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
|
||||||
char *buf, size_t buflen)
|
struct strbuf *buf)
|
||||||
{
|
{
|
||||||
struct probe_trace_arg_ref *ref = arg->ref;
|
struct probe_trace_arg_ref *ref = arg->ref;
|
||||||
int ret, depth = 0;
|
int depth = 0;
|
||||||
char *tmp = buf;
|
|
||||||
|
|
||||||
/* Argument name or separator */
|
/* Argument name or separator */
|
||||||
if (arg->name)
|
if (arg->name)
|
||||||
ret = e_snprintf(buf, buflen, " %s=", arg->name);
|
strbuf_addf(buf, " %s=", arg->name);
|
||||||
else
|
else
|
||||||
ret = e_snprintf(buf, buflen, " ");
|
strbuf_addch(buf, ' ');
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
buf += ret;
|
|
||||||
buflen -= ret;
|
|
||||||
|
|
||||||
/* Special case: @XXX */
|
/* Special case: @XXX */
|
||||||
if (arg->value[0] == '@' && arg->ref)
|
if (arg->value[0] == '@' && arg->ref)
|
||||||
@ -1837,60 +1791,41 @@ static int synthesize_probe_trace_arg(struct probe_trace_arg *arg,
|
|||||||
|
|
||||||
/* Dereferencing arguments */
|
/* Dereferencing arguments */
|
||||||
if (ref) {
|
if (ref) {
|
||||||
depth = __synthesize_probe_trace_arg_ref(ref, &buf,
|
depth = __synthesize_probe_trace_arg_ref(ref, buf, 1);
|
||||||
&buflen, 1);
|
|
||||||
if (depth < 0)
|
if (depth < 0)
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print argument value */
|
/* Print argument value */
|
||||||
if (arg->value[0] == '@' && arg->ref)
|
if (arg->value[0] == '@' && arg->ref)
|
||||||
ret = e_snprintf(buf, buflen, "%s%+ld", arg->value,
|
strbuf_addf(buf, "%s%+ld", arg->value, arg->ref->offset);
|
||||||
arg->ref->offset);
|
|
||||||
else
|
else
|
||||||
ret = e_snprintf(buf, buflen, "%s", arg->value);
|
strbuf_addstr(buf, arg->value);
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
buf += ret;
|
|
||||||
buflen -= ret;
|
|
||||||
|
|
||||||
/* Closing */
|
/* Closing */
|
||||||
while (depth--) {
|
while (depth--)
|
||||||
ret = e_snprintf(buf, buflen, ")");
|
strbuf_addch(buf, ')');
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
buf += ret;
|
|
||||||
buflen -= ret;
|
|
||||||
}
|
|
||||||
/* Print argument type */
|
/* Print argument type */
|
||||||
if (arg->type) {
|
if (arg->type)
|
||||||
ret = e_snprintf(buf, buflen, ":%s", arg->type);
|
strbuf_addf(buf, ":%s", arg->type);
|
||||||
if (ret <= 0)
|
|
||||||
return ret;
|
|
||||||
buf += ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf - tmp;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *synthesize_probe_trace_command(struct probe_trace_event *tev)
|
char *synthesize_probe_trace_command(struct probe_trace_event *tev)
|
||||||
{
|
{
|
||||||
struct probe_trace_point *tp = &tev->point;
|
struct probe_trace_point *tp = &tev->point;
|
||||||
char *buf;
|
struct strbuf buf;
|
||||||
int i, len, ret;
|
char *ret = NULL;
|
||||||
|
int i;
|
||||||
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;
|
|
||||||
|
|
||||||
/* Uprobes must have tp->module */
|
/* Uprobes must have tp->module */
|
||||||
if (tev->uprobes && !tp->module)
|
if (tev->uprobes && !tp->module)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
|
strbuf_init(&buf, 32);
|
||||||
|
strbuf_addf(&buf, "%c:%s/%s ", tp->retprobe ? 'r' : 'p',
|
||||||
|
tev->group, tev->event);
|
||||||
/*
|
/*
|
||||||
* If tp->address == 0, then this point must be a
|
* If tp->address == 0, then this point must be a
|
||||||
* absolute address uprobe.
|
* absolute address uprobe.
|
||||||
@ -1904,34 +1839,23 @@ char *synthesize_probe_trace_command(struct probe_trace_event *tev)
|
|||||||
|
|
||||||
/* Use the tp->address for uprobes */
|
/* Use the tp->address for uprobes */
|
||||||
if (tev->uprobes)
|
if (tev->uprobes)
|
||||||
ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s:0x%lx",
|
strbuf_addf(&buf, "%s:0x%lx", tp->module, tp->address);
|
||||||
tp->module, tp->address);
|
|
||||||
else if (!strncmp(tp->symbol, "0x", 2))
|
else if (!strncmp(tp->symbol, "0x", 2))
|
||||||
/* Absolute address. See try_to_find_absolute_address() */
|
/* Absolute address. See try_to_find_absolute_address() */
|
||||||
ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s0x%lx",
|
strbuf_addf(&buf, "%s%s0x%lx", tp->module ?: "",
|
||||||
tp->module ?: "", tp->module ? ":" : "",
|
tp->module ? ":" : "", tp->address);
|
||||||
tp->address);
|
|
||||||
else
|
else
|
||||||
ret = e_snprintf(buf + len, MAX_CMDLEN - len, "%s%s%s+%lu",
|
strbuf_addf(&buf, "%s%s%s+%lu", tp->module ?: "",
|
||||||
tp->module ?: "", tp->module ? ":" : "",
|
tp->module ? ":" : "", tp->symbol, tp->offset);
|
||||||
tp->symbol, tp->offset);
|
|
||||||
|
|
||||||
if (ret <= 0)
|
for (i = 0; i < tev->nargs; i++)
|
||||||
goto error;
|
if (synthesize_probe_trace_arg(&tev->args[i], &buf) < 0)
|
||||||
len += ret;
|
|
||||||
|
|
||||||
for (i = 0; i < tev->nargs; i++) {
|
|
||||||
ret = synthesize_probe_trace_arg(&tev->args[i], buf + len,
|
|
||||||
MAX_CMDLEN - len);
|
|
||||||
if (ret <= 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
len += ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
ret = strbuf_detach(&buf, NULL);
|
||||||
error:
|
error:
|
||||||
free(buf);
|
strbuf_release(&buf);
|
||||||
return NULL;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
|
static int find_perf_probe_point_from_map(struct probe_trace_point *tp,
|
||||||
@ -2013,7 +1937,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,
|
static int convert_to_perf_probe_event(struct probe_trace_event *tev,
|
||||||
struct perf_probe_event *pev, bool is_kprobe)
|
struct perf_probe_event *pev, bool is_kprobe)
|
||||||
{
|
{
|
||||||
char buf[64] = "";
|
struct strbuf buf = STRBUF_INIT;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
/* Convert event/group name */
|
/* Convert event/group name */
|
||||||
@ -2036,9 +1960,9 @@ static int convert_to_perf_probe_event(struct probe_trace_event *tev,
|
|||||||
if (tev->args[i].name)
|
if (tev->args[i].name)
|
||||||
pev->args[i].name = strdup(tev->args[i].name);
|
pev->args[i].name = strdup(tev->args[i].name);
|
||||||
else {
|
else {
|
||||||
ret = synthesize_probe_trace_arg(&tev->args[i],
|
strbuf_init(&buf, 32);
|
||||||
buf, 64);
|
ret = synthesize_probe_trace_arg(&tev->args[i], &buf);
|
||||||
pev->args[i].name = strdup(buf);
|
pev->args[i].name = strbuf_detach(&buf, NULL);
|
||||||
}
|
}
|
||||||
if (pev->args[i].name == NULL && ret >= 0)
|
if (pev->args[i].name == NULL && ret >= 0)
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
@ -2216,37 +2140,37 @@ static int perf_probe_event__sprintf(const char *group, const char *event,
|
|||||||
const char *module,
|
const char *module,
|
||||||
struct strbuf *result)
|
struct strbuf *result)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i;
|
||||||
char buf[128];
|
char *buf;
|
||||||
char *place;
|
|
||||||
|
if (asprintf(&buf, "%s:%s", group, event) < 0)
|
||||||
|
return -errno;
|
||||||
|
strbuf_addf(result, " %-20s (on ", buf);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
/* Synthesize only event probe point */
|
/* Synthesize only event probe point */
|
||||||
place = synthesize_perf_probe_point(&pev->point);
|
buf = synthesize_perf_probe_point(&pev->point);
|
||||||
if (!place)
|
if (!buf)
|
||||||
return -EINVAL;
|
return -ENOMEM;
|
||||||
|
strbuf_addstr(result, buf);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
ret = e_snprintf(buf, 128, "%s:%s", group, event);
|
|
||||||
if (ret < 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
strbuf_addf(result, " %-20s (on %s", buf, place);
|
|
||||||
if (module)
|
if (module)
|
||||||
strbuf_addf(result, " in %s", module);
|
strbuf_addf(result, " in %s", module);
|
||||||
|
|
||||||
if (pev->nargs > 0) {
|
if (pev->nargs > 0) {
|
||||||
strbuf_add(result, " with", 5);
|
strbuf_add(result, " with", 5);
|
||||||
for (i = 0; i < pev->nargs; i++) {
|
for (i = 0; i < pev->nargs; i++) {
|
||||||
ret = synthesize_perf_probe_arg(&pev->args[i],
|
buf = synthesize_perf_probe_arg(&pev->args[i]);
|
||||||
buf, 128);
|
if (!buf)
|
||||||
if (ret < 0)
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
strbuf_addf(result, " %s", buf);
|
strbuf_addf(result, " %s", buf);
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strbuf_addch(result, ')');
|
strbuf_addch(result, ')');
|
||||||
out:
|
|
||||||
free(place);
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show an event */
|
/* Show an event */
|
||||||
|
@ -120,7 +120,7 @@ int parse_probe_trace_command(const char *cmd, struct probe_trace_event *tev);
|
|||||||
/* Events to command string */
|
/* Events to command string */
|
||||||
char *synthesize_perf_probe_command(struct perf_probe_event *pev);
|
char *synthesize_perf_probe_command(struct perf_probe_event *pev);
|
||||||
char *synthesize_probe_trace_command(struct probe_trace_event *tev);
|
char *synthesize_probe_trace_command(struct probe_trace_event *tev);
|
||||||
int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len);
|
char *synthesize_perf_probe_arg(struct perf_probe_arg *pa);
|
||||||
|
|
||||||
/* Check the perf_probe_event needs debuginfo */
|
/* Check the perf_probe_event needs debuginfo */
|
||||||
bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
|
bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
|
||||||
|
@ -553,7 +553,7 @@ static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
|
|||||||
static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
|
static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
|
||||||
{
|
{
|
||||||
Dwarf_Die vr_die;
|
Dwarf_Die vr_die;
|
||||||
char buf[32], *ptr;
|
char *buf, *ptr;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* Copy raw parameters */
|
/* Copy raw parameters */
|
||||||
@ -563,13 +563,13 @@ static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf)
|
|||||||
if (pf->pvar->name)
|
if (pf->pvar->name)
|
||||||
pf->tvar->name = strdup(pf->pvar->name);
|
pf->tvar->name = strdup(pf->pvar->name);
|
||||||
else {
|
else {
|
||||||
ret = synthesize_perf_probe_arg(pf->pvar, buf, 32);
|
buf = synthesize_perf_probe_arg(pf->pvar);
|
||||||
if (ret < 0)
|
if (!buf)
|
||||||
return ret;
|
return -ENOMEM;
|
||||||
ptr = strchr(buf, ':'); /* Change type separator to _ */
|
ptr = strchr(buf, ':'); /* Change type separator to _ */
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = '_';
|
*ptr = '_';
|
||||||
pf->tvar->name = strdup(buf);
|
pf->tvar->name = buf;
|
||||||
}
|
}
|
||||||
if (pf->tvar->name == NULL)
|
if (pf->tvar->name == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -1334,8 +1334,8 @@ static int collect_variables_cb(Dwarf_Die *die_mem, void *data)
|
|||||||
if (ret2 == 0) {
|
if (ret2 == 0) {
|
||||||
strlist__add(vl->vars,
|
strlist__add(vl->vars,
|
||||||
strbuf_detach(&buf, NULL));
|
strbuf_detach(&buf, NULL));
|
||||||
}
|
} else
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user