Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/acme/linux into perf/core

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

Infrastructure changes:

  - Revert "perf tools: Improve setting of gcc debug option", -Og is broken,
    GCC PR created (Jiri Olsa)

  - More reference count fixes (Masami Hiramatsu)

  - Untangle browser setup (--stdio, --tui, etc) from argument checking,
    prep work to move the usage() code out of tools/perf for use by
    other tools/ living utilities (Namhyung Kim)

  - Delete half-processed hist entries when exiting 'perf top' (Namhyung Kim)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Dec 11, 2015
2 parents d18929e + e7a7865 commit 54c9238
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 66 deletions.
33 changes: 16 additions & 17 deletions tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,19 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
return ret;

argc = parse_options(argc, argv, options, annotate_usage, 0);
if (argc) {
/*
* Special case: if there's an argument left then assume that
* it's a symbol filter:
*/
if (argc > 1)
usage_with_options(annotate_usage, options);

if (annotate.use_stdio)
use_browser = 0;
else if (annotate.use_tui)
use_browser = 1;
else if (annotate.use_gtk)
use_browser = 2;
annotate.sym_hist_filter = argv[0];
}

file.path = input_name;

setup_browser(true);

annotate.session = perf_session__new(&file, false, &annotate.tool);
if (annotate.session == NULL)
return -1;
Expand All @@ -369,16 +370,14 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
if (setup_sorting() < 0)
usage_with_options(annotate_usage, options);

if (argc) {
/*
* Special case: if there's an argument left then assume that
* it's a symbol filter:
*/
if (argc > 1)
usage_with_options(annotate_usage, options);
if (annotate.use_stdio)
use_browser = 0;
else if (annotate.use_tui)
use_browser = 1;
else if (annotate.use_gtk)
use_browser = 2;

annotate.sym_hist_filter = argv[0];
}
setup_browser(true);

ret = __cmd_annotate(&annotate);

Expand Down
3 changes: 0 additions & 3 deletions tools/perf/builtin-kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
disable_buildid_cache();

use_browser = 0;
setup_browser(false);

if (argc) {
argc = parse_options(argc, argv, live_options,
Expand Down Expand Up @@ -1409,8 +1408,6 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
err = kvm_events_live_report(kvm);

out:
exit_browser(0);

if (kvm->session)
perf_session__delete(kvm->session);
kvm->session = NULL;
Expand Down
21 changes: 10 additions & 11 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,16 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
perf_config(report__config, &report);

argc = parse_options(argc, argv, options, report_usage, 0);
if (argc) {
/*
* Special case: if there's an argument left then assume that
* it's a symbol filter:
*/
if (argc > 1)
usage_with_options(report_usage, options);

report.symbol_filter_str = argv[0];
}

if (symbol_conf.vmlinux_name &&
access(symbol_conf.vmlinux_name, R_OK)) {
Expand Down Expand Up @@ -946,17 +956,6 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
if (symbol__init(&session->header.env) < 0)
goto error;

if (argc) {
/*
* Special case: if there's an argument left then assume that
* it's a symbol filter:
*/
if (argc > 1)
usage_with_options(report_usage, options);

report.symbol_filter_str = argv[0];
}

sort__setup_elide(stdout);

ret = __cmd_report(&report);
Expand Down
9 changes: 6 additions & 3 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ static int __cmd_top(struct perf_top *top)
if (ret)
goto out_delete;

if (perf_session__register_idle_thread(top->session) == NULL)
if (perf_session__register_idle_thread(top->session) < 0)
goto out_delete;

machine__synthesize_threads(&top->session->machines.host, &opts->target,
Expand Down Expand Up @@ -1279,8 +1279,11 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
if (target__none(target))
target->system_wide = true;

if (perf_evlist__create_maps(top.evlist, target) < 0)
usage_with_options(top_usage, options);
if (perf_evlist__create_maps(top.evlist, target) < 0) {
ui__error("Couldn't create thread/CPU maps: %s\n",
errno == ENOENT ? "No such process" : strerror_r(errno, errbuf, sizeof(errbuf)));
goto out_delete_evlist;
}

if (!top.evlist->nr_entries &&
perf_evlist__add_default(top.evlist) < 0) {
Expand Down
2 changes: 0 additions & 2 deletions tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ endif

ifeq ($(DEBUG),0)
CFLAGS += -O6
else
CFLAGS += $(call cc-option,-Og,-O0)
endif

ifdef PARSER_DEBUG
Expand Down
19 changes: 0 additions & 19 deletions tools/perf/config/utilities.mak
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,3 @@ $(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2)))
endef
_ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2)))
_gea_err = $(if $(1),$(error Please set '$(1)' appropriately))

# try-run
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
# Exit code chooses option. "$$TMP" is can be used as temporary file and
# is automatically cleaned up.
try-run = $(shell set -e; \
TMP="$(TMPOUT).$$$$.tmp"; \
TMPO="$(TMPOUT).$$$$.o"; \
if ($(1)) >/dev/null 2>&1; \
then echo "$(2)"; \
else echo "$(3)"; \
fi; \
rm -f "$$TMP" "$$TMPO")

