diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-17 15:23:22 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-19 12:01:50 -0400 |
commit | fea013928cdcf81fbe0bfbf9e2eed1c7da2d62c2 (patch) | |
tree | 92335965a80f1ceeebdfd6d4b231abbbd117dc85 | |
parent | a12a4e023a55f058178afea1ada3ce7bf4db94c3 (diff) |
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>
-rw-r--r-- | tools/perf/builtin-script.c | 1 | ||||
-rw-r--r-- | tools/perf/builtin-trace.c | 1 | ||||
-rw-r--r-- | tools/perf/tests/is_printable_array.c | 2 | ||||
-rw-r--r-- | tools/perf/util/Build | 1 | ||||
-rw-r--r-- | tools/perf/util/debug.c | 1 | ||||
-rw-r--r-- | tools/perf/util/print_binary.c | 55 | ||||
-rw-r--r-- | tools/perf/util/print_binary.h | 28 | ||||
-rw-r--r-- | tools/perf/util/python-ext-sources | 1 | ||||
-rw-r--r-- | tools/perf/util/python.c | 1 | ||||
-rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 1 | ||||
-rw-r--r-- | tools/perf/util/util.c | 54 | ||||
-rw-r--r-- | tools/perf/util/util.h | 23 |
12 files changed, 91 insertions, 78 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 5afd9a62360a..5f4e36a4c444 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "util/stat.h" | 23 | #include "util/stat.h" |
24 | #include "util/thread-stack.h" | 24 | #include "util/thread-stack.h" |
25 | #include "util/time-utils.h" | 25 | #include "util/time-utils.h" |
26 | #include "print_binary.h" | ||
26 | #include <linux/bitmap.h> | 27 | #include <linux/bitmap.h> |
27 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
28 | #include <linux/stringify.h> | 29 | #include <linux/stringify.h> |
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0b00d8ac5226..9a8b9e6f47f7 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include "util/parse-events.h" | 36 | #include "util/parse-events.h" |
37 | #include "util/bpf-loader.h" | 37 | #include "util/bpf-loader.h" |
38 | #include "callchain.h" | 38 | #include "callchain.h" |
39 | #include "print_binary.h" | ||
39 | #include "syscalltbl.h" | 40 | #include "syscalltbl.h" |
40 | #include "rb_resort.h" | 41 | #include "rb_resort.h" |
41 | 42 | ||
diff --git a/tools/perf/tests/is_printable_array.c b/tools/perf/tests/is_printable_array.c index a008e5c2d980..a5192f6a20d7 100644 --- a/tools/perf/tests/is_printable_array.c +++ b/tools/perf/tests/is_printable_array.c | |||
@@ -2,7 +2,7 @@ | |||
2 | #include <linux/kernel.h> | 2 | #include <linux/kernel.h> |
3 | #include "tests.h" | 3 | #include "tests.h" |
4 | #include "debug.h" | 4 | #include "debug.h" |
5 | #include "util.h" | 5 | #include "print_binary.h" |
6 | 6 | ||
7 | int test__is_printable_array(int subtest __maybe_unused) | 7 | int test__is_printable_array(int subtest __maybe_unused) |
8 | { | 8 | { |
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 5c0ea11a8f0a..f0b9e5d0e2fc 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build | |||
@@ -16,6 +16,7 @@ libperf-y += llvm-utils.o | |||
16 | libperf-y += parse-events.o | 16 | libperf-y += parse-events.o |
17 | libperf-y += perf_regs.o | 17 | libperf-y += perf_regs.o |
18 | libperf-y += path.o | 18 | libperf-y += path.o |
19 | libperf-y += print_binary.o | ||
19 | libperf-y += rbtree.o | 20 | libperf-y += rbtree.o |
20 | libperf-y += libstring.o | 21 | libperf-y += libstring.o |
21 | libperf-y += bitmap.o | 22 | libperf-y += bitmap.o |
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 41aa7c63e037..6e1d7e159649 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "color.h" | 13 | #include "color.h" |
14 | #include "event.h" | 14 | #include "event.h" |
15 | #include "debug.h" | 15 | #include "debug.h" |
16 | #include "print_binary.h" | ||
16 | #include "util.h" | 17 | #include "util.h" |
17 | #include "target.h" | 18 | #include "target.h" |
18 | 19 | ||
diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c new file mode 100644 index 000000000000..e908177b9976 --- /dev/null +++ b/tools/perf/util/print_binary.c | |||
@@ -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 | } | ||
diff --git a/tools/perf/util/print_binary.h b/tools/perf/util/print_binary.h new file mode 100644 index 000000000000..da0427263d2d --- /dev/null +++ b/tools/perf/util/print_binary.h | |||
@@ -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 */ | ||
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 0546a4304347..7d3927447fba 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
@@ -21,6 +21,7 @@ util/cgroup.c | |||
21 | util/parse-branch-options.c | 21 | util/parse-branch-options.c |
22 | util/rblist.c | 22 | util/rblist.c |
23 | util/counts.c | 23 | util/counts.c |
24 | util/print_binary.c | ||
24 | util/strlist.c | 25 | util/strlist.c |
25 | util/trace-event.c | 26 | util/trace-event.c |
26 | ../lib/rbtree.c | 27 | ../lib/rbtree.c |
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index a5fbc012e3df..0533711af44d 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include "evsel.h" | 7 | #include "evsel.h" |
8 | #include "event.h" | 8 | #include "event.h" |
9 | #include "cpumap.h" | 9 | #include "cpumap.h" |
10 | #include "print_binary.h" | ||
10 | #include "thread_map.h" | 11 | #include "thread_map.h" |
11 | 12 | ||
12 | /* | 13 | /* |
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index dd61213e7a3c..9d92af7d0718 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -46,6 +46,7 @@ | |||
46 | #include "../call-path.h" | 46 | #include "../call-path.h" |
47 | #include "thread_map.h" | 47 | #include "thread_map.h" |
48 | #include "cpumap.h" | 48 | #include "cpumap.h" |
49 | #include "print_binary.h" | ||
49 | #include "stat.h" | 50 | #include "stat.h" |
50 | 51 | ||
51 | PyMODINIT_FUNC initperf_trace_context(void); | 52 | PyMODINIT_FUNC initperf_trace_context(void); |
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 717541e72999..4fb8ee552a31 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c | |||
@@ -21,8 +21,6 @@ | |||
21 | #include "callchain.h" | 21 | #include "callchain.h" |
22 | #include "strlist.h" | 22 | #include "strlist.h" |
23 | 23 | ||
24 | #include "sane_ctype.h" | ||
25 | |||
26 | #define CALLCHAIN_PARAM_DEFAULT \ | 24 | #define CALLCHAIN_PARAM_DEFAULT \ |
27 | .mode = CHAIN_GRAPH_ABS, \ | 25 | .mode = CHAIN_GRAPH_ABS, \ |
28 | .min_percent = 0.5, \ | 26 | .min_percent = 0.5, \ |
@@ -742,58 +740,6 @@ int fetch_current_timestamp(char *buf, size_t sz) | |||
742 | return 0; | 740 | return 0; |
743 | } | 741 | } |
744 | 742 | ||
745 | void print_binary(unsigned char *data, size_t len, | ||
746 | size_t bytes_per_line, print_binary_t printer, | ||
747 | void *extra) | ||
748 | { | ||
749 | size_t i, j, mask; | ||
750 | |||
751 | if (!printer) | ||
752 | return; | ||
753 | |||
754 | bytes_per_line = roundup_pow_of_two(bytes_per_line); | ||
755 | mask = bytes_per_line - 1; | ||
756 | |||
757 | printer(BINARY_PRINT_DATA_BEGIN, 0, extra); | ||
758 | for (i = 0; i < len; i++) { | ||
759 | if ((i & mask) == 0) { | ||
760 | printer(BINARY_PRINT_LINE_BEGIN, -1, extra); | ||
761 | printer(BINARY_PRINT_ADDR, i, extra); | ||
762 | } | ||
763 | |||
764 | printer(BINARY_PRINT_NUM_DATA, data[i], extra); | ||
765 | |||
766 | if (((i & mask) == mask) || i == len - 1) { | ||
767 | for (j = 0; j < mask-(i & mask); j++) | ||
768 | printer(BINARY_PRINT_NUM_PAD, -1, extra); | ||
769 | |||
770 | printer(BINARY_PRINT_SEP, i, extra); | ||
771 | for (j = i & ~mask; j <= i; j++) | ||
772 | printer(BINARY_PRINT_CHAR_DATA, data[j], extra); | ||
773 | for (j = 0; j < mask-(i & mask); j++) | ||
774 | printer(BINARY_PRINT_CHAR_PAD, i, extra); | ||
775 | printer(BINARY_PRINT_LINE_END, -1, extra); | ||
776 | } | ||
777 | } | ||
778 | printer(BINARY_PRINT_DATA_END, -1, extra); | ||
779 | } | ||
780 | |||
781 | int is_printable_array(char *p, unsigned int len) | ||
782 | { | ||
783 | unsigned int i; | ||
784 | |||
785 | if (!p || !len || p[len - 1] != 0) | ||
786 | return 0; | ||
787 | |||
788 | len--; | ||
789 | |||
790 | for (i = 0; i < len; i++) { | ||
791 | if (!isprint(p[i]) && !isspace(p[i])) | ||
792 | return 0; | ||
793 | } | ||
794 | return 1; | ||
795 | } | ||
796 | |||
797 | int unit_number__scnprintf(char *buf, size_t size, u64 n) | 743 | int unit_number__scnprintf(char *buf, size_t size, u64 n) |
798 | { | 744 | { |
799 | char unit[4] = "BKMG"; | 745 | char unit[4] = "BKMG"; |
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index f7e1ead50f47..4d9069ab569a 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -213,33 +213,10 @@ const char *perf_tip(const char *dirpath); | |||
213 | bool is_regular_file(const char *file); | 213 | bool is_regular_file(const char *file); |
214 | int fetch_current_timestamp(char *buf, size_t sz); | 214 | int fetch_current_timestamp(char *buf, size_t sz); |
215 | 215 | ||
216 | enum binary_printer_ops { | ||
217 | BINARY_PRINT_DATA_BEGIN, | ||
218 | BINARY_PRINT_LINE_BEGIN, | ||
219 | BINARY_PRINT_ADDR, | ||
220 | BINARY_PRINT_NUM_DATA, | ||
221 | BINARY_PRINT_NUM_PAD, | ||
222 | BINARY_PRINT_SEP, | ||
223 | BINARY_PRINT_CHAR_DATA, | ||
224 | BINARY_PRINT_CHAR_PAD, | ||
225 | BINARY_PRINT_LINE_END, | ||
226 | BINARY_PRINT_DATA_END, | ||
227 | }; | ||
228 | |||
229 | typedef void (*print_binary_t)(enum binary_printer_ops, | ||
230 | unsigned int val, | ||
231 | void *extra); | ||
232 | |||
233 | void print_binary(unsigned char *data, size_t len, | ||
234 | size_t bytes_per_line, print_binary_t printer, | ||
235 | void *extra); | ||
236 | |||
237 | #ifndef HAVE_SCHED_GETCPU_SUPPORT | 216 | #ifndef HAVE_SCHED_GETCPU_SUPPORT |
238 | int sched_getcpu(void); | 217 | int sched_getcpu(void); |
239 | #endif | 218 | #endif |
240 | 219 | ||
241 | int is_printable_array(char *p, unsigned int len); | ||
242 | |||
243 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); | 220 | int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz); |
244 | 221 | ||
245 | int unit_number__scnprintf(char *buf, size_t size, u64 n); | 222 | int unit_number__scnprintf(char *buf, size_t size, u64 n); |