perf tools: Pass build_id object to build_id__sprintf()
Passing build_id object to build_id__sprintf function, so it can operate with the proper size of build id. This will create proper md5 build id readable names, like following: a50e350e97c43b4708d09bcd85ebfff7 instead of: a50e350e97c43b4708d09bcd85ebfff700000000 Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Ian Rogers <irogers@google.com> Link: https://lore.kernel.org/r/20201013192441.1299447-5-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:

committed by
Arnaldo Carvalho de Melo

parent
3ff1b8c8cc
commit
bf5411695a
@@ -37,6 +37,7 @@
|
||||
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/zalloc.h>
|
||||
#include <asm/bug.h>
|
||||
|
||||
static bool no_buildid_cache;
|
||||
|
||||
@@ -95,13 +96,13 @@ struct perf_tool build_id__mark_dso_hit_ops = {
|
||||
.ordered_events = true,
|
||||
};
|
||||
|
||||
int build_id__sprintf(const u8 *build_id, int len, char *bf)
|
||||
int build_id__sprintf(const struct build_id *build_id, char *bf)
|
||||
{
|
||||
char *bid = bf;
|
||||
const u8 *raw = build_id;
|
||||
int i;
|
||||
const u8 *raw = build_id->data;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
for (i = 0; i < build_id->size; ++i) {
|
||||
sprintf(bid, "%02x", *raw);
|
||||
++raw;
|
||||
bid += 2;
|
||||
@@ -125,7 +126,7 @@ int sysfs__sprintf_build_id(const char *root_dir, char *sbuild_id)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
|
||||
return build_id__sprintf(&bid, sbuild_id);
|
||||
}
|
||||
|
||||
int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
|
||||
@@ -137,7 +138,7 @@ int filename__sprintf_build_id(const char *pathname, char *sbuild_id)
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
|
||||
return build_id__sprintf(&bid, sbuild_id);
|
||||
}
|
||||
|
||||
/* asnprintf consolidates asprintf and snprintf */
|
||||
@@ -270,7 +271,7 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size,
|
||||
if (!dso->has_build_id)
|
||||
return NULL;
|
||||
|
||||
build_id__sprintf(dso->bid.data, sizeof(dso->bid.data), sbuild_id);
|
||||
build_id__sprintf(&dso->bid, sbuild_id);
|
||||
linkname = build_id_cache__linkname(sbuild_id, NULL, 0);
|
||||
if (!linkname)
|
||||
return NULL;
|
||||
@@ -767,13 +768,13 @@ out_free:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
|
||||
static int build_id_cache__add_b(const struct build_id *bid,
|
||||
const char *name, struct nsinfo *nsi,
|
||||
bool is_kallsyms, bool is_vdso)
|
||||
{
|
||||
char sbuild_id[SBUILD_ID_SIZE];
|
||||
|
||||
build_id__sprintf(build_id, build_id_size, sbuild_id);
|
||||
build_id__sprintf(bid, sbuild_id);
|
||||
|
||||
return build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms,
|
||||
is_vdso);
|
||||
@@ -839,8 +840,8 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine)
|
||||
is_kallsyms = true;
|
||||
name = machine->mmap_name;
|
||||
}
|
||||
return build_id_cache__add_b(dso->bid.data, sizeof(dso->bid.data), name,
|
||||
dso->nsinfo, is_kallsyms, is_vdso);
|
||||
return build_id_cache__add_b(&dso->bid, name, dso->nsinfo,
|
||||
is_kallsyms, is_vdso);
|
||||
}
|
||||
|
||||
static int __dsos__cache_build_ids(struct list_head *head,
|
||||
@@ -900,3 +901,10 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void build_id__init(struct build_id *bid, const u8 *data, size_t size)
|
||||
{
|
||||
WARN_ON(size > BUILD_ID_SIZE);
|
||||
memcpy(bid->data, data, size);
|
||||
bid->size = size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user