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

Commit c942ee2e 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/urgent

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

 * Remove several cases of needless global variables, on most builtins.

 * Look up thread using tid instead of pid in 'perf sched'.

 * Move global variables into a perf_kvm struct, from David Ahern.

 * Hists refactorings, preparatory for improved 'diff' command, from Jiri Olsa.

 * Hists refactorings, preparatory for event group viewieng work, from Namhyung Kim.

 * Remove double negation on optional feature macro definitions, from Namhyung Kim.

 * Bash auto completion improvements, now we can auto complete the tools long
   options, tracepoint event names, etc, from Namhyung Kim.

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents e717bf4e 139c0815
Loading
Loading
Loading
Loading
+29 −54
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ include config/utilities.mak
#
# Define NO_LIBUNWIND if you do not want libunwind dependency for dwarf
# backtrace post unwind.
#
# Define NO_BACKTRACE if you do not want stack backtrace debug feature

$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
	@$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
@@ -185,7 +187,7 @@ strip-libs = $(filter-out -l%,$(1))
PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py

$(OUTPUT)python/perf.so: $(PYRF_OBJS) $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
	$(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \
	  --quiet build_ext; \
	mkdir -p $(OUTPUT)python && \
@@ -446,20 +448,6 @@ BUILTIN_OBJS += $(OUTPUT)builtin-inject.o

PERFLIBS = $(LIB_FILE) $(LIBTRACEEVENT)

# Files needed for the python binding, perf.so
# pyrf is just an internal name needed for all those wrappers.
# This has to be in sync with what is in the 'sources' variable in
# tools/perf/util/setup.py

PYRF_OBJS += $(OUTPUT)util/cpumap.o
PYRF_OBJS += $(OUTPUT)util/ctype.o
PYRF_OBJS += $(OUTPUT)util/evlist.o
PYRF_OBJS += $(OUTPUT)util/evsel.o
PYRF_OBJS += $(OUTPUT)util/python.o
PYRF_OBJS += $(OUTPUT)util/thread_map.o
PYRF_OBJS += $(OUTPUT)util/util.o
PYRF_OBJS += $(OUTPUT)util/xyarray.o

#
# Platform specific tweaks
#
@@ -486,7 +474,13 @@ ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF)),y)
		NO_DWARF := 1
		NO_DEMANGLE := 1
	endif
endif
else
	FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
	ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
		msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
		NO_DWARF := 1
	endif # Dwarf support
endif # SOURCE_LIBELF
endif # NO_LIBELF

ifndef NO_LIBUNWIND
@@ -511,8 +505,6 @@ ifneq ($(OUTPUT),)
endif

ifdef NO_LIBELF
BASIC_CFLAGS += -DNO_LIBELF_SUPPORT

EXTLIBS := $(filter-out -lelf,$(EXTLIBS))

# Remove ELF/DWARF dependent codes
@@ -527,17 +519,12 @@ BUILTIN_OBJS := $(filter-out $(OUTPUT)builtin-probe.o,$(BUILTIN_OBJS))
LIB_OBJS += $(OUTPUT)util/symbol-minimal.o

else # NO_LIBELF
BASIC_CFLAGS += -DLIBELF_SUPPORT

ifneq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_COMMON)),y)
	BASIC_CFLAGS += -DLIBELF_NO_MMAP
ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_COMMON)),y)
	BASIC_CFLAGS += -DLIBELF_MMAP
endif

FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
	msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
	NO_DWARF := 1
endif # Dwarf support

ifndef NO_DWARF
ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
	msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
@@ -550,38 +537,33 @@ endif # PERF_HAVE_DWARF_REGS
endif # NO_DWARF
endif # NO_LIBELF

ifdef NO_LIBUNWIND
	BASIC_CFLAGS += -DNO_LIBUNWIND_SUPPORT
else
ifndef NO_LIBUNWIND
	BASIC_CFLAGS += -DLIBUNWIND_SUPPORT
	EXTLIBS += $(LIBUNWIND_LIBS)
	BASIC_CFLAGS := $(LIBUNWIND_CFLAGS) $(BASIC_CFLAGS)
	BASIC_LDFLAGS := $(LIBUNWIND_LDFLAGS) $(BASIC_LDFLAGS)
	LIB_OBJS += $(OUTPUT)util/unwind.o
endif

ifdef NO_LIBAUDIT
	BASIC_CFLAGS += -DNO_LIBAUDIT_SUPPORT
