aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-diff.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-11-28 08:52:41 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-12-09 06:46:07 -0500
commitf4c8bae1920c459b7b9c12363d11e8a588862e42 (patch)
tree923d0b943153198760e473261480666ea36dca05 /tools/perf/builtin-diff.c
parent05472daa4d8ab88a071bfcaa3bb47473e4071848 (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>
Diffstat (limited to 'tools/perf/builtin-diff.c')
-rw-r--r--tools/perf/builtin-diff.c35
1 files changed, 13 insertions, 22 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
187static int formula_delta(struct hist_entry *he, char *buf, size_t size) 187static 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
201static int formula_ratio(struct hist_entry *he, char *buf, size_t size) 197static 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
213static int formula_wdiff(struct hist_entry *he, char *buf, size_t size) 206static 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
227int perf_diff__formula(char *buf, size_t size, struct hist_entry *he) 217int 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 }