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>,
"André Goddard Rosa" <andre.goddard@gmail.com>
Subject: [PATCH 31/43] perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel
Date: Mon, 1 Jul 2019 23:26:04 -0300 [thread overview]
Message-ID: <20190702022616.1259-32-acme@kernel.org> (raw)
In-Reply-To: <20190702022616.1259-1-acme@kernel.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
No change in behaviour, just using the same kernel idiom for such
operation.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: André Goddard Rosa <andre.goddard@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-a85lkptkt0ru40irpga8yf54@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-script.c | 12 ++++++------
tools/perf/ui/browser.c | 2 +-
tools/perf/ui/browsers/hists.c | 2 +-
tools/perf/ui/gtk/hists.c | 4 ++--
tools/perf/ui/stdio/hist.c | 2 +-
tools/perf/util/annotate.c | 10 +++++-----
tools/perf/util/event.c | 4 +---
tools/perf/util/pmu.c | 3 ++-
tools/perf/util/stat-display.c | 4 ++--
tools/perf/util/string.c | 14 --------------
tools/perf/util/string2.h | 4 ++--
11 files changed, 23 insertions(+), 38 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0131f7a0d48d..520e5b6b9ef9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2880,7 +2880,7 @@ static int read_script_info(struct script_desc *desc, const char *filename)
return -1;
while (fgets(line, sizeof(line), fp)) {
- p = ltrim(line);
+ p = skip_spaces(line);
if (strlen(p) == 0)
continue;
if (*p != '#')
@@ -2889,19 +2889,19 @@ static int read_script_info(struct script_desc *desc, const char *filename)
if (strlen(p) && *p == '!')
continue;
- p = ltrim(p);
+ p = skip_spaces(p);
if (strlen(p) && p[strlen(p) - 1] == '\n')
p[strlen(p) - 1] = '\0';
if (!strncmp(p, "description:", strlen("description:"))) {
p += strlen("description:");
- desc->half_liner = strdup(ltrim(p));
+ desc->half_liner = strdup(skip_spaces(p));
continue;
}
if (!strncmp(p, "args:", strlen("args:"))) {
p += strlen("args:");
- desc->args = strdup(ltrim(p));
+ desc->args = strdup(skip_spaces(p));
continue;
}
}
@@ -3008,7 +3008,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
return -1;
while (fgets(line, sizeof(line), fp)) {
- p = ltrim(line);
+ p = skip_spaces(line);
if (*p == '#')
continue;
@@ -3018,7 +3018,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
break;
p += 2;
- p = ltrim(p);
+ p = skip_spaces(p);
len = strcspn(p, " \t");
if (!len)
break;
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 8812c1564995..55ff05a46e0b 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -594,7 +594,7 @@ static int ui_browser__color_config(const char *var, const char *value,
break;
*bg = '\0';
- bg = ltrim(++bg);
+ bg = skip_spaces(bg + 1);
ui_browser__colorsets[i].bg = bg;
ui_browser__colorsets[i].fg = fg;
return 0;
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 59483bdb0027..04a56114df92 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1470,7 +1470,7 @@ static int hist_browser__show_hierarchy_entry(struct hist_browser *browser,
int i = 0;
width -= fmt->entry(fmt, &hpp, entry);
- ui_browser__printf(&browser->b, "%s", ltrim(s));
+ ui_browser__printf(&browser->b, "%s", skip_spaces(s));
while (isspace(s[i++]))
width++;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 0c08890f006a..6341c421a8f7 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -459,7 +459,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists *hists,
advance_hpp(hpp, ret + 2);
}
- gtk_tree_store_set(store, &iter, col_idx, ltrim(rtrim(bf)), -1);
+ gtk_tree_store_set(store, &iter, col_idx, trim(bf), -1);
if (!he->leaf) {
hpp->buf = bf;
@@ -555,7 +555,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, struct hists *hists,
first_col = false;
fmt->header(fmt, &hpp, hists, 0, NULL);
- strcat(buf, ltrim(rtrim(hpp.buf)));
+ strcat(buf, trim(hpp.buf));
}
}
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 4b1a6e921d1c..594e56628904 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -516,7 +516,7 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
* dynamic entries are right-aligned but we want left-aligned
* in the hierarchy mode
*/
- printed += fprintf(fp, "%s%s", sep ?: " ", ltrim(buf));
+ printed += fprintf(fp, "%s%s", sep ?: " ", skip_spaces(buf));
}
printed += putc('\n', fp);
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 65005ccea232..783e2628cc8e 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -557,7 +557,7 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy
if (comment == NULL)
return 0;
- comment = ltrim(comment);
+ comment = skip_spaces(comment);
comment__symbol(ops->source.raw, comment + 1, &ops->source.addr, &ops->source.name);
comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name);
@@ -602,7 +602,7 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *ops
if (comment == NULL)
return 0;
- comment = ltrim(comment);
+ comment = skip_spaces(comment);
comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name);
return 0;
@@ -1098,7 +1098,7 @@ static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, str
static int disasm_line__parse(char *line, const char **namep, char **rawp)
{
- char tmp, *name = ltrim(line);
+ char tmp, *name = skip_spaces(line);
if (name[0] == '\0')
return -1;
@@ -1116,7 +1116,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
goto out_free_name;
(*rawp)[0] = tmp;
- *rawp = ltrim(*rawp);
+ *rawp = skip_spaces(*rawp);
return 0;
@@ -1503,7 +1503,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,
return 0;
}
- tmp = ltrim(parsed_line);
+ tmp = skip_spaces(parsed_line);
if (*tmp) {
/*
* Parse hexa addresses followed by ':'
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index d8f8a20543c5..e1d0c5ba1f92 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -158,9 +158,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
if (name) {
char *nl;
- name += 5; /* strlen("Name:") */
- name = ltrim(name);
-
+ name = skip_spaces(name + 5); /* strlen("Name:") */
nl = strchr(name, '\n');
if (nl)
*nl = '\0';
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index faa8eb231e1b..38dc0c6e28b8 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/list.h>
#include <linux/compiler.h>
+#include <linux/string.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
@@ -1339,7 +1340,7 @@ static void wordwrap(char *s, int start, int max, int corr)
break;
s += wlen;
column += n;
- s = ltrim(s);
+ s = skip_spaces(s);
}
}
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index ce993d29cca5..90df41169113 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -212,7 +212,7 @@ static void print_metric_csv(struct perf_stat_config *config __maybe_unused,
return;
}
snprintf(buf, sizeof(buf), fmt, val);
- ends = vals = ltrim(buf);
+ ends = vals = skip_spaces(buf);
while (isdigit(*ends) || *ends == '.')
ends++;
*ends = 0;
@@ -280,7 +280,7 @@ static void print_metric_only_csv(struct perf_stat_config *config __maybe_unused
return;
unit = fixunit(tbuf, os->evsel, unit);
snprintf(buf, sizeof buf, fmt, val);
- ends = vals = ltrim(buf);
+ ends = vals = skip_spaces(buf);
while (isdigit(*ends) || *ends == '.')
ends++;
*ends = 0;
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index d28e723e2790..99a555ea4a9f 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -318,20 +318,6 @@ char *strxfrchar(char *s, char from, char to)
return s;
}
-/**
- * ltrim - Removes leading whitespace from @s.
- * @s: The string to be stripped.
- *
- * Return pointer to the first non-whitespace character in @s.
- */
-char *ltrim(char *s)
-{
- while (isspace(*s))
- s++;
-
- return s;
-}
-
/**
* rtrim - Removes trailing whitespace from @s.
* @s: The string to be stripped.
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
index 07fd37568543..db02059e31c5 100644
--- a/tools/perf/util/string2.h
+++ b/tools/perf/util/string2.h
@@ -2,6 +2,7 @@
#ifndef PERF_STRING_H
#define PERF_STRING_H
+#include <linux/string.h>
#include <linux/types.h>
#include <stddef.h>
#include <string.h>
@@ -22,12 +23,11 @@ static inline bool strisglob(const char *str)
int strtailcmp(const char *s1, const char *s2);
char *strxfrchar(char *s, char from, char to);
-char *ltrim(char *s);
char *rtrim(char *s);
static inline char *trim(char *s)
{
- return ltrim(rtrim(s));
+ return skip_spaces(rtrim(s));
}
char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
--
2.20.1
next prev 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 ` Arnaldo Carvalho de Melo [this message]
2019-07-02 2:26 ` [PATCH 32/43] tools lib: Adopt strim() from the kernel 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 ` [PATCH 34/43] perf tools: Ditch rtrim(), use strim() from tools/lib Arnaldo Carvalho de Melo
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-32-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=andre.goddard@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).