else
ifndef NO_LIBAUDIT
	FLAGS_LIBAUDIT = $(ALL_CFLAGS) $(ALL_LDFLAGS) -laudit
	ifneq ($(call try-cc,$(SOURCE_LIBAUDIT),$(FLAGS_LIBAUDIT)),y)
		msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
		BASIC_CFLAGS += -DNO_LIBAUDIT_SUPPORT
	else
		BASIC_CFLAGS += -DLIBAUDIT_SUPPORT
		BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
		EXTLIBS += -laudit
	endif
endif

ifdef NO_NEWT
	BASIC_CFLAGS += -DNO_NEWT_SUPPORT
else
ifndef NO_NEWT
	FLAGS_NEWT=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lnewt
	ifneq ($(call try-cc,$(SOURCE_NEWT),$(FLAGS_NEWT)),y)
		msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
		BASIC_CFLAGS += -DNO_NEWT_SUPPORT
	else
		# Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
		BASIC_CFLAGS += -I/usr/include/slang
		BASIC_CFLAGS += -DNEWT_SUPPORT
		EXTLIBS += -lnewt -lslang
		LIB_OBJS += $(OUTPUT)ui/setup.o
		LIB_OBJS += $(OUTPUT)ui/browser.o
@@ -603,17 +585,15 @@ else
	endif
endif

ifdef NO_GTK2
	BASIC_CFLAGS += -DNO_GTK2_SUPPORT
else
ifndef NO_GTK2
	FLAGS_GTK2=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
	ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2)),y)
		msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
		BASIC_CFLAGS += -DNO_GTK2_SUPPORT
	else
		ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2)),y)
			BASIC_CFLAGS += -DHAVE_GTK_INFO_BAR
		endif
		BASIC_CFLAGS += -DGTK2_SUPPORT
		BASIC_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
		EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
		LIB_OBJS += $(OUTPUT)ui/gtk/browser.o
@@ -621,7 +601,7 @@ else
		LIB_OBJS += $(OUTPUT)ui/gtk/util.o
		LIB_OBJS += $(OUTPUT)ui/gtk/helpline.o
		# Make sure that it'd be included only once.
		ifneq ($(findstring -DNO_NEWT_SUPPORT,$(BASIC_CFLAGS)),)
		ifeq ($(findstring -DNEWT_SUPPORT,$(BASIC_CFLAGS)),)
			LIB_OBJS += $(OUTPUT)ui/setup.o
			LIB_OBJS += $(OUTPUT)ui/util.o
		endif
@@ -762,23 +742,18 @@ ifeq ($(NO_PERF_REGS),0)
	ifeq ($(ARCH),x86)
		LIB_H += arch/x86/include/perf_regs.h
	endif
else
	BASIC_CFLAGS += -DNO_PERF_REGS
	BASIC_CFLAGS += -DHAVE_PERF_REGS
endif

ifdef NO_STRLCPY
	BASIC_CFLAGS += -DNO_STRLCPY
else
	ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y)
		BASIC_CFLAGS += -DNO_STRLCPY
ifndef NO_STRLCPY
	ifeq ($(call try-cc,$(SOURCE_STRLCPY),),y)
		BASIC_CFLAGS += -DHAVE_STRLCPY
	endif
endif

ifdef NO_BACKTRACE
       BASIC_CFLAGS += -DNO_BACKTRACE
else
       ifneq ($(call try-cc,$(SOURCE_BACKTRACE),),y)
               BASIC_CFLAGS += -DNO_BACKTRACE
ifndef NO_BACKTRACE
       ifeq ($(call try-cc,$(SOURCE_BACKTRACE),),y)
               BASIC_CFLAGS += -DBACKTRACE_SUPPORT
       endif
endif

+43 −7
Original line number Diff line number Diff line
# perf completion

function_exists()
{
	declare -F $1 > /dev/null
	return $?
}

