mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-21 16:29:59 +00:00
![Ian Rogers](/assets/img/avatar_default.png)
Most perf commands want to sort symbols by name and this is done via an invasive rbtree that on 64-bit systems costs 24 bytes. Sorting the symbols in a DSO by name is optional and not done by default, however, if sorting is requested the 24 bytes is allocated for every symbol. This change removes the rbtree and uses a sorted array of symbol pointers instead (costing 8 bytes per symbol). As the array is created on demand then there are further memory savings. The complexity of sorting the array and using the rbtree are the same. To support going to the next symbol, the index of the current symbol needs to be passed around as a pair with the current symbol. This requires some API changes. Signed-off-by: Ian Rogers <irogers@google.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Carsten Haitzler <carsten.haitzler@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Jason Wang <wangborong@cdjrlc.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Yang Jihong <yangjihong1@huawei.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Link: https://lore.kernel.org/r/20230623054520.4118442-3-irogers@google.com [ minimize change in symbols__sort_by_name() ] Signed-off-by: Namhyung Kim <namhyung@kernel.org>
73 lines
1.8 KiB
C
73 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <elf.h>
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
|
|
#include "dso.h"
|
|
#include "map.h"
|
|
#include "symbol.h"
|
|
|
|
size_t symbol__fprintf(struct symbol *sym, FILE *fp)
|
|
{
|
|
return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %c %s\n",
|
|
sym->start, sym->end,
|
|
sym->binding == STB_GLOBAL ? 'g' :
|
|
sym->binding == STB_LOCAL ? 'l' : 'w',
|
|
sym->name);
|
|
}
|
|
|
|
size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
|
|
const struct addr_location *al,
|
|
bool unknown_as_addr,
|
|
bool print_offsets, FILE *fp)
|
|
{
|
|
unsigned long offset;
|
|
size_t length;
|
|
|
|
if (sym) {
|
|
length = fprintf(fp, "%s", sym->name);
|
|
if (al && print_offsets) {
|
|
if (al->addr < sym->end)
|
|
offset = al->addr - sym->start;
|
|
else
|
|
offset = al->addr - map__start(al->map) - sym->start;
|
|
length += fprintf(fp, "+0x%lx", offset);
|
|
}
|
|
return length;
|
|
} else if (al && unknown_as_addr)
|
|
return fprintf(fp, "[%#" PRIx64 "]", al->addr);
|
|
else
|
|
return fprintf(fp, "[unknown]");
|
|
}
|
|
|
|
size_t symbol__fprintf_symname_offs(const struct symbol *sym,
|
|
const struct addr_location *al,
|
|
FILE *fp)
|
|
{
|
|
return __symbol__fprintf_symname_offs(sym, al, false, true, fp);
|
|
}
|
|
|
|
size_t __symbol__fprintf_symname(const struct symbol *sym,
|
|
const struct addr_location *al,
|
|
bool unknown_as_addr, FILE *fp)
|
|
{
|
|
return __symbol__fprintf_symname_offs(sym, al, unknown_as_addr, false, fp);
|
|
}
|
|
|
|
size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp)
|
|
{
|
|
return __symbol__fprintf_symname_offs(sym, NULL, false, false, fp);
|
|
}
|
|
|
|
size_t dso__fprintf_symbols_by_name(struct dso *dso,
|
|
FILE *fp)
|
|
{
|
|
size_t ret = 0;
|
|
|
|
for (size_t i = 0; i < dso->symbol_names_len; i++) {
|
|
struct symbol *pos = dso->symbol_names[i];
|
|
|
|
ret += fprintf(fp, "%s\n", pos->name);
|
|
}
|
|
return ret;
|
|
}
|