mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-05 22:28:00 +00:00
perf annotate: Simplify disasm_line allocation and freeing code
We are allocating disasm_line object in annotation_line__new() instead of disasm_line__new(). Similarly annotation_line__delete() is actually freeing disasm_line object as well. This complexity is because of privsize. But we don't need privsize anymore so get rid of privsize and simplify disasm_line allocation and freeing code. Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Ian Rogers <irogers@google.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Song Liu <songliubraving@fb.com> Link: http://lore.kernel.org/lkml/20200204045233.474937-3-ravi.bangoria@linux.ibm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
e0ad4d6854
commit
2316f861ae
2 changed files with 34 additions and 59 deletions
|
@ -1143,7 +1143,6 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
struct annotate_args {
|
struct annotate_args {
|
||||||
size_t privsize;
|
|
||||||
struct arch *arch;
|
struct arch *arch;
|
||||||
struct map_symbol ms;
|
struct map_symbol ms;
|
||||||
struct evsel *evsel;
|
struct evsel *evsel;
|
||||||
|
@ -1153,83 +1152,61 @@ struct annotate_args {
|
||||||
int line_nr;
|
int line_nr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void annotation_line__delete(struct annotation_line *al)
|
static void annotation_line__init(struct annotation_line *al,
|
||||||
|
struct annotate_args *args,
|
||||||
|
int nr)
|
||||||
{
|
{
|
||||||
void *ptr = (void *) al - al->privsize;
|
al->offset = args->offset;
|
||||||
|
al->line = strdup(args->line);
|
||||||
free_srcline(al->path);
|
al->line_nr = args->line_nr;
|
||||||
zfree(&al->line);
|
al->data_nr = nr;
|
||||||
free(ptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static void annotation_line__exit(struct annotation_line *al)
|
||||||
* Allocating the annotation line data with following
|
{
|
||||||
* structure:
|
free_srcline(al->path);
|
||||||
*
|
zfree(&al->line);
|
||||||
* --------------------------------------
|
}
|
||||||
* private space | struct annotation_line
|
|
||||||
* --------------------------------------
|
static size_t disasm_line_size(int nr)
|
||||||
*
|
|
||||||
* Size of the private space is stored in 'struct annotation_line'.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static struct annotation_line *
|
|
||||||
annotation_line__new(struct annotate_args *args, size_t privsize)
|
|
||||||
{
|
{
|
||||||
struct annotation_line *al;
|
struct annotation_line *al;
|
||||||
struct evsel *evsel = args->evsel;
|
|
||||||
size_t size = privsize + sizeof(*al);
|
|
||||||
int nr = 1;
|
|
||||||
|
|
||||||
if (perf_evsel__is_group_event(evsel))
|
return (sizeof(struct disasm_line) + (sizeof(al->data[0]) * nr));
|
||||||
nr = evsel->core.nr_members;
|
|
||||||
|
|
||||||
size += sizeof(al->data[0]) * nr;
|
|
||||||
|
|
||||||
al = zalloc(size);
|
|
||||||
if (al) {
|
|
||||||
al = (void *) al + privsize;
|
|
||||||
al->privsize = privsize;
|
|
||||||
al->offset = args->offset;
|
|
||||||
al->line = strdup(args->line);
|
|
||||||
al->line_nr = args->line_nr;
|
|
||||||
al->data_nr = nr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return al;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocating the disasm annotation line data with
|
* Allocating the disasm annotation line data with
|
||||||
* following structure:
|
* following structure:
|
||||||
*
|
*
|
||||||
* ------------------------------------------------------------
|
* -------------------------------------------
|
||||||
* privsize space | struct disasm_line | struct annotation_line
|
* struct disasm_line | struct annotation_line
|
||||||
* ------------------------------------------------------------
|
* -------------------------------------------
|
||||||
*
|
*
|
||||||
* We have 'struct annotation_line' member as last member
|
* We have 'struct annotation_line' member as last member
|
||||||
* of 'struct disasm_line' to have an easy access.
|
* of 'struct disasm_line' to have an easy access.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static struct disasm_line *disasm_line__new(struct annotate_args *args)
|
static struct disasm_line *disasm_line__new(struct annotate_args *args)
|
||||||
{
|
{
|
||||||
struct disasm_line *dl = NULL;
|
struct disasm_line *dl = NULL;
|
||||||
struct annotation_line *al;
|
int nr = 1;
|
||||||
size_t privsize = args->privsize + offsetof(struct disasm_line, al);
|
|
||||||
|
|
||||||
al = annotation_line__new(args, privsize);
|
if (perf_evsel__is_group_event(args->evsel))
|
||||||
if (al != NULL) {
|
nr = args->evsel->core.nr_members;
|
||||||
dl = disasm_line(al);
|
|
||||||
|
|
||||||
if (dl->al.line == NULL)
|
dl = zalloc(disasm_line_size(nr));
|
||||||
goto out_delete;
|
if (!dl)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (args->offset != -1) {
|
annotation_line__init(&dl->al, args, nr);
|
||||||
if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) < 0)
|
if (dl->al.line == NULL)
|
||||||
goto out_free_line;
|
goto out_delete;
|
||||||
|
|
||||||
disasm_line__init_ins(dl, args->arch, &args->ms);
|
if (args->offset != -1) {
|
||||||
}
|
if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) < 0)
|
||||||
|
goto out_free_line;
|
||||||
|
|
||||||
|
disasm_line__init_ins(dl, args->arch, &args->ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dl;
|
return dl;
|
||||||
|
@ -1248,7 +1225,8 @@ void disasm_line__free(struct disasm_line *dl)
|
||||||
else
|
else
|
||||||
ins__delete(&dl->ops);
|
ins__delete(&dl->ops);
|
||||||
zfree(&dl->ins.name);
|
zfree(&dl->ins.name);
|
||||||
annotation_line__delete(&dl->al);
|
annotation_line__exit(&dl->al);
|
||||||
|
free(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name)
|
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name)
|
||||||
|
@ -2152,11 +2130,9 @@ void symbol__calc_percent(struct symbol *sym, struct evsel *evsel)
|
||||||
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
|
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
|
||||||
struct annotation_options *options, struct arch **parch)
|
struct annotation_options *options, struct arch **parch)
|
||||||
{
|
{
|
||||||
size_t privsize = 0;
|
|
||||||
struct symbol *sym = ms->sym;
|
struct symbol *sym = ms->sym;
|
||||||
struct annotation *notes = symbol__annotation(sym);
|
struct annotation *notes = symbol__annotation(sym);
|
||||||
struct annotate_args args = {
|
struct annotate_args args = {
|
||||||
.privsize = privsize,
|
|
||||||
.evsel = evsel,
|
.evsel = evsel,
|
||||||
.options = options,
|
.options = options,
|
||||||
};
|
};
|
||||||
|
|
|
@ -139,7 +139,6 @@ struct annotation_line {
|
||||||
u64 cycles;
|
u64 cycles;
|
||||||
u64 cycles_max;
|
u64 cycles_max;
|
||||||
u64 cycles_min;
|
u64 cycles_min;
|
||||||
size_t privsize;
|
|
||||||
char *path;
|
char *path;
|
||||||
u32 idx;
|
u32 idx;
|
||||||
int idx_asm;
|
int idx_asm;
|
||||||
|
|
Loading…
Add table
Reference in a new issue