mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 01:24:12 +08:00
perf srcline: Introduce map__srcline() to make code more compact
Replacing a common open coded sequence. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-2d7d1nzd3ksqornloqeer99r@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
982d410bc6
commit
e2d88aaa64
@ -415,16 +415,20 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
|
|||||||
return fprintf(fp, "%s", dsoname);
|
return fprintf(fp, "%s", dsoname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
|
||||||
|
{
|
||||||
|
if (map == NULL)
|
||||||
|
return SRCLINE_UNKNOWN;
|
||||||
|
return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
|
||||||
|
}
|
||||||
|
|
||||||
int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
|
int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
|
||||||
FILE *fp)
|
FILE *fp)
|
||||||
{
|
{
|
||||||
char *srcline;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (map && map->dso) {
|
if (map && map->dso) {
|
||||||
srcline = get_srcline(map->dso,
|
char *srcline = map__srcline(map, addr, NULL);
|
||||||
map__rip_2objdump(map, addr), NULL,
|
|
||||||
true, true, addr);
|
|
||||||
if (srcline != SRCLINE_UNKNOWN)
|
if (srcline != SRCLINE_UNKNOWN)
|
||||||
ret = fprintf(fp, "%s%s", prefix, srcline);
|
ret = fprintf(fp, "%s%s", prefix, srcline);
|
||||||
free_srcline(srcline);
|
free_srcline(srcline);
|
||||||
|
@ -169,6 +169,7 @@ static inline void __map__zput(struct map **map)
|
|||||||
int map__overlap(struct map *l, struct map *r);
|
int map__overlap(struct map *l, struct map *r);
|
||||||
size_t map__fprintf(struct map *map, FILE *fp);
|
size_t map__fprintf(struct map *map, FILE *fp);
|
||||||
size_t map__fprintf_dsoname(struct map *map, FILE *fp);
|
size_t map__fprintf_dsoname(struct map *map, FILE *fp);
|
||||||
|
char *map__srcline(struct map *map, u64 addr, struct symbol *sym);
|
||||||
int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
|
int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
|
||||||
FILE *fp);
|
FILE *fp);
|
||||||
|
|
||||||
|
@ -333,13 +333,7 @@ struct sort_entry sort_sym = {
|
|||||||
|
|
||||||
char *hist_entry__get_srcline(struct hist_entry *he)
|
char *hist_entry__get_srcline(struct hist_entry *he)
|
||||||
{
|
{
|
||||||
struct map *map = he->ms.map;
|
return map__srcline(he->ms.map, he->ip, he->ms.sym);
|
||||||
|
|
||||||
if (!map)
|
|
||||||
return SRCLINE_UNKNOWN;
|
|
||||||
|
|
||||||
return get_srcline(map->dso, map__rip_2objdump(map, he->ip),
|
|
||||||
he->ms.sym, true, true, he->ip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t
|
static int64_t
|
||||||
@ -375,28 +369,14 @@ static int64_t
|
|||||||
sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
|
sort__srcline_from_cmp(struct hist_entry *left, struct hist_entry *right)
|
||||||
{
|
{
|
||||||
if (!left->branch_info->srcline_from) {
|
if (!left->branch_info->srcline_from) {
|
||||||
struct map *map = left->branch_info->from.map;
|
left->branch_info->srcline_from = map__srcline(left->branch_info->from.map,
|
||||||
if (!map)
|
left->branch_info->from.al_addr,
|
||||||
left->branch_info->srcline_from = SRCLINE_UNKNOWN;
|
left->branch_info->from.sym);
|
||||||
else
|
|
||||||
left->branch_info->srcline_from = get_srcline(map->dso,
|
|
||||||
map__rip_2objdump(map,
|
|
||||||
left->branch_info->from.al_addr),
|
|
||||||
left->branch_info->from.sym,
|
|
||||||
true, true,
|
|
||||||
left->branch_info->from.al_addr);
|
|
||||||
}
|
}
|
||||||
if (!right->branch_info->srcline_from) {
|
if (!right->branch_info->srcline_from) {
|
||||||
struct map *map = right->branch_info->from.map;
|
right->branch_info->srcline_from = map__srcline(right->branch_info->from.map,
|
||||||
if (!map)
|
right->branch_info->from.al_addr,
|
||||||
right->branch_info->srcline_from = SRCLINE_UNKNOWN;
|
right->branch_info->from.sym);
|
||||||
else
|
|
||||||
right->branch_info->srcline_from = get_srcline(map->dso,
|
|
||||||
map__rip_2objdump(map,
|
|
||||||
right->branch_info->from.al_addr),
|
|
||||||
right->branch_info->from.sym,
|
|
||||||
true, true,
|
|
||||||
right->branch_info->from.al_addr);
|
|
||||||
}
|
}
|
||||||
return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from);
|
return strcmp(right->branch_info->srcline_from, left->branch_info->srcline_from);
|
||||||
}
|
}
|
||||||
@ -420,28 +400,14 @@ static int64_t
|
|||||||
sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
|
sort__srcline_to_cmp(struct hist_entry *left, struct hist_entry *right)
|
||||||
{
|
{
|
||||||
if (!left->branch_info->srcline_to) {
|
if (!left->branch_info->srcline_to) {
|
||||||
struct map *map = left->branch_info->to.map;
|
left->branch_info->srcline_to = map__srcline(left->branch_info->to.map,
|
||||||
if (!map)
|
left->branch_info->to.al_addr,
|
||||||
left->branch_info->srcline_to = SRCLINE_UNKNOWN;
|
left->branch_info->to.sym);
|
||||||
else
|
|
||||||
left->branch_info->srcline_to = get_srcline(map->dso,
|
|
||||||
map__rip_2objdump(map,
|
|
||||||
left->branch_info->to.al_addr),
|
|
||||||
left->branch_info->from.sym,
|
|
||||||
true, true,
|
|
||||||
left->branch_info->to.al_addr);
|
|
||||||
}
|
}
|
||||||
if (!right->branch_info->srcline_to) {
|
if (!right->branch_info->srcline_to) {
|
||||||
struct map *map = right->branch_info->to.map;
|
right->branch_info->srcline_to = map__srcline(right->branch_info->to.map,
|
||||||
if (!map)
|
right->branch_info->to.al_addr,
|
||||||
right->branch_info->srcline_to = SRCLINE_UNKNOWN;
|
right->branch_info->to.sym);
|
||||||
else
|
|
||||||
right->branch_info->srcline_to = get_srcline(map->dso,
|
|
||||||
map__rip_2objdump(map,
|
|
||||||
right->branch_info->to.al_addr),
|
|
||||||
right->branch_info->to.sym,
|
|
||||||
true, true,
|
|
||||||
right->branch_info->to.al_addr);
|
|
||||||
}
|
}
|
||||||
return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to);
|
return strcmp(right->branch_info->srcline_to, left->branch_info->srcline_to);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user