Skip to content

Commit f59e366

Browse files
committed
perf annotate: Remove sym_hist.addr[] array
It's not used anymore and the code is coverted to use a hash map. Now sym_hist has a static size, so no need to have sizeof_sym_hist in the struct annotated_source. Reviewed-by: Ian Rogers <[email protected]> Reviewed-by: Arnaldo Carvalho de Melo <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Andi Kleen <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8015457 commit f59e366

File tree

2 files changed

+6
-34
lines changed

2 files changed

+6
-34
lines changed

tools/perf/util/annotate.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -896,33 +896,10 @@ static __maybe_unused void annotated_source__delete(struct annotated_source *src
896896
}
897897

898898
static int annotated_source__alloc_histograms(struct annotated_source *src,
899-
size_t size, int nr_hists)
899+
int nr_hists)
900900
{
901-
size_t sizeof_sym_hist;
902-
903-
/*
904-
* Add buffer of one element for zero length symbol.
905-
* When sample is taken from first instruction of
906-
* zero length symbol, perf still resolves it and
907-
* shows symbol name in perf report and allows to
908-
* annotate it.
909-
*/
910-
if (size == 0)
911-
size = 1;
912-
913-
/* Check for overflow when calculating sizeof_sym_hist */
914-
if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(struct sym_hist_entry))
915-
return -1;
916-
917-
sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(struct sym_hist_entry));
918-
919-
/* Check for overflow in zalloc argument */
920-
if (sizeof_sym_hist > SIZE_MAX / nr_hists)
921-
return -1;
922-
923-
src->sizeof_sym_hist = sizeof_sym_hist;
924901
src->nr_histograms = nr_hists;
925-
src->histograms = calloc(nr_hists, sizeof_sym_hist) ;
902+
src->histograms = calloc(nr_hists, sizeof(*src->histograms));
926903

927904
if (src->histograms == NULL)
928905
return -1;
@@ -941,7 +918,7 @@ void symbol__annotate_zero_histograms(struct symbol *sym)
941918
annotation__lock(notes);
942919
if (notes->src != NULL) {
943920
memset(notes->src->histograms, 0,
944-
notes->src->nr_histograms * notes->src->sizeof_sym_hist);
921+
notes->src->nr_histograms * sizeof(*notes->src->histograms));
945922
hashmap__clear(notes->src->samples);
946923
}
947924
if (notes->branch && notes->branch->cycles_hist) {
@@ -1039,9 +1016,7 @@ static int __symbol__inc_addr_samples(struct map_symbol *ms,
10391016
}
10401017

10411018
h->nr_samples++;
1042-
h->addr[offset].nr_samples++;
10431019
h->period += sample->period;
1044-
h->addr[offset].period += sample->period;
10451020
entry->nr_samples++;
10461021
entry->period += sample->period;
10471022

@@ -1094,8 +1069,7 @@ struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists)
10941069

10951070
if (notes->src->histograms == NULL) {
10961071
alloc_histograms:
1097-
annotated_source__alloc_histograms(notes->src, symbol__size(sym),
1098-
nr_hists);
1072+
annotated_source__alloc_histograms(notes->src, nr_hists);
10991073
}
11001074

11011075
return notes->src;
@@ -2854,7 +2828,7 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx)
28542828
struct annotation *notes = symbol__annotation(sym);
28552829
struct sym_hist *h = annotation__histogram(notes, evidx);
28562830

2857-
memset(h, 0, notes->src->sizeof_sym_hist);
2831+
memset(h, 0, sizeof(*notes->src->histograms) * notes->src->nr_histograms);
28582832
}
28592833

28602834
void symbol__annotate_decay_histogram(struct symbol *sym, int evidx)

tools/perf/util/annotate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ void symbol__calc_percent(struct symbol *sym, struct evsel *evsel);
242242
struct sym_hist {
243243
u64 nr_samples;
244244
u64 period;
245-
struct sym_hist_entry addr[];
246245
};
247246

248247
struct cyc_hist {
@@ -278,7 +277,6 @@ struct cyc_hist {
278277
*/
279278
struct annotated_source {
280279
struct list_head source;
281-
size_t sizeof_sym_hist;
282280
struct sym_hist *histograms;
283281
struct annotation_line **offsets;
284282
struct hashmap *samples;
@@ -348,7 +346,7 @@ void annotation__toggle_full_addr(struct annotation *notes, struct map_symbol *m
348346

349347
static inline struct sym_hist *annotated_source__histogram(struct annotated_source *src, int idx)
350348
{
351-
return ((void *)src->histograms) + (src->sizeof_sym_hist * idx);
349+
return &src->histograms[idx];
352350
}
353351

354352
static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)

0 commit comments

Comments
 (0)