# cc-option
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)

cc-option = $(call try-run,\
$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
26 changes: 25 additions & 1 deletion tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ static void hists__delete_entry(struct hists *hists, struct hist_entry *he)

if (sort__need_collapse)
rb_erase(&he->rb_node_in, &hists->entries_collapsed);
else
rb_erase(&he->rb_node_in, hists->entries_in);

--hists->nr_entries;
if (!he->filtered)
Expand Down Expand Up @@ -1567,11 +1569,33 @@ static int hists_evsel__init(struct perf_evsel *evsel)
return 0;
}

static void hists__delete_remaining_entries(struct rb_root *root)
{
struct rb_node *node;
struct hist_entry *he;

while (!RB_EMPTY_ROOT(root)) {
node = rb_first(root);
rb_erase(node, root);

he = rb_entry(node, struct hist_entry, rb_node_in);
hist_entry__delete(he);
}
}

static void hists__delete_all_entries(struct hists *hists)
{
hists__delete_entries(hists);
hists__delete_remaining_entries(&hists->entries_in_array[0]);
hists__delete_remaining_entries(&hists->entries_in_array[1]);
hists__delete_remaining_entries(&hists->entries_collapsed);
}

static void hists_evsel__exit(struct perf_evsel *evsel)
{
struct hists *hists = evsel__hists(evsel);

hists__delete_entries(hists);
hists__delete_all_entries(hists);
}

/*
Expand Down
3 changes: 0 additions & 3 deletions tools/perf/util/parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,6 @@ int usage_with_options_internal(const char * const *usagestr,
void usage_with_options(const char * const *usagestr,
const struct option *opts)
{
exit_browser(false);
usage_with_options_internal(usagestr, opts, 0, NULL);
exit(129);
}
Expand All @@ -776,8 +775,6 @@ void usage_with_options_msg(const char * const *usagestr,
{
va_list ap;

exit_browser(false);

va_start(ap, fmt);
strbuf_addv(&error_buf, fmt, ap);
va_end(ap);
Expand Down
11 changes: 7 additions & 4 deletions tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,17 +1311,20 @@ struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
return machine__findnew_thread(&session->machines.host, -1, pid);
}

struct thread *perf_session__register_idle_thread(struct perf_session *session)
int perf_session__register_idle_thread(struct perf_session *session)
{
struct thread *thread;
int err = 0;

thread = machine__findnew_thread(&session->machines.host, 0, 0);
if (thread == NULL || thread__set_comm(thread, "swapper", 0)) {
pr_err("problem inserting idle task.\n");
thread = NULL;
err = -1;
}

return thread;
/* machine__findnew_thread() got the thread, so put it */
thread__put(thread);
return err;
}

static void perf_session__warn_about_errors(const struct perf_session *session)
Expand Down Expand Up @@ -1676,7 +1679,7 @@ int perf_session__process_events(struct perf_session *session)
u64 size = perf_data_file__size(session->file);
int err;

if (perf_session__register_idle_thread(session) == NULL)
if (perf_session__register_idle_thread(session) < 0)
return -ENOMEM;

if (!perf_data_file__is_pipe(session->file))
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct machine *perf_session__findnew_machine(struct perf_session *session, pid_
}

struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
struct thread *perf_session__register_idle_thread(struct perf_session *session);
int perf_session__register_idle_thread(struct perf_session *session);

size_t perf_session__fprintf(struct perf_session *session, FILE *fp);

Expand Down
9 changes: 7 additions & 2 deletions tools/perf/util/symbol-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,8 @@ int dso__load_sym(struct dso *dso, struct map *map,
curr_dso->long_name_len = dso->long_name_len;
curr_map = map__new2(start, curr_dso,
map->type);
dso__put(curr_dso);
if (curr_map == NULL) {
dso__put(curr_dso);
goto out_elf_end;
}
if (adjust_kernel_syms) {
Expand All @@ -1042,9 +1042,14 @@ int dso__load_sym(struct dso *dso, struct map *map,
}
curr_dso->symtab_type = dso->symtab_type;
map_groups__insert(kmaps, curr_map);
/*
* Add it before we drop the referece to curr_map,
* i.e. while we still are sure to have a reference
* to this DSO via curr_map->dso.
*/
dsos__add(&map->groups->machine->dsos, curr_dso);
/* kmaps already got it */
map__put(curr_map);
dsos__add(&map->groups->machine->dsos, curr_dso);
dso__set_loaded(curr_dso, map->type);
} else
curr_dso = curr_map->dso;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/thread_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ static struct thread_map *thread_map__new_by_tid_str(const char *tid_str)

out_free_threads:
zfree(&threads);
strlist__delete(slist);
goto out;
}

Expand Down

0 comments on commit 54c9238

Please sign in to comment.