Skip to contentSkip to conversation

perf symbols: turn dso__fprintf_symbols_by_name into void function

PATCH In review Yang Li 2 participants 2 messages Mar 8, 2021 perf events

lore
Share & tools
lore

Yang Li

author
#0 lore raw

PATCH 1/1 perf symbols: turn dso__fprintf_symbols_by_name into void function

This function always return '0' and no callers use the return value. So make it a void function.

---
 tools/perf/util/dso.h            | 2 +-
 tools/perf/util/symbol_fprintf.c | 5 +----
 2 files changed, 2 insertions(+), 5 deletions(-)
tools/perf/util/dso.h +1 -1
index cd2fe64..d7ebf21 100644
@@ -364,7 +364,7 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
 
 void dso__reset_find_symbol_cache(struct dso *dso);
 
-size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
+void dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
 size_t dso__fprintf(struct dso *dso, FILE *fp);
 
 static inline bool dso__is_vmlinux(struct dso *dso)
tools/perf/util/symbol_fprintf.c +1 -4
index 35c936c..031584e 100644
@@ -59,10 +59,9 @@ size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
 	return __symbol__fprintf_symname_offs(sym, NULL, false, false, fp);
 }
 
-size_t dso__fprintf_symbols_by_name(struct dso *dso,
+void dso__fprintf_symbols_by_name(struct dso *dso,
 				    FILE *fp)
 {
-	size_t ret = 0;
 	struct rb_node *nd;
 	struct symbol_name_rb_node *pos;
 
@@ -70,6 +69,4 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso,
 		pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 		fprintf(fp, "%s\n", pos->sym.name);
 	}
-
-	return ret;
 }
Signature · 1 line
1.8.3.1
#1 lore raw

Em Mon, Mar 08, 2021 at 04:55:04PM +0800, Yang Li escreveu:

Quoted 40 lines

This function always return '0' and no callers use the return value. So make it a void function.

---
 tools/perf/util/dso.h            | 2 +-
 tools/perf/util/symbol_fprintf.c | 5 +----
 2 files changed, 2 insertions(+), 5 deletions(-)
tools/perf/util/dso.h +1 -1
index cd2fe64..d7ebf21 100644
@@ -364,7 +364,7 @@ struct dso *machine__findnew_kernel(struct machine *machine, const char *name,
 
 void dso__reset_find_symbol_cache(struct dso *dso);
 
-size_t dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
+void dso__fprintf_symbols_by_name(struct dso *dso, FILE *fp);
 size_t dso__fprintf(struct dso *dso, FILE *fp);
 
 static inline bool dso__is_vmlinux(struct dso *dso)
tools/perf/util/symbol_fprintf.c +1 -2
index 35c936c..031584e 100644
@@ -59,10 +59,9 @@ size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
 	return __symbol__fprintf_symname_offs(sym, NULL, false, false, fp);
 }
 
-size_t dso__fprintf_symbols_by_name(struct dso *dso,
+void dso__fprintf_symbols_by_name(struct dso *dso,
 				    FILE *fp)
 {
-	size_t ret = 0;
 	struct rb_node *nd;
 	struct symbol_name_rb_node *pos;
 

tools/perf/util/symbol_fprintf.c size_t dso__fprintf_symbols_by_name(struct dso *dso, · line 74

Quoted 5 lines
tools/perf/util/symbol_fprintf.c +0 -2
@@ -70,6 +69,4 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso,
 		pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
 		fprintf(fp, "%s\n", pos->sym.name);
 	}
-
-	return ret;

The class__fprintf* functions follow the fprintf semantics, i.e. return how many bytes were printed, so the fix should instead be the one below, that I've commited to my tree, thanks for reporting!

- Arnaldo

commit 210e4c89ef61432040c6cd828fefa441f4887186

Author: Arnaldo Carvalho de Melo <[email protected]>
Date:   Mon Mar 8 11:17:51 2021 -0300

perf symbols: Fix dso__fprintf_symbols_by_name() to return the number of printed chars

The 'ret' variable was initialized to zero but then it was not updated from the fprintf() return, fix it.

cc Alexander Shishkin <[email protected]>
cc Ingo Molnar <[email protected]>
cc Jiri Olsa <[email protected]>
cc Mark Rutland <[email protected]>
cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Fixes 90f18e63fbd00513 ("perf symbols: List symbols in a dso in ascending name order")
tools/perf/util/symbol_fprintf.c +1 -1
index 35c936ce33efa6ea..2664fb65e47ada94 100644
@@ -68,7 +68,7 @@ size_t dso__fprintf_symbols_by_name(struct dso *dso,
 
 	for (nd = rb_first_cached(&dso->symbol_names); nd; nd = rb_next(nd)) {
 		pos = rb_entry(nd, struct symbol_name_rb_node, rb_node);
-		fprintf(fp, "%s\n", pos->sym.name);
+		ret += fprintf(fp, "%s\n", pos->sym.name);
 	}
 
 	return ret;