All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>, Thomas Gleixner <tglx@linutronix.de>
Cc: Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: [PATCH 34/43] perf tools: Ditch rtrim(), use strim() from tools/lib
Date: Mon,  1 Jul 2019 23:26:07 -0300	[thread overview]
Message-ID: <20190702022616.1259-35-acme@kernel.org> (raw)
In-Reply-To: <20190702022616.1259-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

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     |  3 ++-
 tools/perf/util/annotate.c         |  3 ++-
 tools/perf/util/header.c           |  6 +++---
 tools/perf/util/pmu.c              |  2 +-
 tools/perf/util/python-ext-sources |  1 +
 tools/perf/util/srcline.c          |  3 ++-
 tools/perf/util/string.c           | 23 -----------------------
 tools/perf/util/string2.h          |  2 --
 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,
 		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,
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 @@
 #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) {
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
 		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;
 }
 
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
 	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);
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
 ../lib/bitmap.c
 ../lib/find_bit.c
 ../lib/hweight.c
+../lib/string.c
 ../lib/vsprintf.c
 util/thread_map.c
 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 @@
 #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;
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)
 	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)
 {
 	/*
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)
 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)
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 @@
 #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);
-- 
2.20.1


  parent reply	other threads:[~2019-07-02  2:28 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-02  2:25 [GIT PULL] perf/core improvements and fixes Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 01/43] perf tools: Fix cache.h include directive Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 02/43] perf thread-stack: Fix thread stack return from kernel for kernel-only case Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 03/43] perf thread-stack: Eliminate code duplicating thread_stack__pop_ks() Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 04/43] perf tools: Increase MAX_NR_CPUS and MAX_CACHES Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 05/43] perf intel-pt: Decoder to output CBR changes immediately Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 06/43] perf intel-pt: Cater for CBR change in PSB+ Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 07/43] perf intel-pt: Add CBR value to decoder state Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 08/43] perf intel-pt: Synthesize CBR events when last seen value changes Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 09/43] perf db-export: Export synth events Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 10/43] perf scripts python: export-to-sqlite.py: Export Intel PT power and ptwrite events Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 11/43] perf scripts python: export-to-postgresql.py: " Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 12/43] perf ctype: Remove unused 'graph_line' variable Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 13/43] perf ui stdio: No need to use 'spaces' to left align Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 14/43] perf ctype: Remove now unused 'spaces' variable Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 15/43] perf string: Move 'dots' and 'graph_dotted_line' out of sane_ctype.h Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 16/43] tools x86 machine: Add missing util.h to pick up 'page_size' Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 17/43] perf kallsyms: Adopt hex2u64 from tools/perf/util/util.h Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 18/43] perf symbols: We need util.h in symbol-elf.c for zfree() Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 19/43] perf tools: Remove old baggage that is util/include/linux/ctype.h Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 20/43] perf tools: Add missing util.h to pick up 'page_size' variable Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 21/43] tools perf: Move from sane_ctype.h obtained from git to the Linux's original Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 22/43] perf tools: Use linux/ctype.h in more places Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 23/43] tools lib: Adopt skip_spaces() from the kernel sources Arnaldo Carvalho de Melo
2019-07-02 12:12   ` Jiri Olsa
2019-07-02 13:46     ` Arnaldo Carvalho de Melo
2019-07-02 13:48       ` Arnaldo Carvalho de Melo
2019-07-02 13:54         ` Jiri Olsa
2019-07-02 14:02           ` Arnaldo Carvalho de Melo
2019-07-02 13:49       ` Joe Perches
2019-07-03 14:32     ` [tip:perf/core] objtool: Fix build by linking against tools/lib/ctype.o sources tip-bot for Jiri Olsa
2019-07-02  2:25 ` [PATCH 24/43] perf stat: Use recently introduced skip_spaces() Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 25/43] perf header: Use skip_spaces() in __write_cpudesc() Arnaldo Carvalho de Melo
2019-07-02  2:25 ` [PATCH 26/43] perf time-utils: Use skip_spaces() Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 27/43] perf probe: Use skip_spaces() for argv handling Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 28/43] perf strfilter: Use skip_spaces() Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 29/43] perf metricgroup: Use strsep() Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 30/43] perf report: Use skip_spaces() Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 31/43] perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 32/43] tools lib: Adopt strim() from " Arnaldo Carvalho de Melo
     [not found]   ` <CAGje9yTfFrUxj-vSX=Au856Fe_307aQqD=YrbGeWfHESQ6Rw8w@mail.gmail.com>
2019-07-02 16:00     ` Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 33/43] perf tools: Remove trim() implementation, use tools/lib's strim() Arnaldo Carvalho de Melo
2019-07-02  2:26 ` Arnaldo Carvalho de Melo [this message]
2019-07-02  2:26 ` [PATCH 35/43] tools lib: Adopt strreplace() from the kernel Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 36/43] perf tools: Drop strxfrchar(), use strreplace() equivalent from kernel Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 37/43] tools lib: Move argv_{split,free} from tools/perf/util/ Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 38/43] perf stat: Make metric event lookup more robust Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 39/43] perf stat: Don't merge events in the same PMU Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 40/43] perf stat: Fix group lookup for metric group Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 41/43] perf stat: Fix metrics with --no-merge Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 42/43] perf annotate: Add csky support Arnaldo Carvalho de Melo
2019-07-02  2:26 ` [PATCH 43/43] perf jevents: Use nonlocal include statements in pmu-events.c Arnaldo Carvalho de Melo
2019-07-03 13:55 ` [GIT PULL] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190702022616.1259-35-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.