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

Commit b66d8c0c authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf annotate: Auto allocate symbol per addr hist buckets



Instead of open coding it in multiple places in 'report' and 'top'.

Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ay1ushp57qsva9aw59rha5ve@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent bf19b82e
Loading
Loading
Loading
Loading
+16 −43
Original line number Original line Diff line number Diff line
@@ -140,22 +140,11 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
			goto out;
			goto out;
	}
	}


	if (sort__has_sym && he->mem_info->daddr.sym && use_browser > 0) {
		struct annotation *notes;

	mx = he->mem_info;
	mx = he->mem_info;

	err = symbol__inc_addr_samples(mx->daddr.sym, mx->daddr.map,
		notes = symbol__annotation(mx->daddr.sym);
				       evsel->idx, mx->daddr.al_addr);
		if (notes->src == NULL && symbol__alloc_hist(mx->daddr.sym) < 0)
			goto out;

		err = symbol__inc_addr_samples(mx->daddr.sym,
					       mx->daddr.map,
					       evsel->idx,
					       mx->daddr.al_addr);
	if (err)
	if (err)
		goto out;
		goto out;
	}


	evsel->hists.stats.total_period += cost;
	evsel->hists.stats.total_period += cost;
	hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
	hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
@@ -214,35 +203,19 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,
		he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL,
		he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL,
					1, 1, 0);
					1, 1, 0);
		if (he) {
		if (he) {
			struct annotation *notes;
			bx = he->branch_info;
			bx = he->branch_info;
			if (bx->from.sym && use_browser == 1 && sort__has_sym) {
				notes = symbol__annotation(bx->from.sym);
				if (!notes->src
				    && symbol__alloc_hist(bx->from.sym) < 0)
					goto out;

			err = symbol__inc_addr_samples(bx->from.sym,
			err = symbol__inc_addr_samples(bx->from.sym,
							       bx->from.map,
						       bx->from.map, evsel->idx,
							       evsel->idx,
						       bx->from.al_addr);
						       bx->from.al_addr);
			if (err)
			if (err)
				goto out;
				goto out;
			}

			if (bx->to.sym && use_browser == 1 && sort__has_sym) {
				notes = symbol__annotation(bx->to.sym);
				if (!notes->src
				    && symbol__alloc_hist(bx->to.sym) < 0)
					goto out;


			err = symbol__inc_addr_samples(bx->to.sym,
			err = symbol__inc_addr_samples(bx->to.sym,
							       bx->to.map,
						       bx->to.map, evsel->idx,
							       evsel->idx,
						       bx->to.al_addr);
						       bx->to.al_addr);
			if (err)
			if (err)
				goto out;
				goto out;
			}

			evsel->hists.stats.total_period += 1;
			evsel->hists.stats.total_period += 1;
			hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
			hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
		} else
		} else
+5 −8
Original line number Original line Diff line number Diff line
@@ -189,14 +189,6 @@ static void perf_top__record_precise_ip(struct perf_top *top,
	if (pthread_mutex_trylock(&notes->lock))
	if (pthread_mutex_trylock(&notes->lock))
		return;
		return;


	if (notes->src == NULL && symbol__alloc_hist(sym) < 0) {
		pthread_mutex_unlock(&notes->lock);
		pr_err("Not enough memory for annotating '%s' symbol!\n",
		       sym->name);
		sleep(1);
		return;
	}

	ip = he->ms.map->map_ip(he->ms.map, ip);
	ip = he->ms.map->map_ip(he->ms.map, ip);
	err = symbol__inc_addr_samples(sym, he->ms.map, counter, ip);
	err = symbol__inc_addr_samples(sym, he->ms.map, counter, ip);


@@ -204,6 +196,11 @@ static void perf_top__record_precise_ip(struct perf_top *top,


	if (err == -ERANGE && !he->ms.map->erange_warned)
	if (err == -ERANGE && !he->ms.map->erange_warned)
		ui__warn_map_erange(he->ms.map, sym, ip);
		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);
	}
}
}


static void perf_top__show_details(struct perf_top *top)
static void perf_top__show_details(struct perf_top *top)
+19 −7
Original line number Original line Diff line number Diff line
@@ -464,17 +464,12 @@ void symbol__annotate_zero_histograms(struct symbol *sym)
	pthread_mutex_unlock(&notes->lock);
	pthread_mutex_unlock(&notes->lock);
}
}


int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map,
			     int evidx, u64 addr)
				      struct annotation *notes, int evidx, u64 addr)
{
{
	unsigned offset;
	unsigned offset;
	struct annotation *notes;
	struct sym_hist *h;
	struct sym_hist *h;


	notes = symbol__annotation(sym);
	if (notes->src == NULL)
		return -ENOMEM;

	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
	pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));


	if (addr < sym->start || addr > sym->end)
	if (addr < sym->start || addr > sym->end)
@@ -491,6 +486,23 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
	return 0;
	return 0;
}
}


int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
			     int evidx, u64 addr)
{
	struct annotation *notes;

	if (sym == NULL || use_browser != 1 || !sort__has_sym)
		return 0;

	notes = symbol__annotation(sym);
	if (notes->src == NULL) {
		if (symbol__alloc_hist(sym) < 0)
			return -ENOMEM;
	}

	return __symbol__inc_addr_samples(sym, map, notes, evidx, addr);
}

static void disasm_line__init_ins(struct disasm_line *dl)
static void disasm_line__init_ins(struct disasm_line *dl)
{
{
	dl->ins = ins__find(dl->name);
	dl->ins = ins__find(dl->name);