diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-11-28 08:52:40 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-12-09 06:46:06 -0500 |
commit | 05472daa4d8ab88a071bfcaa3bb47473e4071848 (patch) | |
tree | cf86ff56669b9967fed53839b5e6f4e6cd820a57 | |
parent | fa283ada1606e687641dc2b157d66ef0f9c9aa8a (diff) |
perf diff: Change compute methods to work with pair directly
Changing compute methods to operate over hist entry and its pair
directly. This makes the code more obvious and readable, instead of all
time checking for pair being != NULL.
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1354110769-2998-6-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-diff.c | 38 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 40 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 7 |
3 files changed, 46 insertions, 39 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 9fbbc01c5ad7..342085a18076 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -146,47 +146,40 @@ static int setup_compute(const struct option *opt, const char *str, | |||
146 | return -EINVAL; | 146 | return -EINVAL; |
147 | } | 147 | } |
148 | 148 | ||
149 | static double get_period_percent(struct hist_entry *he, u64 period) | 149 | double perf_diff__period_percent(struct hist_entry *he, u64 period) |
150 | { | 150 | { |
151 | u64 total = he->hists->stats.total_period; | 151 | u64 total = he->hists->stats.total_period; |
152 | return (period * 100.0) / total; | 152 | return (period * 100.0) / total; |
153 | } | 153 | } |
154 | 154 | ||
155 | double perf_diff__compute_delta(struct hist_entry *he) | 155 | double perf_diff__compute_delta(struct hist_entry *he, struct hist_entry *pair) |
156 | { | 156 | { |
157 | struct hist_entry *pair = hist_entry__next_pair(he); | 157 | double new_percent = perf_diff__period_percent(he, he->stat.period); |
158 | double new_percent = get_period_percent(he, he->stat.period); | 158 | double old_percent = perf_diff__period_percent(pair, pair->stat.period); |
159 | double old_percent = pair ? get_period_percent(pair, pair->stat.period) : 0.0; | ||
160 | 159 | ||
161 | he->diff.period_ratio_delta = new_percent - old_percent; | 160 | he->diff.period_ratio_delta = new_percent - old_percent; |
162 | he->diff.computed = true; | 161 | he->diff.computed = true; |
163 | return he->diff.period_ratio_delta; | 162 | return he->diff.period_ratio_delta; |
164 | } | 163 | } |
165 | 164 | ||
166 | double perf_diff__compute_ratio(struct hist_entry *he) | 165 | double perf_diff__compute_ratio(struct hist_entry *he, struct hist_entry *pair) |
167 | { | 166 | { |
168 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
169 | double new_period = he->stat.period; | 167 | double new_period = he->stat.period; |
170 | double old_period = pair ? pair->stat.period : 0; | 168 | double old_period = pair->stat.period; |
171 | 169 | ||
172 | he->diff.computed = true; | 170 | he->diff.computed = true; |
173 | he->diff.period_ratio = pair ? (new_period / old_period) : 0; | 171 | he->diff.period_ratio = new_period / old_period; |
174 | return he->diff.period_ratio; | 172 | return he->diff.period_ratio; |
175 | } | 173 | } |
176 | 174 | ||
177 | s64 perf_diff__compute_wdiff(struct hist_entry *he) | 175 | s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair) |
178 | { | 176 | { |
179 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
180 | u64 new_period = he->stat.period; | 177 | u64 new_period = he->stat.period; |
181 | u64 old_period = pair ? pair->stat.period : 0; | 178 | u64 old_period = pair->stat.period; |
182 | 179 | ||
183 | he->diff.computed = true; | 180 | he->diff.computed = true; |
184 | 181 | he->diff.wdiff = new_period * compute_wdiff_w2 - | |
185 | if (!pair) | 182 | old_period * compute_wdiff_w1; |
186 | he->diff.wdiff = 0; | ||
187 | else | ||
188 | he->diff.wdiff = new_period * compute_wdiff_w2 - | ||
189 | old_period * compute_wdiff_w1; | ||
190 | 183 | ||
191 | return he->diff.wdiff; | 184 | return he->diff.wdiff; |
192 | } | 185 | } |
@@ -385,18 +378,21 @@ static void hists__precompute(struct hists *hists) | |||
385 | 378 | ||
386 | while (next != NULL) { | 379 | while (next != NULL) { |
387 | struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node); | 380 | struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node); |
381 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
388 | 382 | ||
389 | next = rb_next(&he->rb_node); | 383 | next = rb_next(&he->rb_node); |
384 | if (!pair) | ||
385 | continue; | ||
390 | 386 | ||
391 | switch (compute) { | 387 | switch (compute) { |
392 | case COMPUTE_DELTA: | 388 | case COMPUTE_DELTA: |
393 | perf_diff__compute_delta(he); | 389 | perf_diff__compute_delta(he, pair); |
394 | break; | 390 | break; |
395 | case COMPUTE_RATIO: | 391 | case COMPUTE_RATIO: |
396 | perf_diff__compute_ratio(he); | 392 | perf_diff__compute_ratio(he, pair); |
397 | break; | 393 | break; |
398 | case COMPUTE_WEIGHTED_DIFF: | 394 | case COMPUTE_WEIGHTED_DIFF: |
399 | perf_diff__compute_wdiff(he); | 395 | perf_diff__compute_wdiff(he, pair); |
400 | break; | 396 | break; |
401 | default: | 397 | default: |
402 | BUG_ON(1); | 398 | BUG_ON(1); |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 6e639b506829..108e5ed67621 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -268,14 +268,18 @@ static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused) | |||
268 | 268 | ||
269 | static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) | 269 | static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) |
270 | { | 270 | { |
271 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
271 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; | 272 | const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; |
272 | char buf[32] = " "; | 273 | char buf[32] = " "; |
273 | double diff; | 274 | double diff = 0.0; |
274 | 275 | ||
275 | if (he->diff.computed) | 276 | if (pair) { |
276 | diff = he->diff.period_ratio_delta; | 277 | if (he->diff.computed) |
277 | else | 278 | diff = he->diff.period_ratio_delta; |
278 | diff = perf_diff__compute_delta(he); | 279 | else |
280 | diff = perf_diff__compute_delta(he, pair); | ||
281 | } else | ||
282 | diff = perf_diff__period_percent(he, he->stat.period); | ||
279 | 283 | ||
280 | if (fabs(diff) >= 0.01) | 284 | if (fabs(diff) >= 0.01) |
281 | scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); | 285 | scnprintf(buf, sizeof(buf), "%+4.2F%%", diff); |
@@ -297,14 +301,17 @@ static int hpp__width_ratio(struct perf_hpp *hpp __maybe_unused) | |||
297 | 301 | ||
298 | static int hpp__entry_ratio(struct perf_hpp *hpp, struct hist_entry *he) | 302 | static int hpp__entry_ratio(struct perf_hpp *hpp, struct hist_entry *he) |
299 | { | 303 | { |
304 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
300 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; | 305 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; |
301 | char buf[32] = " "; | 306 | char buf[32] = " "; |
302 | double ratio; | 307 | double ratio = 0.0; |
303 | 308 | ||
304 | if (he->diff.computed) | 309 | if (pair) { |
305 | ratio = he->diff.period_ratio; | 310 | if (he->diff.computed) |
306 | else | 311 | ratio = he->diff.period_ratio; |
307 | ratio = perf_diff__compute_ratio(he); | 312 | else |
313 | ratio = perf_diff__compute_ratio(he, pair); | ||
314 | } | ||
308 | 315 | ||
309 | if (ratio > 0.0) | 316 | if (ratio > 0.0) |
310 | scnprintf(buf, sizeof(buf), "%+14.6F", ratio); | 317 | scnprintf(buf, sizeof(buf), "%+14.6F", ratio); |
@@ -326,14 +333,17 @@ static int hpp__width_wdiff(struct perf_hpp *hpp __maybe_unused) | |||
326 | 333 | ||
327 | static int hpp__entry_wdiff(struct perf_hpp *hpp, struct hist_entry *he) | 334 | static int hpp__entry_wdiff(struct perf_hpp *hpp, struct hist_entry *he) |
328 | { | 335 | { |
336 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
329 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; | 337 | const char *fmt = symbol_conf.field_sep ? "%s" : "%14s"; |
330 | char buf[32] = " "; | 338 | char buf[32] = " "; |
331 | s64 wdiff; | 339 | s64 wdiff = 0; |
332 | 340 | ||
333 | if (he->diff.computed) | 341 | if (pair) { |
334 | wdiff = he->diff.wdiff; | 342 | if (he->diff.computed) |
335 | else | 343 | wdiff = he->diff.wdiff; |
336 | wdiff = perf_diff__compute_wdiff(he); | 344 | else |
345 | wdiff = perf_diff__compute_wdiff(he, pair); | ||
346 | } | ||
337 | 347 | ||
338 | if (wdiff != 0) | 348 | if (wdiff != 0) |
339 | scnprintf(buf, sizeof(buf), "%14ld", wdiff); | 349 | scnprintf(buf, sizeof(buf), "%14ld", wdiff); |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index a935a60d521c..235503aac08c 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -226,8 +226,9 @@ int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused, | |||
226 | 226 | ||
227 | unsigned int hists__sort_list_width(struct hists *self); | 227 | unsigned int hists__sort_list_width(struct hists *self); |
228 | 228 | ||
229 | double perf_diff__compute_delta(struct hist_entry *he); | 229 | double perf_diff__compute_delta(struct hist_entry *he, struct hist_entry *pair); |
230 | double perf_diff__compute_ratio(struct hist_entry *he); | 230 | double perf_diff__compute_ratio(struct hist_entry *he, struct hist_entry *pair); |
231 | s64 perf_diff__compute_wdiff(struct hist_entry *he); | 231 | s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair); |
232 | int perf_diff__formula(char *buf, size_t size, struct hist_entry *he); | 232 | int perf_diff__formula(char *buf, size_t size, struct hist_entry *he); |
233 | double perf_diff__period_percent(struct hist_entry *he, u64 period); | ||
233 | #endif /* __PERF_HIST_H */ | 234 | #endif /* __PERF_HIST_H */ |