Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5cb2aef authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge tag 'perf-core-for-mingo' of...

Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

 into perf/core

Pull perf/core improvements and fixes from Arnaldo Carvalho de Melo:

 * Don't pass const char pointers to basename, so that we can unconditionally
   use libgen.h and thus avoid ifdef BIONIC lines, from David Ahern

 * Fix assert/BUG_ON when NDEBUG is defined, from Irina Tirdea.

 * Refactor hist formatting so that it can be reused with the GTK browser,
   From Namhyung Kim

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents ef34eb4d 6c7f6312
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -403,7 +403,9 @@ LIB_OBJS += $(OUTPUT)util/cgroup.o
LIB_OBJS += $(OUTPUT)util/target.o
LIB_OBJS += $(OUTPUT)util/rblist.o
LIB_OBJS += $(OUTPUT)util/intlist.o

LIB_OBJS += $(OUTPUT)ui/helpline.o
LIB_OBJS += $(OUTPUT)ui/hist.o
LIB_OBJS += $(OUTPUT)ui/stdio/hist.o

BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
+3 −3
Original line number Diff line number Diff line
@@ -56,13 +56,13 @@ int bench_sched_pipe(int argc, const char **argv,
	 * causes error in building environment for perf
	 */
	int __used ret, wait_stat;
	pid_t pid, retpid;
	pid_t pid, retpid __used;

	argc = parse_options(argc, argv, options,
			     bench_sched_pipe_usage, 0);

	assert(!pipe(pipe_1));
	assert(!pipe(pipe_2));
	BUG_ON(pipe(pipe_1));
	BUG_ON(pipe(pipe_2));

	pid = fork();
	assert(pid >= 0);
+1 −0
Original line number Diff line number Diff line
@@ -264,6 +264,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix __used)
	if (symbol__init() < 0)
		return -1;

	perf_hpp__init(true, show_displacement);
	setup_sorting(diff_usage, options);
	setup_pager();

+73 −23
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ struct hist_browser {
	bool		     has_symbols;
};

extern void hist_browser__init_hpp(void);

static int hists__browser_title(struct hists *hists, char *bf, size_t size,
				const char *ev_name);

@@ -563,14 +565,47 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
	return row - first_row;
}

#define HPP__COLOR_FN(_name, _field)					\
static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp,	\
					     struct hist_entry *he)	\
{									\
	double percent = 100.0 * he->_field / hpp->total_period;	\
	*(double *)hpp->ptr = percent;					\
	return scnprintf(hpp->buf, hpp->size, "%5.2f%%", percent);	\
}

HPP__COLOR_FN(overhead, period)
HPP__COLOR_FN(overhead_sys, period_sys)
HPP__COLOR_FN(overhead_us, period_us)
HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
HPP__COLOR_FN(overhead_guest_us, period_guest_us)

#undef HPP__COLOR_FN

void hist_browser__init_hpp(void)
{
	perf_hpp__init(false, false);

	perf_hpp__format[PERF_HPP__OVERHEAD].color =
				hist_browser__hpp_color_overhead;
	perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
				hist_browser__hpp_color_overhead_sys;
	perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
				hist_browser__hpp_color_overhead_us;
	perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
				hist_browser__hpp_color_overhead_guest_sys;
	perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
				hist_browser__hpp_color_overhead_guest_us;
}

