Skip to content

Commit fea0139

Browse files
committed
perf tools: Move print_binary definitions to separate files
Continuing the split of util.[ch] into more manageable bits. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-5eu367rwcwnvvn7fz09l7xpb@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent a12a4e0 commit fea0139

12 files changed

Lines changed: 91 additions & 78 deletions

File tree

‎tools/perf/builtin-script.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "util/stat.h"
2424
#include "util/thread-stack.h"
2525
#include "util/time-utils.h"
26+
#include "print_binary.h"
2627
#include <linux/bitmap.h>
2728
#include <linux/kernel.h>
2829
#include <linux/stringify.h>

‎tools/perf/builtin-trace.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "util/parse-events.h"
3737
#include "util/bpf-loader.h"
3838
#include "callchain.h"
39+
#include "print_binary.h"
3940
#include "syscalltbl.h"
4041
#include "rb_resort.h"
4142

‎tools/perf/tests/is_printable_array.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <linux/kernel.h>
33
#include "tests.h"
44
#include "debug.h"
5-
#include "util.h"
5+
#include "print_binary.h"
66

77
int test__is_printable_array(int subtest __maybe_unused)
88
{

‎tools/perf/util/Build‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ libperf-y += llvm-utils.o
1616
libperf-y += parse-events.o
1717
libperf-y += perf_regs.o
1818
libperf-y += path.o
19+
libperf-y += print_binary.o
1920
libperf-y += rbtree.o
2021
libperf-y += libstring.o
2122
libperf-y += bitmap.o

‎tools/perf/util/debug.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "color.h"
1414
#include "event.h"
1515
#include "debug.h"
16+
#include "print_binary.h"
1617
#include "util.h"
1718
#include "target.h"
1819

‎tools/perf/util/print_binary.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "print_binary.h"
2+
#include <linux/log2.h>
3+
#include "sane_ctype.h"
4+
5+
void print_binary(unsigned char *data, size_t len,
6+
size_t bytes_per_line, print_binary_t printer,
7+
void *extra)
8+
{
9+
size_t i, j, mask;
10+
11+
if (!printer)
12+
return;
13+
14+
bytes_per_line = roundup_pow_of_two(bytes_per_line);
15+
mask = bytes_per_line - 1;
16+
17+
printer(BINARY_PRINT_DATA_BEGIN, 0, extra);
18+
for (i = 0; i < len; i++) {
19+
if ((i & mask) == 0) {
20+
printer(BINARY_PRINT_LINE_BEGIN, -1, extra);
21+
printer(BINARY_PRINT_ADDR, i, extra);
22+
}
23+
24+
printer(BINARY_PRINT_NUM_DATA, data[i], extra);
25+
26+
if (((i & mask) == mask) || i == len - 1) {
27+
for (j = 0; j < mask-(i & mask); j++)
28+
printer(BINARY_PRINT_NUM_PAD, -1, extra);
29+
30+
printer(BINARY_PRINT_SEP, i, extra);
31+
for (j = i & ~mask; j <= i; j++)
32+
printer(BINARY_PRINT_CHAR_DATA, data[j], extra);
33+
for (j = 0; j < mask-(i & mask); j++)
34+
printer(BINARY_PRINT_CHAR_PAD, i, extra);
35+
printer(BINARY_PRINT_LINE_END, -1, extra);
36+
}
37+
}
38+
printer(BINARY_PRINT_DATA_END, -1, extra);
39+
}
40+
41+
int is_printable_array(char *p, unsigned int len)
42+
{
43+
unsigned int i;
44+
45+
if (!p || !len || p[len - 1] != 0)
46+
return 0;
47+
48+
len--;
49+
50+
for (i = 0; i < len; i++) {
51+
if (!isprint(p[i]) && !isspace(p[i]))
52+
return 0;
53+
}
54+
return 1;
55+
}

‎tools/perf/util/print_binary.h‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef PERF_PRINT_BINARY_H
2+
#define PERF_PRINT_BINARY_H
3+
4+
#include <stddef.h>
5+
6+
enum binary_printer_ops {
7+
BINARY_PRINT_DATA_BEGIN,
8+
BINARY_PRINT_LINE_BEGIN,
9+
BINARY_PRINT_ADDR,
10+
BINARY_PRINT_NUM_DATA,
11+
BINARY_PRINT_NUM_PAD,
12+
BINARY_PRINT_SEP,
13+
BINARY_PRINT_CHAR_DATA,
14+
BINARY_PRINT_CHAR_PAD,
15+
BINARY_PRINT_LINE_END,
16+
BINARY_PRINT_DATA_END,
17+
};
18+
19+
typedef void (*print_binary_t)(enum binary_printer_ops op,
20+
unsigned int val, void *extra);
21+
22+
void print_binary(unsigned char *data, size_t len,
23+
size_t bytes_per_line, print_binary_t printer,
24+
void *extra);
25+
26+
int is_printable_array(char *p, unsigned int len);
27+
28+
#endif /* PERF_PRINT_BINARY_H */

‎tools/perf/util/python-ext-sources‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ util/cgroup.c
2121
util/parse-branch-options.c
2222
util/rblist.c
2323
util/counts.c
24+
util/print_binary.c
2425
util/strlist.c
2526
util/trace-event.c
2627
../lib/rbtree.c

‎tools/perf/util/python.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "evsel.h"
88
#include "event.h"
99
#include "cpumap.h"
10+
#include "print_binary.h"
1011
#include "thread_map.h"
1112

1213
/*

‎tools/perf/util/scripting-engines/trace-event-python.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "../call-path.h"
4747
#include "thread_map.h"
4848
#include "cpumap.h"
49+
#include "print_binary.h"
4950
#include "stat.h"
5051

5152
PyMODINIT_FUNC initperf_trace_context(void);

0 commit comments

Comments
 (0)