File perf-annotate-introduce-struct-sym_hist_entry.patch of Package perf
259
1
From: Taeung Song <treeze.taeung@gmail.com>
2
Date: Thu, 20 Jul 2017 06:36:45 +0900
3
Subject: perf annotate: Introduce struct sym_hist_entry
4
Git-commit: 896bccd3cb8d95cbc565687715516009c5169e71
5
Patch-mainline: v4.14-rc1
6
References: bsc#1070010 (git-fixes)
7
Signed-off-By: Tony Jones <tonyj@suse.de>
8
9
struct sym_hist has addr[] but it should have not only number of samples
10
but also the sample period. So use new struct symhist_entry to pave the
11
way to have that.
12
13
Committer notes:
14
15
This initial patch will only introduce the struct sym_hist_entry and use
16
only the nr_samples member, which makes the code clearer and paves the
17
way to save the period as well.
18
19
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
20
Suggested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
21
Cc: Jiri Olsa <jolsa@redhat.com>
22
Cc: Namhyung Kim <namhyung@kernel.org>
23
Link: http://lkml.kernel.org/r/1500500205-16553-1-git-send-email-treeze.taeung@gmail.com
24
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
25
---
26
tools/perf/ui/browsers/annotate.c | 6 +++---
27
tools/perf/ui/gtk/annotate.c | 4 ++--
28
tools/perf/util/annotate.c | 45 ++++++++++++++++++++-------------------
29
tools/perf/util/annotate.h | 9 ++++++--
30
4 files changed, 35 insertions(+), 29 deletions(-)
31
32
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
33
index 6794a8bec404..dbe4e630b90f 100644
34
--- a/tools/perf/ui/browsers/annotate.c
35
+++ b/tools/perf/ui/browsers/annotate.c
36
37
next = disasm__get_next_ip_line(¬es->src->source, pos);
38
39
for (i = 0; i < browser->nr_events; i++) {
40
- u64 nr_samples;
41
+ struct sym_hist_entry sample;
42
43
bpos->samples[i].percent = disasm__calc_percent(notes,
44
evsel->idx + i,
45
pos->offset,
46
next ? next->offset : len,
47
- &path, &nr_samples);
48
- bpos->samples[i].nr = nr_samples;
49
+ &path, &sample);
50
+ bpos->samples[i].nr = sample.nr_samples;
51
52
if (max_percent < bpos->samples[i].percent)
53
max_percent = bpos->samples[i].percent;
54
diff --git a/tools/perf/ui/gtk/annotate.c b/tools/perf/ui/gtk/annotate.c
55
index 87e3760624f2..d736fd57ab9b 100644
56
--- a/tools/perf/ui/gtk/annotate.c
57
+++ b/tools/perf/ui/gtk/annotate.c
58
59
return 0;
60
61
symhist = annotation__histogram(symbol__annotation(sym), evidx);
62
- if (!symbol_conf.event_group && !symhist->addr[dl->offset])
63
+ if (!symbol_conf.event_group && !symhist->addr[dl->offset].nr_samples)
64
return 0;
65
66
- percent = 100.0 * symhist->addr[dl->offset] / symhist->sum;
67
+ percent = 100.0 * symhist->addr[dl->offset].nr_samples / symhist->sum;
68
69
markup = perf_gtk__get_percent_color(percent);
70
if (markup)
71
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
72
index 1742510f0120..c3829555ce1c 100644
73
--- a/tools/perf/util/annotate.c
74
+++ b/tools/perf/util/annotate.c
75
76
size_t sizeof_sym_hist;
77
78
/* Check for overflow when calculating sizeof_sym_hist */
79
- if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(u64))
80
+ if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(struct sym_hist_entry))
81
return -1;
82
83
- sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64));
84
+ sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(struct sym_hist_entry));
85
86
/* Check for overflow in zalloc argument */
87
if (sizeof_sym_hist > (SIZE_MAX - sizeof(*notes->src))
88
89
offset = addr - sym->start;
90
h = annotation__histogram(notes, evidx);
91
h->sum++;
92
- h->addr[offset]++;
93
+ h->addr[offset].nr_samples++;
94
95
pr_debug3("%#" PRIx64 " %s: period++ [addr: %#" PRIx64 ", %#" PRIx64
96
", evidx=%d] => %" PRIu64 "\n", sym->start, sym->name,
97
- addr, addr - sym->start, evidx, h->addr[offset]);
98
+ addr, addr - sym->start, evidx, h->addr[offset].nr_samples);
99
return 0;
100
}
101
102
103
}
104
105
double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
106
- s64 end, const char **path, u64 *nr_samples)
107
+ s64 end, const char **path, struct sym_hist_entry *sample)
108
{
109
struct source_line *src_line = notes->src->lines;
110
double percent = 0.0;
111
- *nr_samples = 0;
112
+
113
+ sample->nr_samples = 0;
114
115
if (src_line) {
116
size_t sizeof_src_line = sizeof(*src_line) +
117
118
*path = src_line->path;
119
120
percent += src_line->samples[evidx].percent;
121
- *nr_samples += src_line->samples[evidx].nr;
122
+ sample->nr_samples += src_line->samples[evidx].nr;
123
offset++;
124
}
125
} else {
126
127
unsigned int hits = 0;
128
129
while (offset < end)
130
- hits += h->addr[offset++];
131
+ hits += h->addr[offset++].nr_samples;
132
133
if (h->sum) {
134
- *nr_samples = hits;
135
+ sample->nr_samples = hits;
136
percent = 100.0 * hits / h->sum;
137
}
138
}
139
140
141
if (dl->offset != -1) {
142
const char *path = NULL;
143
- u64 nr_samples;
144
double percent, max_percent = 0.0;
145
double *ppercents = &percent;
146
- u64 *psamples = &nr_samples;
147
+ struct sym_hist_entry sample;
148
+ struct sym_hist_entry *psamples = &sample;
149
int i, nr_percent = 1;
150
const char *color;
151
struct annotation *notes = symbol__annotation(sym);
152
153
if (perf_evsel__is_group_event(evsel)) {
154
nr_percent = evsel->nr_members;
155
ppercents = calloc(nr_percent, sizeof(double));
156
- psamples = calloc(nr_percent, sizeof(u64));
157
+ psamples = calloc(nr_percent, sizeof(struct sym_hist_entry));
158
if (ppercents == NULL || psamples == NULL) {
159
return -1;
160
}
161
162
notes->src->lines ? i : evsel->idx + i,
163
offset,
164
next ? next->offset : (s64) len,
165
- &path, &nr_samples);
166
+ &path, &sample);
167
168
ppercents[i] = percent;
169
- psamples[i] = nr_samples;
170
+ psamples[i] = sample;
171
if (percent > max_percent)
172
max_percent = percent;
173
}
174
175
176
for (i = 0; i < nr_percent; i++) {
177
percent = ppercents[i];
178
- nr_samples = psamples[i];
179
+ sample = psamples[i];
180
color = get_percent_color(percent);
181
182
if (symbol_conf.show_total_period)
183
color_fprintf(stdout, color, " %7" PRIu64,
184
- nr_samples);
185
+ sample.nr_samples);
186
else
187
color_fprintf(stdout, color, " %7.2f", percent);
188
}
189
190
if (ppercents != &percent)
191
free(ppercents);
192
193
- if (psamples != &nr_samples)
194
+ if (psamples != &sample)
195
free(psamples);
196
197
} else if (max_lines && printed >= max_lines)
198
199
double percent = 0.0;
200
201
h = annotation__histogram(notes, evidx + k);
202
- nr_samples = h->addr[i];
203
+ nr_samples = h->addr[i].nr_samples;
204
if (h->sum)
205
percent = 100.0 * nr_samples / h->sum;
206
207
208
u64 len = symbol__size(sym), offset;
209
210
for (offset = 0; offset < len; ++offset)
211
- if (h->addr[offset] != 0)
212
+ if (h->addr[offset].nr_samples != 0)
213
printf("%*" PRIx64 ": %" PRIu64 "\n", BITS_PER_LONG / 2,
214
- sym->start + offset, h->addr[offset]);
215
+ sym->start + offset, h->addr[offset].nr_samples);
216
printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
217
}
218
219
220
221
h->sum = 0;
222
for (offset = 0; offset < len; ++offset) {
223
- h->addr[offset] = h->addr[offset] * 7 / 8;
224
- h->sum += h->addr[offset];
225
+ h->addr[offset].nr_samples = h->addr[offset].nr_samples * 7 / 8;
226
+ h->sum += h->addr[offset].nr_samples;
227
}
228
}
229
230
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
231
index bac698d7cc6a..3a176633b324 100644
232
--- a/tools/perf/util/annotate.h
233
+++ b/tools/perf/util/annotate.h
234
235
return dl->ops.target.offset_avail;
236
}
237
238
+struct sym_hist_entry {
239
+ u64 nr_samples;
240
+ u64 period;
241
+};
242
+
243
void disasm_line__free(struct disasm_line *dl);
244
struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
245
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
246
size_t disasm__fprintf(struct list_head *head, FILE *fp);
247
double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
248
- s64 end, const char **path, u64 *nr_samples);
249
+ s64 end, const char **path, struct sym_hist_entry *sample);
250
251
struct sym_hist {
252
u64 sum;
253
- u64 addr[0];
254
+ struct sym_hist_entry addr[0];
255
};
256
257
struct cyc_hist {
258
259