diff options
author | Jiri Olsa <jolsa@redhat.com> | 2012-11-28 08:52:41 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-12-09 06:46:07 -0500 |
commit | f4c8bae1920c459b7b9c12363d11e8a588862e42 (patch) | |
tree | 923d0b943153198760e473261480666ea36dca05 | |
parent | 05472daa4d8ab88a071bfcaa3bb47473e4071848 (diff) |
perf diff: Change formula methods to work with pair directly
Changing formula 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-7-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-diff.c | 35 | ||||
-rw-r--r-- | tools/perf/ui/hist.c | 5 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 3 |
3 files changed, 19 insertions, 24 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 342085a18076..d869029fb75e 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -184,13 +184,9 @@ s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair) | |||
184 | return he->diff.wdiff; | 184 | return he->diff.wdiff; |
185 | } | 185 | } |
186 | 186 | ||
187 | static int formula_delta(struct hist_entry *he, char *buf, size_t size) | 187 | static int formula_delta(struct hist_entry *he, struct hist_entry *pair, |
188 | char *buf, size_t size) | ||
188 | { | 189 | { |
189 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
190 | |||
191 | if (!pair) | ||
192 | return -1; | ||
193 | |||
194 | return scnprintf(buf, size, | 190 | return scnprintf(buf, size, |
195 | "(%" PRIu64 " * 100 / %" PRIu64 ") - " | 191 | "(%" PRIu64 " * 100 / %" PRIu64 ") - " |
196 | "(%" PRIu64 " * 100 / %" PRIu64 ")", | 192 | "(%" PRIu64 " * 100 / %" PRIu64 ")", |
@@ -198,41 +194,36 @@ static int formula_delta(struct hist_entry *he, char *buf, size_t size) | |||
198 | pair->stat.period, pair->hists->stats.total_period); | 194 | pair->stat.period, pair->hists->stats.total_period); |
199 | } | 195 | } |
200 | 196 | ||
201 | static int formula_ratio(struct hist_entry *he, char *buf, size_t size) | 197 | static int formula_ratio(struct hist_entry *he, struct hist_entry *pair, |
198 | char *buf, size_t size) | ||
202 | { | 199 | { |
203 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
204 | double new_period = he->stat.period; | 200 | double new_period = he->stat.period; |
205 | double old_period = pair ? pair->stat.period : 0; | 201 | double old_period = pair->stat.period; |
206 | |||
207 | if (!pair) | ||
208 | return -1; | ||
209 | 202 | ||
210 | return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period); | 203 | return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period); |
211 | } | 204 | } |
212 | 205 | ||
213 | static int formula_wdiff(struct hist_entry *he, char *buf, size_t size) | 206 | static int formula_wdiff(struct hist_entry *he, struct hist_entry *pair, |
207 | char *buf, size_t size) | ||
214 | { | 208 | { |
215 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
216 | u64 new_period = he->stat.period; | 209 | u64 new_period = he->stat.period; |
217 | u64 old_period = pair ? pair->stat.period : 0; | 210 | u64 old_period = pair->stat.period; |
218 | |||
219 | if (!pair) | ||
220 | return -1; | ||
221 | 211 | ||
222 | return scnprintf(buf, size, | 212 | return scnprintf(buf, size, |
223 | "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")", | 213 | "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")", |
224 | new_period, compute_wdiff_w2, old_period, compute_wdiff_w1); | 214 | new_period, compute_wdiff_w2, old_period, compute_wdiff_w1); |
225 | } | 215 | } |
226 | 216 | ||
227 | int perf_diff__formula(char *buf, size_t size, struct hist_entry *he) | 217 | int perf_diff__formula(struct hist_entry *he, struct hist_entry *pair, |
218 | char *buf, size_t size) | ||
228 | { | 219 | { |
229 | switch (compute) { | 220 | switch (compute) { |
230 | case COMPUTE_DELTA: | 221 | case COMPUTE_DELTA: |
231 | return formula_delta(he, buf, size); | 222 | return formula_delta(he, pair, buf, size); |
232 | case COMPUTE_RATIO: | 223 | case COMPUTE_RATIO: |
233 | return formula_ratio(he, buf, size); | 224 | return formula_ratio(he, pair, buf, size); |
234 | case COMPUTE_WEIGHTED_DIFF: | 225 | case COMPUTE_WEIGHTED_DIFF: |
235 | return formula_wdiff(he, buf, size); | 226 | return formula_wdiff(he, pair, buf, size); |
236 | default: | 227 | default: |
237 | BUG_ON(1); | 228 | BUG_ON(1); |
238 | } | 229 | } |
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 108e5ed67621..1785bab7adfd 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -389,10 +389,13 @@ static int hpp__width_formula(struct perf_hpp *hpp __maybe_unused) | |||
389 | 389 | ||
390 | static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he) | 390 | static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he) |
391 | { | 391 | { |
392 | struct hist_entry *pair = hist_entry__next_pair(he); | ||
392 | const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s"; | 393 | const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s"; |
393 | char buf[96] = " "; | 394 | char buf[96] = " "; |
394 | 395 | ||
395 | perf_diff__formula(buf, sizeof(buf), he); | 396 | if (pair) |
397 | perf_diff__formula(he, pair, buf, sizeof(buf)); | ||
398 | |||
396 | return scnprintf(hpp->buf, hpp->size, fmt, buf); | 399 | return scnprintf(hpp->buf, hpp->size, fmt, buf); |
397 | } | 400 | } |
398 | 401 | ||
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 235503aac08c..c1b2fade8e70 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -229,6 +229,7 @@ unsigned int hists__sort_list_width(struct hists *self); | |||
229 | double perf_diff__compute_delta(struct hist_entry *he, struct hist_entry *pair); | 229 | double perf_diff__compute_delta(struct hist_entry *he, struct hist_entry *pair); |
230 | double perf_diff__compute_ratio(struct hist_entry *he, struct hist_entry *pair); | 230 | double perf_diff__compute_ratio(struct hist_entry *he, struct hist_entry *pair); |
231 | s64 perf_diff__compute_wdiff(struct hist_entry *he, struct hist_entry *pair); | 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(struct hist_entry *he, struct hist_entry *pair, |
233 | char *buf, size_t size); | ||
233 | double perf_diff__period_percent(struct hist_entry *he, u64 period); | 234 | double perf_diff__period_percent(struct hist_entry *he, u64 period); |
234 | #endif /* __PERF_HIST_H */ | 235 | #endif /* __PERF_HIST_H */ |