perf tools: Ditch rtrim(), use strim() from tools/lib
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 26 Jun 2019 15:13:13 +0000 (12:13 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 2 Jul 2019 01:50:33 +0000 (22:50 -0300)
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>
tools/perf/ui/browsers/hists.c
tools/perf/util/annotate.c
tools/perf/util/header.c
tools/perf/util/pmu.c
tools/perf/util/python-ext-sources
tools/perf/util/srcline.c
tools/perf/util/string.c
tools/perf/util/string2.h
tools/perf/util/thread_map.c

index 1024340..33e67aa 100644 (file)
@@ -2071,7 +2071,8 @@ static int hist_browser__fprintf_hierarchy_entry(struct hist_browser *browser,
                advance_hpp(&hpp, ret);
        }
 
-       printed += fprintf(fp, "%s\n", rtrim(s));
+       strim(s);
+       printed += fprintf(fp, "%s\n", s);
 
        if (he->leaf && folded_sign == '-') {
                printed += hist_browser__fprintf_callchain(browser, he, fp,
index 783e262..2d08c4b 100644 (file)
@@ -35,6 +35,7 @@
 #include <pthread.h>
 #include <linux/bitops.h>
 #include <linux/kernel.h>
+#include <linux/string.h>
 #include <bpf/libbpf.h>
 
 /* FIXME: For the HE_COLORSET */
@@ -1495,7 +1496,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,
                return -1;
 
        line_ip = -1;
-       parsed_line = rtrim(line);
+       parsed_line = strim(line);
 
        /* /filename:linenr ? Save line number and ignore. */
        if (regexec(&file_lineno, parsed_line, 2, match, 0) == 0) {
index 1eb15f7..bf26dc8 100644 (file)
@@ -1048,7 +1048,7 @@ static int cpu_cache_level__read(struct cpu_cache_level *cache, u32 cpu, u16 lev
                return -1;
 
        cache->type[len] = 0;
-       cache->type = rtrim(cache->type);
+       cache->type = strim(cache->type);
 
        scnprintf(file, PATH_MAX, "%s/size", path);
        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
        }
 
        cache->size[len] = 0;
-       cache->size = rtrim(cache->size);
+       cache->size = strim(cache->size);
 
        scnprintf(file, PATH_MAX, "%s/shared_cpu_list", path);
        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
        }
 
        cache->map[len] = 0;
-       cache->map = rtrim(cache->map);
+       cache->map = strim(cache->map);
        return 0;
 }
 
index 38dc0c6..8139a1f 100644 (file)
@@ -395,7 +395,7 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI
        buf[ret] = 0;
 
        /* Remove trailing newline from sysfs file */
-       rtrim(buf);
+       strim(buf);
 
        return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
                                     NULL, NULL, NULL);
index 648bcd8..2237bac 100644 (file)
@@ -16,6 +16,7 @@ util/namespaces.c
 ../lib/bitmap.c
 ../lib/find_bit.c
 ../lib/hweight.c
+../lib/string.c
 ../lib/vsprintf.c
 util/thread_map.c
 util/util.c
index 10ca153..1824cab 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 
 #include <linux/kernel.h>
+#include <linux/string.h>
 
 #include "util/dso.h"
 #include "util/util.h"
@@ -464,7 +465,7 @@ static struct inline_node *addr2inlines(const char *dso_name, u64 addr,
                char *srcline;
                struct symbol *inline_sym;
 
-               rtrim(funcname);
+               strim(funcname);
 
                if (getline(&filename, &filelen, fp) == -1)
                        goto out;
index 99a555e..93a5340 100644 (file)
@@ -318,29 +318,6 @@ char *strxfrchar(char *s, char from, char to)
        return s;
 }
 
-/**
- * rtrim - Removes trailing whitespace from @s.
- * @s: The string to be stripped.
- *
- * Note that the first trailing whitespace is replaced with a %NUL-terminator
- * in the given string @s. Returns @s.
- */
-char *rtrim(char *s)
-{
-       size_t size = strlen(s);
-       char *end;
-
-       if (!size)
-               return s;
-
-       end = s + size - 1;
-       while (end >= s && isspace(*end))
-               end--;
-       *(end + 1) = '\0';
-
-       return s;
-}
-
 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints)
 {
        /*
index 5bc3fea..6da835a 100644 (file)
@@ -23,8 +23,6 @@ static inline bool strisglob(const char *str)
 int strtailcmp(const char *s1, const char *s2);
 char *strxfrchar(char *s, char from, char to);
 
-char *rtrim(char *s);
-
 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
 
 static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
index 5d467d8..281bf06 100644 (file)
@@ -12,6 +12,7 @@
 #include "strlist.h"
 #include <string.h>
 #include <api/fs/fs.h>
+#include <linux/string.h>
 #include "asm/bug.h"
 #include "thread_map.h"
 #include "util.h"
@@ -392,7 +393,7 @@ static int get_comm(char **comm, pid_t pid)
                 * mark the end of the string.
                 */
                (*comm)[size] = 0;
-               rtrim(*comm);
+               strim(*comm);
        }
 
        free(path);