perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel

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>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-06-26 11:42:03 -03:00
parent 526bbbdd44
commit 328584804e
11 changed files with 23 additions and 38 deletions

View File

@ -2880,7 +2880,7 @@ static int read_script_info(struct script_desc *desc, const char *filename)
return -1; return -1;
while (fgets(line, sizeof(line), fp)) { while (fgets(line, sizeof(line), fp)) {
p = ltrim(line); p = skip_spaces(line);
if (strlen(p) == 0) if (strlen(p) == 0)
continue; continue;
if (*p != '#') if (*p != '#')
@ -2889,19 +2889,19 @@ static int read_script_info(struct script_desc *desc, const char *filename)
if (strlen(p) && *p == '!') if (strlen(p) && *p == '!')
continue; continue;
p = ltrim(p); p = skip_spaces(p);
if (strlen(p) && p[strlen(p) - 1] == '\n') if (strlen(p) && p[strlen(p) - 1] == '\n')
p[strlen(p) - 1] = '\0'; p[strlen(p) - 1] = '\0';
if (!strncmp(p, "description:", strlen("description:"))) { if (!strncmp(p, "description:", strlen("description:"))) {
p += strlen("description:"); p += strlen("description:");
desc->half_liner = strdup(ltrim(p)); desc->half_liner = strdup(skip_spaces(p));
continue; continue;
} }
if (!strncmp(p, "args:", strlen("args:"))) { if (!strncmp(p, "args:", strlen("args:"))) {
p += strlen("args:"); p += strlen("args:");
desc->args = strdup(ltrim(p)); desc->args = strdup(skip_spaces(p));
continue; continue;
} }
} }
@ -3008,7 +3008,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
return -1; return -1;
while (fgets(line, sizeof(line), fp)) { while (fgets(line, sizeof(line), fp)) {
p = ltrim(line); p = skip_spaces(line);
if (*p == '#') if (*p == '#')
continue; continue;
@ -3018,7 +3018,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
break; break;
p += 2; p += 2;
p = ltrim(p); p = skip_spaces(p);
len = strcspn(p, " \t"); len = strcspn(p, " \t");
if (!len) if (!len)
break; break;

View File

@ -594,7 +594,7 @@ static int ui_browser__color_config(const char *var, const char *value,
break; break;
*bg = '\0'; *bg = '\0';
bg = ltrim(++bg); bg = skip_spaces(bg + 1);
ui_browser__colorsets[i].bg = bg; ui_browser__colorsets[i].bg = bg;
ui_browser__colorsets[i].fg = fg; ui_browser__colorsets[i].fg = fg;
return 0; return 0;

View File

@ -1470,7 +1470,7 @@ static int hist_browser__show_hierarchy_entry(struct hist_browser *browser,
int i = 0; int i = 0;
width -= fmt->entry(fmt, &hpp, entry); 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++])) while (isspace(s[i++]))
width++; width++;

View File

@ -459,7 +459,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists *hists,
advance_hpp(hpp, ret + 2); 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) { if (!he->leaf) {
hpp->buf = bf; hpp->buf = bf;
@ -555,7 +555,7 @@ static void perf_gtk__show_hierarchy(GtkWidget *window, struct hists *hists,
first_col = false; first_col = false;
fmt->header(fmt, &hpp, hists, 0, NULL); fmt->header(fmt, &hpp, hists, 0, NULL);
strcat(buf, ltrim(rtrim(hpp.buf))); strcat(buf, trim(hpp.buf));
} }
} }

View File

@ -516,7 +516,7 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
* dynamic entries are right-aligned but we want left-aligned * dynamic entries are right-aligned but we want left-aligned
* in the hierarchy mode * 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); printed += putc('\n', fp);

View File

@ -557,7 +557,7 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_sy
if (comment == NULL) if (comment == NULL)
return 0; 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->source.raw, comment + 1, &ops->source.addr, &ops->source.name);
comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.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) if (comment == NULL)
return 0; return 0;
comment = ltrim(comment); comment = skip_spaces(comment);
comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name); comment__symbol(ops->target.raw, comment + 1, &ops->target.addr, &ops->target.name);
return 0; 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) 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') if (name[0] == '\0')
return -1; return -1;
@ -1116,7 +1116,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
goto out_free_name; goto out_free_name;
(*rawp)[0] = tmp; (*rawp)[0] = tmp;
*rawp = ltrim(*rawp); *rawp = skip_spaces(*rawp);
return 0; return 0;
@ -1503,7 +1503,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,
return 0; return 0;
} }
tmp = ltrim(parsed_line); tmp = skip_spaces(parsed_line);
if (*tmp) { if (*tmp) {
/* /*
* Parse hexa addresses followed by ':' * Parse hexa addresses followed by ':'

View File

@ -158,9 +158,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
if (name) { if (name) {
char *nl; char *nl;
name += 5; /* strlen("Name:") */ name = skip_spaces(name + 5); /* strlen("Name:") */
name = ltrim(name);
nl = strchr(name, '\n'); nl = strchr(name, '\n');
if (nl) if (nl)
*nl = '\0'; *nl = '\0';

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <linux/list.h> #include <linux/list.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/string.h>
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -1339,7 +1340,7 @@ static void wordwrap(char *s, int start, int max, int corr)
break; break;
s += wlen; s += wlen;
column += n; column += n;
s = ltrim(s); s = skip_spaces(s);
} }
} }

View File

@ -212,7 +212,7 @@ static void print_metric_csv(struct perf_stat_config *config __maybe_unused,
return; return;
} }
snprintf(buf, sizeof(buf), fmt, val); snprintf(buf, sizeof(buf), fmt, val);
ends = vals = ltrim(buf); ends = vals = skip_spaces(buf);
while (isdigit(*ends) || *ends == '.') while (isdigit(*ends) || *ends == '.')
ends++; ends++;
*ends = 0; *ends = 0;
@ -280,7 +280,7 @@ static void print_metric_only_csv(struct perf_stat_config *config __maybe_unused
return; return;
unit = fixunit(tbuf, os->evsel, unit); unit = fixunit(tbuf, os->evsel, unit);
snprintf(buf, sizeof buf, fmt, val); snprintf(buf, sizeof buf, fmt, val);
ends = vals = ltrim(buf); ends = vals = skip_spaces(buf);
while (isdigit(*ends) || *ends == '.') while (isdigit(*ends) || *ends == '.')
ends++; ends++;
*ends = 0; *ends = 0;

View File

@ -318,20 +318,6 @@ char *strxfrchar(char *s, char from, char to)
return s; 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. * rtrim - Removes trailing whitespace from @s.
* @s: The string to be stripped. * @s: The string to be stripped.

View File

@ -2,6 +2,7 @@
#ifndef PERF_STRING_H #ifndef PERF_STRING_H
#define PERF_STRING_H #define PERF_STRING_H
#include <linux/string.h>
#include <linux/types.h> #include <linux/types.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
@ -22,12 +23,11 @@ static inline bool strisglob(const char *str)
int strtailcmp(const char *s1, const char *s2); int strtailcmp(const char *s1, const char *s2);
char *strxfrchar(char *s, char from, char to); char *strxfrchar(char *s, char from, char to);
char *ltrim(char *s);
char *rtrim(char *s); char *rtrim(char *s);
static inline char *trim(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); char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);