perf tools: Make binary data printer code in trace_event public available
Move code printing binray data from trace_event() to utils.c and allows passing different printer. Further commits will use this logic to print bpf output event. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Li Zefan <lizefan@huawei.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1456312845-111583-2-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
c19ac91245
commit
c339b1a90e
@@ -14,6 +14,7 @@
|
||||
#include <limits.h>
|
||||
#include <byteswap.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/log2.h>
|
||||
#include <unistd.h>
|
||||
#include "callchain.h"
|
||||
#include "strlist.h"
|
||||
@@ -670,3 +671,39 @@ int fetch_current_timestamp(char *buf, size_t sz)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_binary(unsigned char *data, size_t len,
|
||||
size_t bytes_per_line, print_binary_t printer,
|
||||
void *extra)
|
||||
{
|
||||
size_t i, j, mask;
|
||||
|
||||
if (!printer)
|
||||
return;
|
||||
|
||||
bytes_per_line = roundup_pow_of_two(bytes_per_line);
|
||||
mask = bytes_per_line - 1;
|
||||
|
||||
printer(BINARY_PRINT_DATA_BEGIN, 0, extra);
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((i & mask) == 0) {
|
||||
printer(BINARY_PRINT_LINE_BEGIN, -1, extra);
|
||||
printer(BINARY_PRINT_ADDR, i, extra);
|
||||
}
|
||||
|
||||
printer(BINARY_PRINT_NUM_DATA, data[i], extra);
|
||||
|
||||
if (((i & mask) == mask) || i == len - 1) {
|
||||
for (j = 0; j < mask-(i & mask); j++)
|
||||
printer(BINARY_PRINT_NUM_PAD, -1, extra);
|
||||
|
||||
printer(BINARY_PRINT_SEP, i, extra);
|
||||
for (j = i & ~mask; j <= i; j++)
|
||||
printer(BINARY_PRINT_CHAR_DATA, data[j], extra);
|
||||
for (j = 0; j < mask-(i & mask); j++)
|
||||
printer(BINARY_PRINT_CHAR_PAD, i, extra);
|
||||
printer(BINARY_PRINT_LINE_END, -1, extra);
|
||||
}
|
||||
}
|
||||
printer(BINARY_PRINT_DATA_END, -1, extra);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user