perf tools: Ditch rtrim(), use skip_spaces() to get closer to the kernel
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 328584804edc950fb4608c9a38e396ac71ef22b6 Gitweb: https://git.kernel.org/tip/328584804edc950fb4608c9a38e396ac71ef22b6 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Wed, 26 Jun 2019 11:42:03 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Wed, 26 Jun 2019 11:42:03 -0300
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 <[email protected]>
Cc André Goddard Rosa <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- 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(-)
tools/perf/builtin-script.c +6 -6
@@ -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 ;
tools/perf/ui/browser.c +1 -1
@@ -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 ;
tools/perf/ui/browsers/hists.c +1 -1
@@ -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++;
tools/perf/ui/gtk/hists.c +2 -2
@@ -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)); } }
tools/perf/ui/stdio/hist.c +1 -1
@@ -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);
tools/perf/util/annotate.c +5 -5
@@ -557,7 +557,7 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map_syif (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 *opsif (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, strstatic 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 ':'
tools/perf/util/event.c +1 -3
@@ -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' ;
tools/perf/util/pmu.c +2 -1
@@ -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); } }
tools/perf/util/stat-display.c +2 -2
@@ -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_unusedreturn ; 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 ;
tools/perf/util/string.c +0 -14
@@ -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.
tools/perf/util/string2.h +2 -2
@@ -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);