diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-06-26 11:13:13 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-07-01 21:50:33 -0400 |
commit | 13c230ab6e56c6ae3a968f01f4c6505b794cecad (patch) | |
tree | e29882ad70bfa5268376f411084c68c5c5d37229 | |
parent | 3ca43b6053c9a5dbbffb02aa010c1ccf8eb460a8 (diff) |
perf tools: Ditch rtrim(), use strim() from tools/lib
Cleaning up a bit more tools/perf/util/ by using things we got from the
kernel and have in tools/lib/
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-7hluuoveryoicvkclshzjf1k@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/ui/browsers/hists.c | 3 | ||||
-rw-r--r-- | tools/perf/util/annotate.c | 3 | ||||
-rw-r--r-- | tools/perf/util/header.c | 6 | ||||
-rw-r--r-- | tools/perf/util/pmu.c | 2 | ||||
-rw-r--r-- | tools/perf/util/python-ext-sources | 1 | ||||
-rw-r--r-- | tools/perf/util/srcline.c | 3 | ||||
-rw-r--r-- | tools/perf/util/string.c | 23 | ||||
-rw-r--r-- | tools/perf/util/string2.h | 2 | ||||
-rw-r--r-- | tools/perf/util/thread_map.c | 3 |
9 files changed, 13 insertions, 33 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 10243408f3dc..33e67aa91347 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -2071,7 +2071,8 @@ static int hist_browser__fprintf_hierarchy_entry(struct hist_browser *browser, | |||
2071 | advance_hpp(&hpp, ret); | 2071 | advance_hpp(&hpp, ret); |
2072 | } | 2072 | } |
2073 | 2073 | ||
2074 | printed += fprintf(fp, "%s\n", rtrim(s)); | 2074 | strim(s); |
2075 | printed += fprintf(fp, "%s\n", s); | ||
2075 | 2076 | ||
2076 | if (he->leaf && folded_sign == '-') { | 2077 | if (he->leaf && folded_sign == '-') { |
2077 | printed += hist_browser__fprintf_callchain(browser, he, fp, | 2078 | printed += hist_browser__fprintf_callchain(browser, he, fp, |
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 783e2628cc8e..2d08c4b62c63 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <pthread.h> | 35 | #include <pthread.h> |
36 | #include <linux/bitops.h> | 36 | #include <linux/bitops.h> |
37 | #include <linux/kernel.h> | 37 | #include <linux/kernel.h> |
38 | #include <linux/string.h> | ||
38 | #include <bpf/libbpf.h> | 39 | #include <bpf/libbpf.h> |
39 | 40 | ||
40 | /* FIXME: For the HE_COLORSET */ | 41 | /* FIXME: For the HE_COLORSET */ |
@@ -1495,7 +1496,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file, | |||
1495 | return -1; | 1496 | return -1; |
1496 | 1497 | ||
1497 | line_ip = -1; | 1498 | line_ip = -1; |
1498 | parsed_line = rtrim(line); | 1499 | parsed_line = strim(line); |
1499 | 1500 | ||
1500 | /* /filename:linenr ? Save line number and ignore. */ | 1501 | /* /filename:linenr ? Save line number and ignore. */ |
1501 | if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) { | 1502 | if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) { |
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 1eb15f7517b0..bf26dc85eaaa 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c | |||
@@ -1048,7 +1048,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev | |||
1048 | return -1; | 1048 | return -1; |
1049 | 1049 | ||
1050 | cache->type[len] = 0; | 1050 | cache->type[len] = 0; |
1051 | cache->type = rtrim(cache->type); | 1051 | cache->type = strim(cache->type); |
1052 | 1052 | ||
1053 | scnprintf(file, PATH_MAX, "%s/size", path); | 1053 | scnprintf(file, PATH_MAX, "%s/size", path); |
1054 | if (sysfs__read_str(file, &cache->size, &len)) { | 1054 | if (sysfs__read_str(file, &cache->size, &len)) { |
@@ -1057,7 +1057,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev | |||
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | cache->size[len] = 0; | 1059 | cache->size[len] = 0; |
1060 | cache->size = rtrim(cache->size); | 1060 | cache->size = strim(cache->size); |
1061 | 1061 | ||
1062 | scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path); | 1062 | scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path); |
1063 | if (sysfs__read_str(file, &cache->map, &len)) { | 1063 | if (sysfs__read_str(file, &cache->map, &len)) { |
@@ -1067,7 +1067,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev | |||
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | cache->map[len] = 0; | 1069 | cache->map[len] = 0; |
1070 | cache->map = rtrim(cache->map); | 1070 | cache->map = strim(cache->map); |
1071 | return 0; | 1071 | return 0; |
1072 | } | 1072 | } |
1073 | 1073 | ||
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 38dc0c6e28b8..8139a1f3ed39 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -395,7 +395,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI | |||
395 | buf[ret] = 0; | 395 | buf[ret] = 0; |
396 | 396 | ||
397 | /* Remove trailing newline from sysfs file */ | 397 | /* Remove trailing newline from sysfs file */ |
398 | rtrim(buf); | 398 | strim(buf); |
399 | 399 | ||
400 | return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL, | 400 | return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL, |
401 | NULL, NULL, NULL); | 401 | NULL, NULL, NULL); |
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources index 648bcd80b475..2237bac9fadb 100644 --- a/tools/perf/util/python-ext-sources +++ b/tools/perf/util/python-ext-sources | |||
@@ -16,6 +16,7 @@ util/namespaces.c | |||
16 | ../lib/bitmap.c | 16 | ../lib/bitmap.c |
17 | ../lib/find_bit.c | 17 | ../lib/find_bit.c |
18 | ../lib/hweight.c | 18 | ../lib/hweight.c |
19 | ../lib/string.c | ||
19 | ../lib/vsprintf.c | 20 | ../lib/vsprintf.c |
20 | util/thread_map.c | 21 | util/thread_map.c |
21 | util/util.c | 22 | util/util.c |
diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index 10ca1533937e..1824cabe3512 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <string.h> | 5 | #include <string.h> |
6 | 6 | ||
7 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
8 | #include <linux/string.h> | ||
8 | 9 | ||
9 | #include "util/dso.h" | 10 | #include "util/dso.h" |
10 | #include "util/util.h" | 11 | #include "util/util.h" |
@@ -464,7 +465,7 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr, | |||
464 | char *srcline; | 465 | char *srcline; |
465 | struct symbol *inline_sym; | 466 | struct symbol *inline_sym; |
466 | 467 | ||
467 | rtrim(funcname); | 468 | strim(funcname); |
468 | 469 | ||
469 | if (getline(&filename, &filelen, fp) == -1) | 470 | if (getline(&filename, &filelen, fp) == -1) |
470 | goto out; | 471 | goto out; |
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index 99a555ea4a9f..93a5340424df 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c | |||
@@ -318,29 +318,6 @@ char *strxfrchar(char *s, char from, char to) | |||
318 | return s; | 318 | return s; |
319 | } | 319 | } |
320 | 320 | ||
321 | /** | ||
322 | * rtrim - Removes trailing whitespace from @s. | ||
323 | * @s: The string to be stripped. | ||
324 | * | ||
325 | * Note that the first trailing whitespace is replaced with a %NUL-terminator | ||
326 | * in the given string @s. Returns @s. | ||
327 | */ | ||
328 | char *rtrim(char *s) | ||
329 | { | ||
330 | size_t size = strlen(s); | ||
331 | char *end; | ||
332 | |||
333 | if (!size) | ||
334 | return s; | ||
335 | |||
336 | end = s + size - 1; | ||
337 | while (end >= s && isspace(*end)) | ||
338 | end--; | ||
339 | *(end + 1) = '\0'; | ||
340 | |||
341 | return s; | ||
342 | } | ||
343 | |||
344 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) | 321 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints) |
345 | { | 322 | { |
346 | /* | 323 | /* |
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h index 5bc3fea52cdc..6da835ad8f5b 100644 --- a/tools/perf/util/string2.h +++ b/tools/perf/util/string2.h | |||
@@ -23,8 +23,6 @@ static inline bool strisglob(const char *str) | |||
23 | int strtailcmp(const char *s1, const char *s2); | 23 | int strtailcmp(const char *s1, const char *s2); |
24 | char *strxfrchar(char *s, char from, char to); | 24 | char *strxfrchar(char *s, char from, char to); |
25 | 25 | ||
26 | char *rtrim(char *s); | ||
27 | |||
28 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); | 26 | char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints); |
29 | 27 | ||
30 | static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints) | 28 | static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints) |
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c index 5d467d8ae9ab..281bf06f10f2 100644 --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "strlist.h" | 12 | #include "strlist.h" |
13 | #include <string.h> | 13 | #include <string.h> |
14 | #include <api/fs/fs.h> | 14 | #include <api/fs/fs.h> |
15 | #include <linux/string.h> | ||
15 | #include "asm/bug.h" | 16 | #include "asm/bug.h" |
16 | #include "thread_map.h" | 17 | #include "thread_map.h" |
17 | #include "util.h" | 18 | #include "util.h" |
@@ -392,7 +393,7 @@ static int get_comm(char **comm, pid_t pid) | |||
392 | * mark the end of the string. | 393 | * mark the end of the string. |
393 | */ | 394 | */ |
394 | (*comm)[size] = 0; | 395 | (*comm)[size] = 0; |
395 | rtrim(*comm); | 396 | strim(*comm); |
396 | } | 397 | } |
397 | 398 | ||
398 | free(path); | 399 | free(path); |