summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-04-17 15:51:59 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-04-19 12:01:51 -0400
commita067558e2fa72445e8f6e6b2dd372a82afae6e49 (patch)
tree5f8a79cec16d185a0589bf4654cdae2bde91a8b8
parent632a5cabea21eb079b788d2bb4a9318bd6fff5e1 (diff)
perf tools: Move extra string util functions to util/string2.h
Moving them from util.h, where they don't belong. Since libc already have string.h, name it slightly differently, as string2.h. 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-eh3vz5sqxsrdd8lodoro4jrw@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/bench/mem-functions.c1
-rw-r--r--tools/perf/builtin-script.c1
-rw-r--r--tools/perf/builtin-stat.c1
-rw-r--r--tools/perf/builtin-trace.c1
-rw-r--r--tools/perf/ui/browser.c1
-rw-r--r--tools/perf/ui/browsers/hists.c1
-rw-r--r--tools/perf/ui/gtk/hists.c1
-rw-r--r--tools/perf/ui/stdio/hist.c1
-rw-r--r--tools/perf/util/annotate.c1
-rw-r--r--tools/perf/util/dso.c1
-rw-r--r--tools/perf/util/dwarf-aux.c1
-rw-r--r--tools/perf/util/event.c2
-rw-r--r--tools/perf/util/header.c1
-rw-r--r--tools/perf/util/parse-events.c2
-rw-r--r--tools/perf/util/pmu.c1
-rw-r--r--tools/perf/util/probe-event.c1
-rw-r--r--tools/perf/util/probe-file.c1
-rw-r--r--tools/perf/util/probe-finder.c1
-rw-r--r--tools/perf/util/strfilter.c2
-rw-r--r--tools/perf/util/string.c16
-rw-r--r--tools/perf/util/string2.h42
-rw-r--r--tools/perf/util/thread_map.c1
-rw-r--r--tools/perf/util/util.h32
23 files changed, 72 insertions, 41 deletions
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index d1dea33dcfcf..fbd732b54047 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -12,6 +12,7 @@
12#include <subcmd/parse-options.h> 12#include <subcmd/parse-options.h>
13#include "../util/header.h" 13#include "../util/header.h"
14#include "../util/cloexec.h" 14#include "../util/cloexec.h"
15#include "../util/string2.h"
15#include "bench.h" 16#include "bench.h"
16#include "mem-memcpy-arch.h" 17#include "mem-memcpy-arch.h"
17#include "mem-memset-arch.h" 18#include "mem-memset-arch.h"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 5f4e36a4c444..a710f6867954 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -21,6 +21,7 @@
21#include "util/cpumap.h" 21#include "util/cpumap.h"
22#include "util/thread_map.h" 22#include "util/thread_map.h"
23#include "util/stat.h" 23#include "util/stat.h"
24#include "util/string2.h"
24#include "util/thread-stack.h" 25#include "util/thread-stack.h"
25#include "util/time-utils.h" 26#include "util/time-utils.h"
26#include "print_binary.h" 27#include "print_binary.h"
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 5abef25f9983..1da86e6708c0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -64,6 +64,7 @@
64#include "util/session.h" 64#include "util/session.h"
65#include "util/tool.h" 65#include "util/tool.h"
66#include "util/group.h" 66#include "util/group.h"
67#include "util/string2.h"
67#include "asm/bug.h" 68#include "asm/bug.h"
68 69
69#include <linux/time64.h> 70#include <linux/time64.h>
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 9a8b9e6f47f7..4160d946a34d 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -37,6 +37,7 @@
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 "print_binary.h"
40#include "string2.h"
40#include "syscalltbl.h" 41#include "syscalltbl.h"
41#include "rb_resort.h" 42#include "rb_resort.h"
42 43
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 73bdd07321c4..a4d3762cd825 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -1,4 +1,5 @@
1#include "../util.h" 1#include "../util.h"
2#include "../string2.h"
2#include "../config.h" 3#include "../config.h"
3#include "../../perf.h" 4#include "../../perf.h"
4#include "libslang.h" 5#include "libslang.h"
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index ac7f6a3e4a86..bc397bbbc3a7 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -20,6 +20,7 @@
20#include "map.h" 20#include "map.h"
21#include "annotate.h" 21#include "annotate.h"
22#include "srcline.h" 22#include "srcline.h"
23#include "string2.h"
23 24
24#include "sane_ctype.h" 25#include "sane_ctype.h"
25 26
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index a4f02de7c1b5..c42de4dcc055 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -4,6 +4,7 @@
4#include "../sort.h" 4#include "../sort.h"
5#include "../hist.h" 5#include "../hist.h"
6#include "../helpline.h" 6#include "../helpline.h"
7#include "../string2.h"
7#include "gtk.h" 8#include "gtk.h"
8 9
9#define MAX_COLUMNS 32 10#define MAX_COLUMNS 32
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 66aa4eb369f1..5565105c9688 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -5,6 +5,7 @@
5#include "../../util/sort.h" 5#include "../../util/sort.h"
6#include "../../util/evsel.h" 6#include "../../util/evsel.h"
7#include "../../util/srcline.h" 7#include "../../util/srcline.h"
8#include "../../util/string2.h"
8#include "../../util/sane_ctype.h" 9#include "../../util/sane_ctype.h"
9 10
10static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) 11static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index d69fdafba274..297bf5c66609 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -19,6 +19,7 @@
19#include "annotate.h" 19#include "annotate.h"
20#include "evsel.h" 20#include "evsel.h"
21#include "block-range.h" 21#include "block-range.h"
22#include "string2.h"
22#include "arch/common.h" 23#include "arch/common.h"
23#include <regex.h> 24#include <regex.h>
24#include <pthread.h> 25#include <pthread.h>
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 385c82e12473..6ad57730a0ed 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -8,6 +8,7 @@
8#include "auxtrace.h" 8#include "auxtrace.h"
9#include "util.h" 9#include "util.h"
10#include "debug.h" 10#include "debug.h"
11#include "string2.h"
11#include "vdso.h" 12#include "vdso.h"
12 13
13static const char * const debuglink_paths[] = { 14static const char * const debuglink_paths[] = {
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index 5fb186d142f6..780ee4629bd0 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -22,6 +22,7 @@
22#include "util.h" 22#include "util.h"
23#include "debug.h" 23#include "debug.h"
24#include "dwarf-aux.h" 24#include "dwarf-aux.h"
25#include "string2.h"
25 26
26/** 27/**
27 * cu_find_realpath - Find the realpath of the target file 28 * cu_find_realpath - Find the realpath of the target file
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f8a706ba72f2..53b81b2283c1 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -8,7 +8,7 @@
8#include "hist.h" 8#include "hist.h"
9#include "machine.h" 9#include "machine.h"
10#include "sort.h" 10#include "sort.h"
11#include "string.h" 11#include "string2.h"
12#include "strlist.h" 12#include "strlist.h"
13#include "thread.h" 13#include "thread.h"
14#include "thread_map.h" 14#include "thread_map.h"
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index faf046fc398f..51865b8cb9f3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1,5 +1,6 @@
1#include <inttypes.h> 1#include <inttypes.h>
2#include "util.h" 2#include "util.h"
3#include "string2.h"
3#include <sys/types.h> 4#include <sys/types.h>
4#include <byteswap.h> 5#include <byteswap.h>
5#include <unistd.h> 6#include <unistd.h>
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6b498aea9fde..535c7cbb2bfb 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -7,7 +7,7 @@
7#include <subcmd/parse-options.h> 7#include <subcmd/parse-options.h>
8#include "parse-events.h" 8#include "parse-events.h"
9#include <subcmd/exec-cmd.h> 9#include <subcmd/exec-cmd.h>
10#include "string.h" 10#include "string2.h"
11#include "symbol.h" 11#include "symbol.h"
12#include "cache.h" 12#include "cache.h"
13#include "header.h" 13#include "header.h"
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 11c752561c55..7503fa170249 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -15,6 +15,7 @@
15#include "header.h" 15#include "header.h"
16#include "pmu-events/pmu-events.h" 16#include "pmu-events/pmu-events.h"
17#include "cache.h" 17#include "cache.h"
18#include "string2.h"
18 19
19struct perf_pmu_format { 20struct perf_pmu_format {
20 char *name; 21 char *name;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 7caba7003734..8f1374071cfc 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -47,6 +47,7 @@
47#include "probe-finder.h" 47#include "probe-finder.h"
48#include "probe-file.h" 48#include "probe-file.h"
49#include "session.h" 49#include "session.h"
50#include "string2.h"
50 51
51#include "sane_ctype.h" 52#include "sane_ctype.h"
52 53
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 88714dec8912..7942ea5c7e81 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -28,6 +28,7 @@
28#include "probe-file.h" 28#include "probe-file.h"
29#include "session.h" 29#include "session.h"
30#include "perf_regs.h" 30#include "perf_regs.h"
31#include "string2.h"
31 32
32/* 4096 - 2 ('\n' + '\0') */ 33/* 4096 - 2 ('\n' + '\0') */
33#define MAX_CMDLEN 4094 34#define MAX_CMDLEN 4094
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 9ddd7dad2e6e..3f3cd11d3b7c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -41,6 +41,7 @@
41#include "symbol.h" 41#include "symbol.h"
42#include "probe-finder.h" 42#include "probe-finder.h"
43#include "probe-file.h" 43#include "probe-file.h"
44#include "string2.h"
44 45
45/* Kprobe tracer basic type is up to u64 */ 46/* Kprobe tracer basic type is up to u64 */
46#define MAX_BASIC_TYPE_BITS 64 47#define MAX_BASIC_TYPE_BITS 64
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index c663c9153245..3b068e0e2d59 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -1,5 +1,5 @@
1#include "util.h" 1#include "util.h"
2#include "string.h" 2#include "string2.h"
3#include "strfilter.h" 3#include "strfilter.h"
4 4
5#include "sane_ctype.h" 5#include "sane_ctype.h"
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index e716a6e5bb19..cca53b693a48 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,5 +1,7 @@
1#include "util.h" 1#include "string2.h"
2#include "linux/string.h" 2#include <linux/kernel.h>
3#include <linux/string.h>
4#include <stdlib.h>
3 5
4#include "sane_ctype.h" 6#include "sane_ctype.h"
5 7
@@ -101,8 +103,10 @@ static int count_argc(const char *str)
101void argv_free(char **argv) 103void argv_free(char **argv)
102{ 104{
103 char **p; 105 char **p;
104 for (p = argv; *p; p++) 106 for (p = argv; *p; p++) {
105 zfree(p); 107 free(*p);
108 *p = NULL;
109 }
106 110
107 free(argv); 111 free(argv);
108} 112}
@@ -122,7 +126,7 @@ void argv_free(char **argv)
122char **argv_split(const char *str, int *argcp) 126char **argv_split(const char *str, int *argcp)
123{ 127{
124 int argc = count_argc(str); 128 int argc = count_argc(str);
125 char **argv = zalloc(sizeof(*argv) * (argc+1)); 129 char **argv = calloc(argc + 1, sizeof(*argv));
126 char **argvp; 130 char **argvp;
127 131
128 if (argv == NULL) 132 if (argv == NULL)
@@ -379,7 +383,7 @@ char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints
379 goto out_err_overflow; 383 goto out_err_overflow;
380 384
381 if (i > 0) 385 if (i > 0)
382 printed += snprintf(e + printed, size - printed, " %s ", or_and); 386 printed += scnprintf(e + printed, size - printed, " %s ", or_and);
383 printed += scnprintf(e + printed, size - printed, 387 printed += scnprintf(e + printed, size - printed,
384 "%s %s %d", var, eq_neq, ints[i]); 388 "%s %s %d", var, eq_neq, ints[i]);
385 } 389 }
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
new file mode 100644
index 000000000000..2f619681bd6a
--- /dev/null
+++ b/tools/perf/util/string2.h
@@ -0,0 +1,42 @@
1#ifndef PERF_STRING_H
2#define PERF_STRING_H
3
4#include <linux/types.h>
5#include <stddef.h>
6#include <string.h>
7
8s64 perf_atoll(const char *str);
9char **argv_split(const char *str, int *argcp);
10void argv_free(char **argv);
11bool strglobmatch(const char *str, const char *pat);
12bool strglobmatch_nocase(const char *str, const char *pat);
13bool strlazymatch(const char *str, const char *pat);
14static inline bool strisglob(const char *str)
15{
16 return strpbrk(str, "*?[") != NULL;
17}
18int strtailcmp(const char *s1, const char *s2);
19char *strxfrchar(char *s, char from, char to);
20
21char *ltrim(char *s);
22char *rtrim(char *s);
23
24static inline char *trim(char *s)
25{
26 return ltrim(rtrim(s));
27}
28
29char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
30
31static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
32{
33 return asprintf_expr_inout_ints(var, true, nints, ints);
34}
35
36static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
37{
38 return asprintf_expr_inout_ints(var, false, nints, ints);
39}
40
41
42#endif /* PERF_STRING_H */
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 9026408ea55b..ef86bf517e01 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -6,6 +6,7 @@
6#include <sys/types.h> 6#include <sys/types.h>
7#include <sys/stat.h> 7#include <sys/stat.h>
8#include <unistd.h> 8#include <unistd.h>
9#include "string2.h"
9#include "strlist.h" 10#include "strlist.h"
10#include <string.h> 11#include <string.h>
11#include <api/fs/fs.h> 12#include <api/fs/fs.h>
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 46cfdccc32bc..850ca54d17a5 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -98,18 +98,6 @@ int copyfile(const char *from, const char *to);
98int copyfile_mode(const char *from, const char *to, mode_t mode); 98int copyfile_mode(const char *from, const char *to, mode_t mode);
99int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size); 99int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
100 100
101s64 perf_atoll(const char *str);
102char **argv_split(const char *str, int *argcp);
103void argv_free(char **argv);
104bool strglobmatch(const char *str, const char *pat);
105bool strglobmatch_nocase(const char *str, const char *pat);
106bool strlazymatch(const char *str, const char *pat);
107static inline bool strisglob(const char *str)
108{
109 return strpbrk(str, "*?[") != NULL;
110}
111int strtailcmp(const char *s1, const char *s2);
112char *strxfrchar(char *s, char from, char to);
113unsigned long convert_unit(unsigned long value, char *unit); 101unsigned long convert_unit(unsigned long value, char *unit);
114ssize_t readn(int fd, void *buf, size_t n); 102ssize_t readn(int fd, void *buf, size_t n);
115ssize_t writen(int fd, void *buf, size_t n); 103ssize_t writen(int fd, void *buf, size_t n);
@@ -121,14 +109,6 @@ void event_attr_init(struct perf_event_attr *attr);
121size_t hex_width(u64 v); 109size_t hex_width(u64 v);
122int hex2u64(const char *ptr, u64 *val); 110int hex2u64(const char *ptr, u64 *val);
123 111
124char *ltrim(char *s);
125char *rtrim(char *s);
126
127static inline char *trim(char *s)
128{
129 return ltrim(rtrim(s));
130}
131
132void dump_stack(void); 112void dump_stack(void);
133void sighandler_dump_stack(int sig); 113void sighandler_dump_stack(int sig);
134 114
@@ -175,18 +155,6 @@ int gzip_decompress_to_file(const char *input, int output_fd);
175int lzma_decompress_to_file(const char *input, int output_fd); 155int lzma_decompress_to_file(const char *input, int output_fd);
176#endif 156#endif
177 157
178char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
179
180static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
181{
182 return asprintf_expr_inout_ints(var, true, nints, ints);
183}
184
185static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
186{
187 return asprintf_expr_inout_ints(var, false, nints, ints);
188}
189
190int get_stack_size(const char *str, unsigned long *_size); 158int get_stack_size(const char *str, unsigned long *_size);
191 159
192int fetch_kernel_version(unsigned int *puint, 160int fetch_kernel_version(unsigned int *puint,