perf probe: Add sdt probes arguments into the uprobe cmd string

An sdt probe can be associated with arguments but they were not passed
to the user probe tracing interface (uprobe_events); this patch adapts
the sdt argument descriptors according to the uprobe input format.

As the uprobe parser does not support scaled address mode, perf will
skip arguments which cannot be adapted to the uprobe format.

Here are the results:

  $ perf buildid-cache -v --add test_sdt
  $ perf probe -x test_sdt sdt_libfoo:table_frob
  $ perf probe -x test_sdt sdt_libfoo:table_diddle
  $ perf record -e sdt_libfoo:table_frob -e sdt_libfoo:table_diddle test_sdt
  $ perf script
  test_sdt  ...   666.255678:   sdt_libfoo:table_frob: (4004d7) arg0=0 arg1=0
  test_sdt  ...   666.255683: sdt_libfoo:table_diddle: (40051a) arg0=0 arg1=0
  test_sdt  ...   666.255686:   sdt_libfoo:table_frob: (4004d7) arg0=1 arg1=2
  test_sdt  ...   666.255689: sdt_libfoo:table_diddle: (40051a) arg0=3 arg1=4
  test_sdt  ...   666.255692:   sdt_libfoo:table_frob: (4004d7) arg0=2 arg1=4
  test_sdt  ...   666.255694: sdt_libfoo:table_diddle: (40051a) arg0=6 arg1=8

Signed-off-by: Alexis Berlemont <alexis.berlemont@gmail.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20161214000732.1710-3-alexis.berlemont@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Alexis Berlemont
2016-12-14 01:07:32 +01:00
committed by Arnaldo Carvalho de Melo
parent be88184b1c
commit 3b1f8311f6
4 changed files with 261 additions and 4 deletions

View File

@@ -1,4 +1,7 @@
#include <string.h>
#include "../../perf.h"
#include "../../util/util.h"
#include "../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = {
@@ -26,3 +29,83 @@ const struct sample_reg sample_reg_masks[] = {
#endif
SMPL_REG_END
};
struct sdt_name_reg {
const char *sdt_name;
const char *uprobe_name;
};
#define SDT_NAME_REG(n, m) {.sdt_name = "%" #n, .uprobe_name = "%" #m}
#define SDT_NAME_REG_END {.sdt_name = NULL, .uprobe_name = NULL}
static const struct sdt_name_reg sdt_reg_renamings[] = {
SDT_NAME_REG(eax, ax),
SDT_NAME_REG(rax, ax),
SDT_NAME_REG(ebx, bx),
SDT_NAME_REG(rbx, bx),
SDT_NAME_REG(ecx, cx),
SDT_NAME_REG(rcx, cx),
SDT_NAME_REG(edx, dx),
SDT_NAME_REG(rdx, dx),
SDT_NAME_REG(esi, si),
SDT_NAME_REG(rsi, si),
SDT_NAME_REG(edi, di),
SDT_NAME_REG(rdi, di),
SDT_NAME_REG(ebp, bp),
SDT_NAME_REG(rbp, bp),
SDT_NAME_REG_END,
};
int sdt_rename_register(char **pdesc, char *old_name)
{
const struct sdt_name_reg *rnames = sdt_reg_renamings;
char *new_desc, *old_desc = *pdesc;
size_t prefix_len, sdt_len, uprobe_len, old_desc_len, offset;
int ret = -1;
while (ret != 0 && rnames->sdt_name != NULL) {
sdt_len = strlen(rnames->sdt_name);
ret = strncmp(old_name, rnames->sdt_name, sdt_len);
rnames += !!ret;
}
if (rnames->sdt_name == NULL)
return 0;
sdt_len = strlen(rnames->sdt_name);
uprobe_len = strlen(rnames->uprobe_name);
old_desc_len = strlen(old_desc) + 1;
new_desc = zalloc(old_desc_len + uprobe_len - sdt_len);
if (new_desc == NULL)
return -1;
/* Copy the chars before the register name (at least '%') */
prefix_len = old_name - old_desc;
memcpy(new_desc, old_desc, prefix_len);
/* Copy the new register name */
memcpy(new_desc + prefix_len, rnames->uprobe_name, uprobe_len);
/* Copy the chars after the register name (if need be) */
offset = prefix_len + sdt_len;
if (offset < old_desc_len) {
/*
* The orginal register name can be suffixed by 'b',
* 'w' or 'd' to indicate its size; so, we need to
* skip this char if we met one.
*/
char sfx = old_desc[offset];
if (sfx == 'b' || sfx == 'w' || sfx == 'd')
offset++;
}
if (offset < old_desc_len)
memcpy(new_desc + prefix_len + uprobe_len,
old_desc + offset, old_desc_len - offset);
free(old_desc);
*pdesc = new_desc;
return 0;
}