static int hist_browser__show_entry(struct hist_browser *browser,
				    struct hist_entry *entry,
				    unsigned short row)
{
	char s[256];
	double percent;
	int printed = 0;
	int width = browser->b.width - 6; /* The percentage */
	int i, printed = 0;
	int width = browser->b.width - 1;
	char folded_sign = ' ';
	bool current_entry = ui_browser__is_current_entry(&browser->b, row);
	off_t row_offset = entry->row_offset;
@@ -586,35 +621,50 @@ static int hist_browser__show_entry(struct hist_browser *browser,
	}

	if (row_offset == 0) {
		hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
		percent = (entry->period * 100.0) / browser->hists->stats.total_period;
		struct perf_hpp hpp = {
			.buf		= s,
			.size		= sizeof(s),
			.total_period	= browser->hists->stats.total_period,
		};

		ui_browser__gotorc(&browser->b, row, 1);

		for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
			if (!perf_hpp__format[i].cond)
				continue;

			if (i) {
				slsmg_printf("  ");
				width -= 2;
			}

			if (perf_hpp__format[i].color) {
				hpp.ptr = &percent;
				/* It will set percent for us. See HPP__COLOR_FN above. */
				width -= perf_hpp__format[i].color(&hpp, entry);

				ui_browser__set_percent_color(&browser->b, percent, current_entry);
		ui_browser__gotorc(&browser->b, row, 0);
		if (symbol_conf.use_callchain) {

				if (i == 0 && symbol_conf.use_callchain) {
					slsmg_printf("%c ", folded_sign);
					width -= 2;
				}

		slsmg_printf(" %5.2f%%", percent);

		/* The scroll bar isn't being used */
		if (!browser->b.navkeypressed)
			width += 1;
				slsmg_printf("%s", s);

				if (!current_entry || !browser->b.navkeypressed)
					ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);

		if (symbol_conf.show_nr_samples) {
			slsmg_printf(" %11u", entry->nr_events);
			width -= 12;
			} else {
				width -= perf_hpp__format[i].entry(&hpp, entry);
				slsmg_printf("%s", s);
			}

		if (symbol_conf.show_total_period) {
			slsmg_printf(" %12" PRIu64, entry->period);
			width -= 13;
		}

		/* The scroll bar isn't being used */
		if (!browser->b.navkeypressed)
			width += 1;

		hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
		slsmg_write_nstring(s, width);
		++row;
		++printed;
+85 −16
Original line number Diff line number Diff line
@@ -36,6 +36,57 @@ static void perf_gtk__resize_window(GtkWidget *window)
	gtk_window_resize(GTK_WINDOW(window), width, height);
}

static const char *perf_gtk__get_percent_color(double percent)
{
	if (percent >= MIN_RED)
		return "<span fgcolor='red'>";
	if (percent >= MIN_GREEN)
		return "<span fgcolor='dark green'>";
	return NULL;
}

#define HPP__COLOR_FN(_name, _field)						\
static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp,			\
					 struct hist_entry *he)			\
{										\
	double percent = 100.0 * he->_field / hpp->total_period;		\
	const char *markup;							\
	int ret = 0;								\
										\
	markup = perf_gtk__get_percent_color(percent);				\
	if (markup)								\
		ret += scnprintf(hpp->buf, hpp->size, "%s", markup);		\
	ret += scnprintf(hpp->buf + ret, hpp->size - ret, "%5.2f%%", percent); 	\
	if (markup)								\
		ret += scnprintf(hpp->buf + ret, hpp->size - ret, "</span>"); 	\
										\
	return ret;								\
}

HPP__COLOR_FN(overhead, period)
HPP__COLOR_FN(overhead_sys, period_sys)
HPP__COLOR_FN(overhead_us, period_us)
HPP__COLOR_FN(overhead_guest_sys, period_guest_sys)
HPP__COLOR_FN(overhead_guest_us, period_guest_us)

#undef HPP__COLOR_FN

void perf_gtk__init_hpp(void)
{
	perf_hpp__init(false, false);

	perf_hpp__format[PERF_HPP__OVERHEAD].color =
				perf_gtk__hpp_color_overhead;
	perf_hpp__format[PERF_HPP__OVERHEAD_SYS].color =
				perf_gtk__hpp_color_overhead_sys;
	perf_hpp__format[PERF_HPP__OVERHEAD_US].color =
				perf_gtk__hpp_color_overhead_us;
	perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].color =
				perf_gtk__hpp_color_overhead_guest_sys;
	perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].color =
				perf_gtk__hpp_color_overhead_guest_us;
}

static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
{
	GType col_types[MAX_COLUMNS];
@@ -43,15 +94,25 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
	struct sort_entry *se;
	GtkListStore *store;
	struct rb_node *nd;
	u64 total_period;
	GtkWidget *view;
	int col_idx;
	int i, col_idx;
	int nr_cols;
	char s[512];

	struct perf_hpp hpp = {
		.buf		= s,
		.size		= sizeof(s),
		.total_period	= hists->stats.total_period,
	};

	nr_cols = 0;

	/* The percentage column */
	for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
		if (!perf_hpp__format[i].cond)
			continue;

		col_types[nr_cols++] = G_TYPE_STRING;
	}

	list_for_each_entry(se, &hist_entry__sort_list, list) {
		if (se->elide)
@@ -68,11 +129,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)

	col_idx = 0;

	/* The percentage column */
	for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
		if (!perf_hpp__format[i].cond)
			continue;

		perf_hpp__format[i].header(&hpp);

		gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
						    -1, "Overhead (%)",
						    renderer, "text",
							    -1, s,
							    renderer, "markup",
							    col_idx++, NULL);
	}

	list_for_each_entry(se, &hist_entry__sort_list, list) {
		if (se->elide)
@@ -88,13 +155,9 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)

	g_object_unref(GTK_TREE_MODEL(store));

	total_period = hists->stats.total_period;

	for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
		struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
		GtkTreeIter iter;
		double percent;
		char s[512];

		if (h->filtered)
			continue;
@@ -103,11 +166,17 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)

		col_idx = 0;

		percent = (h->period * 100.0) / total_period;
		for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
			if (!perf_hpp__format[i].cond)
				continue;

		snprintf(s, ARRAY_SIZE(s), "%.2f", percent);
			if (perf_hpp__format[i].color)
				perf_hpp__format[i].color(&hpp, h);
			else
				perf_hpp__format[i].entry(&hpp, h);

			gtk_list_store_set(store, &iter, col_idx++, s, -1);
		}

		list_for_each_entry(se, &hist_entry__sort_list, list) {
			if (se->elide)
Loading