Skip to contentSkip to conversation

perf annotate: Use a ops table for annotation_line__write()

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Mar 25, 2018 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  c298304bd747d6a0b733f0becb470ff07ead0317
Gitweb:     https://git.kernel.org/tip/c298304bd747d6a0b733f0becb470ff07ead0317
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 15 Mar 2018 23:14:51 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 20 Mar 2018 15:36:18 -0300

perf annotate: Use a ops table for annotation_line__write()

To simplify the passing of arguments, the --stdio2 code will have to set all the fields with operations printing to stdout.

---
 tools/perf/ui/browsers/annotate.c | 32 +++++++++++++++-------------
 tools/perf/util/annotate.c        | 44 ++++++++++++++++++++-------------------
 tools/perf/util/annotate.h        | 19 ++++++++++-------
 3 files changed, 53 insertions(+), 42 deletions(-)
tools/perf/ui/browsers/annotate.c +18 -14
index 2b18c462b882..bed647807d37 100644
@@ -106,25 +106,29 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 	struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
 	struct annotation *notes = browser__annotation(browser);
 	struct annotation_line *al = list_entry(entry, struct annotation_line, node);
-	bool current_entry = ui_browser__is_current_entry(browser, row);
-	bool change_color = (!notes->options->hide_src_code &&
-			     (!current_entry || (browser->use_navkeypressed &&
-					         !browser->navkeypressed)));
-	int width = browser->width;
+	struct annotation_write_ops ops = {
+		.first_line		 = row == 0,
+		.current_entry		 = ui_browser__is_current_entry(browser, row),
+		.change_color		 = (!notes->options->hide_src_code &&
+					    (!ops.current_entry ||
+					     (browser->use_navkeypressed &&
+					      !browser->navkeypressed))),
+		.width			 = browser->width,
+		.obj			 = browser,
+		.set_color		 = annotate_browser__set_color,
+		.set_percent_color	 = annotate_browser__set_percent_color,
+		.set_jumps_percent_color = ui_browser__set_jumps_percent_color,
+		.printf			 = annotate_browser__printf,
+		.write_graph		 = annotate_browser__write_graph,
+	};
 
 	/* The scroll bar isn't being used */
 	if (!browser->navkeypressed)
-		width += 1;
+		ops.width += 1;
 
-	annotation_line__write(al, notes, row == 0, current_entry, change_color,
-			       width, browser,
-			       annotate_browser__set_color,
-			       annotate_browser__set_percent_color,
-			       ui_browser__set_jumps_percent_color,
-			       annotate_browser__printf,
-			       annotate_browser__write_graph);
+	annotation_line__write(al, notes, &ops);
 
-	if (current_entry)
+	if (ops.current_entry)
 		ab->selection = al;
 }
 
tools/perf/util/annotate.c +23 -21

74 lines not on this page · raw message

tools/perf/util/annotate.h +12 -7
index 27fcdacbb497..6fbb34b9bd77 100644
@@ -125,15 +125,20 @@ void disasm_line__free(struct disasm_line *dl);
 struct annotation_line *
 annotation_line__next(struct annotation_line *pos, struct list_head *head);
 
+struct annotation_write_ops {
+	bool first_line, current_entry, change_color;
+	int  width;
+	void *obj;
+	int  (*set_color)(void *obj, int color);
+	void (*set_percent_color)(void *obj, double percent, bool current);
+	int  (*set_jumps_percent_color)(void *obj, int nr, bool current);
+	void (*printf)(void *obj, const char *fmt, ...);
+	void (*write_graph)(void *obj, int graph);
+};
+
 double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes);
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
-			    bool first_line, bool current_entry, bool change_color, int width,
-			    void *obj,
-			    int  (*obj__set_color)(void *obj, int color),
-			    void (*obj__set_percent_color)(void *obj, double percent, bool current),
-			    int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
-			    void (*obj__printf)(void *obj, const char *fmt, ...),
-			    void (*obj__write_graph)(void *obj, int graph));
+			    struct annotation_write_ops *ops);
 
 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
 size_t disasm__fprintf(struct list_head *head, FILE *fp);