Skip to content

Commit 2316f86

Browse files
Ravi Bangoriaacmel
authored andcommitted
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 <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jin Yao <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Song Liu <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e0ad4d6 commit 2316f86

File tree

2 files changed

+31
-56
lines changed

2 files changed

+31
-56
lines changed

tools/perf/util/annotate.c

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,6 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
11431143
}
11441144

11451145
struct annotate_args {
1146-
size_t privsize;
11471146
struct arch *arch;
11481147
struct map_symbol ms;
11491148
struct evsel *evsel;
@@ -1153,83 +1152,61 @@ struct annotate_args {
11531152
int line_nr;
11541153
};
11551154

1156-
static void annotation_line__delete(struct annotation_line *al)
1155+
static void annotation_line__init(struct annotation_line *al,
1156+
struct annotate_args *args,
1157+
int nr)
11571158
{
1158-
void *ptr = (void *) al - al->privsize;
1159+
al->offset = args->offset;
1160+
al->line = strdup(args->line);
1161+
al->line_nr = args->line_nr;
1162+
al->data_nr = nr;
1163+
}
11591164

1165+
static void annotation_line__exit(struct annotation_line *al)
1166+
{
11601167
free_srcline(al->path);
11611168
zfree(&al->line);
1162-
free(ptr);
11631169
}
11641170

1165-
/*
1166-
* Allocating the annotation line data with following
1167-
* structure:
1168-
*
1169-
* --------------------------------------
1170-
* private space | struct annotation_line
1171-
* --------------------------------------
1172-
*
1173-
* Size of the private space is stored in 'struct annotation_line'.
1174-
*
1175-
*/
1176-
static struct annotation_line *
1177-
annotation_line__new(struct annotate_args *args, size_t privsize)
1171+
static size_t disasm_line_size(int nr)
11781172
{
11791173
struct annotation_line *al;
1180-
struct evsel *evsel = args->evsel;
1181-
size_t size = privsize + sizeof(*al);
1182-
int nr = 1;
1183-
1184-
if (perf_evsel__is_group_event(evsel))
1185-
nr = evsel->core.nr_members;
1186-
1187-
size += sizeof(al->data[0]) * nr;
11881174

1189-
al = zalloc(size);
1190-
if (al) {
1191-
al = (void *) al + privsize;
1192-
al->privsize = privsize;
1193-
al->offset = args->offset;
1194-
al->line = strdup(args->line);
1195-
al->line_nr = args->line_nr;
1196-
al->data_nr = nr;
1197-
}
1198-
1199-
return al;
1175+
return (sizeof(struct disasm_line) + (sizeof(al->data[0]) * nr));
12001176
}
12011177

12021178
/*
12031179
* Allocating the disasm annotation line data with
12041180
* following structure:
12051181
*
1206-
* ------------------------------------------------------------
1207-
* privsize space | struct disasm_line | struct annotation_line
1208-
* ------------------------------------------------------------
1182+
* -------------------------------------------
1183+
* struct disasm_line | struct annotation_line
1184+
* -------------------------------------------
12091185
*
12101186
* We have 'struct annotation_line' member as last member
12111187
* of 'struct disasm_line' to have an easy access.
1212-
*
12131188
*/
12141189
static struct disasm_line *disasm_line__new(struct annotate_args *args)
12151190
{
12161191
struct disasm_line *dl = NULL;
1217-
struct annotation_line *al;
1218-
size_t privsize = args->privsize + offsetof(struct disasm_line, al);
1192+
int nr = 1;
12191193

1220-
al = annotation_line__new(args, privsize);
1221-
if (al != NULL) {
1222-
dl = disasm_line(al);
1194+
if (perf_evsel__is_group_event(args->evsel))
1195+
nr = args->evsel->core.nr_members;
12231196

1224-
if (dl->al.line == NULL)
1225-
goto out_delete;
1197+
dl = zalloc(disasm_line_size(nr));
1198+
if (!dl)
1199+
return NULL;
12261200

1227-
if (args->offset != -1) {
1228-
if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) < 0)
1229-
goto out_free_line;
1201+
annotation_line__init(&dl->al, args, nr);
1202+
if (dl->al.line == NULL)
1203+
goto out_delete;
12301204

1231-
disasm_line__init_ins(dl, args->arch, &args->ms);
1232-
}
1205+
if (args->offset != -1) {
1206+
if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) < 0)
1207+
goto out_free_line;
1208+
1209+
disasm_line__init_ins(dl, args->arch, &args->ms);
12331210
}
12341211

12351212
return dl;
@@ -1248,7 +1225,8 @@ void disasm_line__free(struct disasm_line *dl)
12481225
else
12491226
ins__delete(&dl->ops);
12501227
zfree(&dl->ins.name);
1251-
annotation_line__delete(&dl->al);
1228+
annotation_line__exit(&dl->al);
1229+
free(dl);
12521230
}
12531231

12541232
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)
21522130
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
21532131
struct annotation_options *options, struct arch **parch)
21542132
{
2155-
size_t privsize = 0;
21562133
struct symbol *sym = ms->sym;
21572134
struct annotation *notes = symbol__annotation(sym);
21582135
struct annotate_args args = {
2159-
.privsize = privsize,
21602136
.evsel = evsel,
21612137
.options = options,
21622138
};

tools/perf/util/annotate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ struct annotation_line {
139139
u64 cycles;
140140
u64 cycles_max;
141141
u64 cycles_min;
142-
size_t privsize;
143142
char *path;
144143
u32 idx;
145144
int idx_asm;

0 commit comments

Comments
 (0)