function_exists __ltrim_colon_completions ||
__ltrim_colon_completions()
{
	if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
		# Remove colon-word prefix from COMPREPLY items
		local colon_word=${1%${1##*:}}
		local i=${#COMPREPLY[*]}
		while [[ $((--i)) -ge 0 ]]; do
			COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
		done
	fi
}

have perf &&
_perf()
{
	local cur cmd
	local cur prev cmd

	COMPREPLY=()
	_get_comp_words_by_ref cur prev
	if function_exists _get_comp_words_by_ref; then
		_get_comp_words_by_ref -n : cur prev
	else
		cur=$(_get_cword :)
		prev=${COMP_WORDS[COMP_CWORD-1]}
	fi

	cmd=${COMP_WORDS[0]}

	# List perf subcommands
	# List perf subcommands or long options
	if [ $COMP_CWORD -eq 1 ]; then
		if [[ $cur == --* ]]; then
			COMPREPLY=( $( compgen -W '--help --version \
			--exec-path --html-path --paginate --no-pager \
			--perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
		else
			cmds=$($cmd --list-cmds)
			COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
		fi
	# List possible events for -e option
	elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then
		cmds=$($cmd list --raw-dump)
		COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
		evts=$($cmd list --raw-dump)
		COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
		__ltrim_colon_completions $cur
	# List long option names
	elif [[ $cur == --* ]];  then
		subcmd=${COMP_WORDS[1]}
		opts=$($cmd $subcmd --list-opts)
		COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
	# Fall down to list regular files
	else
		_filedir
+26 −32
Original line number Diff line number Diff line
@@ -15,22 +15,6 @@
#include "util/strlist.h"
#include "util/symbol.h"

static char const *add_name_list_str, *remove_name_list_str;

static const char * const buildid_cache_usage[] = {
	"perf buildid-cache [<options>]",
	NULL
};

static const struct option buildid_cache_options[] = {
	OPT_STRING('a', "add", &add_name_list_str,
		   "file list", "file(s) to add"),
	OPT_STRING('r', "remove", &remove_name_list_str, "file list",
		    "file(s) to remove"),
	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
	OPT_END()
};

static int build_id_cache__add_file(const char *filename, const char *debugdir)
{
	char sbuild_id[BUILD_ID_SIZE * 2 + 1];
@@ -51,8 +35,8 @@ static int build_id_cache__add_file(const char *filename, const char *debugdir)
	return err;
}

static int build_id_cache__remove_file(const char *filename __maybe_unused,
				       const char *debugdir __maybe_unused)
static int build_id_cache__remove_file(const char *filename,
				       const char *debugdir)
{
	u8 build_id[BUILD_ID_SIZE];
	char sbuild_id[BUILD_ID_SIZE * 2 + 1];
@@ -73,11 +57,34 @@ static int build_id_cache__remove_file(const char *filename __maybe_unused,
	return err;
}

static int __cmd_buildid_cache(void)
int cmd_buildid_cache(int argc, const char **argv,
		      const char *prefix __maybe_unused)
{
	struct strlist *list;
	struct str_node *pos;
	char debugdir[PATH_MAX];
	char const *add_name_list_str = NULL,
		   *remove_name_list_str = NULL;
	const struct option buildid_cache_options[] = {
	OPT_STRING('a', "add", &add_name_list_str,
		   "file list", "file(s) to add"),
	OPT_STRING('r', "remove", &remove_name_list_str, "file list",
		    "file(s) to remove"),
	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
	OPT_END()
	};
	const char * const buildid_cache_usage[] = {
		"perf buildid-cache [<options>]",
		NULL
	};

	argc = parse_options(argc, argv, buildid_cache_options,
			     buildid_cache_usage, 0);

	if (symbol__init() < 0)
		return -1;

	setup_pager();

	snprintf(debugdir, sizeof(debugdir), "%s", buildid_dir);

@@ -119,16 +126,3 @@ static int __cmd_buildid_cache(void)

	return 0;
}

int cmd_buildid_cache(int argc, const char **argv,
		      const char *prefix __maybe_unused)
{
	argc = parse_options(argc, argv, buildid_cache_options,
			     buildid_cache_usage, 0);

	if (symbol__init() < 0)
		return -1;

	setup_pager();
	return __cmd_buildid_cache();
}
+24 −31
Original line number Diff line number Diff line
@@ -16,27 +16,6 @@
#include "util/session.h"
#include "util/symbol.h"

static const char *input_name;
static bool force;
static bool show_kernel;
static bool with_hits;

static const char * const buildid_list_usage[] = {
	"perf buildid-list [<options>]",
	NULL
};

static const struct option options[] = {
	OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
	OPT_STRING('i', "input", &input_name, "file",
		    "input file name"),
	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
	OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"),
	OPT_INCR('v', "verbose", &verbose,
		    "be more verbose"),
	OPT_END()
};

static int sysfs__fprintf_build_id(FILE *fp)
{
	u8 kallsyms_build_id[BUILD_ID_SIZE];
@@ -65,7 +44,8 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)
	return fprintf(fp, "%s\n", sbuild_id);
}

static int perf_session__list_build_ids(void)
static int perf_session__list_build_ids(const char *input_name,
					bool force, bool with_hits)
{
	struct perf_session *session;

@@ -95,18 +75,31 @@ out:
	return 0;
}

static int __cmd_buildid_list(void)
{
	if (show_kernel)
		return sysfs__fprintf_build_id(stdout);

	return perf_session__list_build_ids();
}

int cmd_buildid_list(int argc, const char **argv,
		     const char *prefix __maybe_unused)
{
	bool show_kernel = false;
	bool with_hits = false;
	bool force = false;
	const char *input_name = NULL;
	const struct option options[] = {
	OPT_BOOLEAN('H', "with-hits", &with_hits, "Show only DSOs with hits"),
	OPT_STRING('i', "input", &input_name, "file", "input file name"),
	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
	OPT_BOOLEAN('k', "kernel", &show_kernel, "Show current kernel build id"),
	OPT_INCR('v', "verbose", &verbose, "be more verbose"),
	OPT_END()
	};
	const char * const buildid_list_usage[] = {
		"perf buildid-list [<options>]",
		NULL
	};

	argc = parse_options(argc, argv, options, buildid_list_usage, 0);
	setup_pager();
	return __cmd_buildid_list();

	if (show_kernel)
		return sysfs__fprintf_build_id(stdout);

	return perf_session__list_build_ids(input_name, force, with_hits);
}
+49 −19
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ static struct perf_tool tool = {
	.ordering_requires_timestamps = true,
};

static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
static void insert_hist_entry_by_name(struct rb_root *root,
				      struct hist_entry *he)
{
	struct rb_node **p = &root->rb_node;
@@ -90,7 +90,7 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
	rb_insert_color(&he->rb_node, root);
}

static void hists__resort_entries(struct hists *self)
static void hists__name_resort(struct hists *self, bool sort)
{
	unsigned long position = 1;
	struct rb_root tmp = RB_ROOT;
@@ -100,11 +100,15 @@ static void hists__resort_entries(struct hists *self)
		struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node);

		next = rb_next(&n->rb_node);
		rb_erase(&n->rb_node, &self->entries);
		n->position = position++;
		perf_session__insert_hist_entry_by_name(&tmp, n);

		if (sort) {
			rb_erase(&n->rb_node, &self->entries);
			insert_hist_entry_by_name(&tmp, n);
		}
	}

	if (sort)
		self->entries = tmp;
}

@@ -150,6 +154,24 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel,
	return NULL;
}

static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name)
{
	struct perf_evsel *evsel;

	list_for_each_entry(evsel, &evlist->entries, node) {
		struct hists *hists = &evsel->hists;

		hists__output_resort(hists);

		/*
		 * The hists__name_resort only sets possition
		 * if name is false.
		 */
		if (name || ((!name) && show_displacement))
			hists__name_resort(hists, name);
	}
}

static int __cmd_diff(void)
{
	int ret, i;
@@ -176,15 +198,8 @@ static int __cmd_diff(void)
	evlist_old = older->evlist;
	evlist_new = newer->evlist;

	list_for_each_entry(evsel, &evlist_new->entries, node)
		hists__output_resort(&evsel->hists);

	list_for_each_entry(evsel, &evlist_old->entries, node) {
		hists__output_resort(&evsel->hists);

		if (show_displacement)
			hists__resort_entries(&evsel->hists);
	}
	perf_evlist__resort_hists(evlist_old, true);
	perf_evlist__resort_hists(evlist_new, false);

	list_for_each_entry(evsel, &evlist_new->entries, node) {
		struct perf_evsel *evsel_old;
@@ -199,8 +214,7 @@ static int __cmd_diff(void)
		first = false;

		hists__match(&evsel_old->hists, &evsel->hists);
		hists__fprintf(&evsel->hists, &evsel_old->hists,
			       show_displacement, true, 0, 0, stdout);
		hists__fprintf(&evsel->hists, true, 0, 0, stdout);
	}

out_delete:
@@ -242,6 +256,21 @@ static const struct option options[] = {
	OPT_END()
};

static void ui_init(void)
{
	perf_hpp__init();

	/* No overhead column. */
	perf_hpp__column_enable(PERF_HPP__OVERHEAD, false);

	/* Display baseline/delta/displacement columns. */
	perf_hpp__column_enable(PERF_HPP__BASELINE, true);
	perf_hpp__column_enable(PERF_HPP__DELTA, true);

	if (show_displacement)
		perf_hpp__column_enable(PERF_HPP__DISPL, true);
}

int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
{
	sort_order = diff__default_sort_order;
@@ -264,7 +293,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
	if (symbol__init() < 0)
		return -1;

	perf_hpp__init(true, show_displacement);
	ui_init();

	setup_sorting(diff_usage, options);
	setup_pager();

Loading