[PATCH/RFC 04/16] perf top: Factor out warnings in perf_top__record_precise_ip()
From: Namhyung Kim
Date: Thu Dec 10 2015 - 02:59:44 EST
Currently it warns two error cases during annotation update. One is
for ERANGE and it already is in a separate function. Fix this
function to be consistent with others like checking erange_warned
inside the function and passing 'al' in the argument.
Another case is for ENOMEM, make it also as a separate function.
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-top.c | 87 +++++++++++++++++++++++++++++-------------------
tools/perf/util/top.h | 1 +
2 files changed, 53 insertions(+), 35 deletions(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index e6166ef8fd1a..7a237719037a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -143,31 +143,50 @@ static void __zero_source_counters(struct hist_entry *he)
symbol__annotate_zero_histograms(sym);
}
-static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
+static void ui__warn_map_erange(struct perf_top *top __maybe_unused,
+ struct addr_location *al)
{
- struct utsname uts;
- int err = uname(&uts);
-
- ui__warning("Out of bounds address found:\n\n"
- "Addr: %" PRIx64 "\n"
- "DSO: %s %c\n"
- "Map: %" PRIx64 "-%" PRIx64 "\n"
- "Symbol: %" PRIx64 "-%" PRIx64 " %c %s\n"
- "Arch: %s\n"
- "Kernel: %s\n"
- "Tools: %s\n\n"
- "Not all samples will be on the annotation output.\n\n"
- "Please report to linux-kernel@xxxxxxxxxxxxxxx\n",
- ip, map->dso->long_name, dso__symtab_origin(map->dso),
- map->start, map->end, sym->start, sym->end,
- sym->binding == STB_GLOBAL ? 'g' :
- sym->binding == STB_LOCAL ? 'l' : 'w', sym->name,
- err ? "[unknown]" : uts.machine,
- err ? "[unknown]" : uts.release, perf_version_string);
- if (use_browser <= 0)
- sleep(5);
-
- map->erange_warned = true;
+ struct map *map = al->map;
+ struct symbol *sym = al->sym;
+ u64 ip = al->addr;
+
+ if (!map->erange_warned) {
+ struct utsname uts;
+ int err = uname(&uts);
+
+ ui__warning("Out of bounds address found:\n\n"
+ "Addr: %" PRIx64 "\n"
+ "DSO: %s %c\n"
+ "Map: %" PRIx64 "-%" PRIx64 "\n"
+ "Symbol: %" PRIx64 "-%" PRIx64 " %c %s\n"
+ "Arch: %s\n"
+ "Kernel: %s\n"
+ "Tools: %s\n\n"
+ "Not all samples will be on the annotation output.\n\n"
+ "Please report to linux-kernel@xxxxxxxxxxxxxxx\n",
+ ip, map->dso->long_name, dso__symtab_origin(map->dso),
+ map->start, map->end, sym->start, sym->end,
+ sym->binding == STB_GLOBAL ? 'g' :
+ sym->binding == STB_LOCAL ? 'l' : 'w', sym->name,
+ err ? "[unknown]" : uts.machine,
+ err ? "[unknown]" : uts.release, perf_version_string);
+ if (use_browser <= 0)
+ sleep(5);
+
+ map->erange_warned = true;
+ }
+}
+
+static void ui__warn_enomem(struct perf_top *top, struct addr_location *al)
+{
+ if (!top->enomem_warned) {
+ ui__warning("Not enough memory for annotating '%s' symbol!\n",
+ al->sym->name);
+
+ if (use_browser <= 0)
+ sleep(5);
+ top->enomem_warned = true;
+ }
}
static void ui__warn_kptr_restrict(struct perf_top *top, struct addr_location *al)
@@ -219,10 +238,11 @@ static void ui__warn_vmlinux(struct perf_top *top, struct addr_location *al)
static void perf_top__record_precise_ip(struct perf_top *top,
struct hist_entry *he,
- int counter, u64 ip)
+ struct addr_location *al,
+ int counter)
{
struct annotation *notes;
- struct symbol *sym = he->ms.sym;
+ struct symbol *sym = al->sym;
int err = 0;
if (sym == NULL || (use_browser == 0 &&
@@ -235,7 +255,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,
if (pthread_mutex_trylock(¬es->lock))
return;
- err = hist_entry__inc_addr_samples(he, counter, ip);
+ err = hist_entry__inc_addr_samples(he, counter, al->addr);
pthread_mutex_unlock(¬es->lock);
@@ -246,13 +266,10 @@ static void perf_top__record_precise_ip(struct perf_top *top,
*/
pthread_mutex_unlock(&he->hists->lock);
- if (err == -ERANGE && !he->ms.map->erange_warned)
- ui__warn_map_erange(he->ms.map, sym, ip);
- else if (err == -ENOMEM) {
- pr_err("Not enough memory for annotating '%s' symbol!\n",
- sym->name);
- sleep(1);
- }
+ if (err == -ERANGE)
+ ui__warn_map_erange(top, al);
+ else if (err == -ENOMEM)
+ ui__warn_enomem(top, al);
pthread_mutex_lock(&he->hists->lock);
}
@@ -733,7 +750,7 @@ static int hist_iter__top_callback(struct hist_entry_iter *iter,
struct perf_evsel *evsel = iter->evsel;
if (sort__has_sym && single)
- perf_top__record_precise_ip(top, he, evsel->idx, al->addr);
+ perf_top__record_precise_ip(top, he, al, evsel->idx);
hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
!(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY));
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index f92c37abb0a8..c56a00cff5b4 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -29,6 +29,7 @@ struct perf_top {
bool use_tui, use_stdio;
bool kptr_restrict_warned;
bool vmlinux_warned;
+ bool enomem_warned;
bool dump_symtab;
struct hist_entry *sym_filter_entry;
struct perf_evsel *sym_evsel;
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/