aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-10-05 10:44:45 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-10-05 13:13:36 -0400
commited279da2fc9774b4c0dc9fd513fa89a11cae3f56 (patch)
treecf7f38620d7e7ede1976b999ae613c35db959fc8
parent61949b212e7f6f8f31891236ba24033f9b7af8c3 (diff)
perf diff: Add -F option to display formula for computation
Adding -F option to display the formula for specified computation. This is mainly to facilitate debugging, but can be useful anyway. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Andi Kleen <andi@firstfloor.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/1349448287-18919-7-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-diff.txt4
-rw-r--r--tools/perf/builtin-diff.c67
-rw-r--r--tools/perf/ui/hist.c24
-rw-r--r--tools/perf/ui/stdio/hist.c2
-rw-r--r--tools/perf/util/hist.h2
5 files changed, 96 insertions, 3 deletions
diff --git a/tools/perf/Documentation/perf-diff.txt b/tools/perf/Documentation/perf-diff.txt
index 21cc2ef7756b..194f37d635df 100644
--- a/tools/perf/Documentation/perf-diff.txt
+++ b/tools/perf/Documentation/perf-diff.txt
@@ -87,6 +87,10 @@ OPTIONS
87--period:: 87--period::
88 Show period values for both compared hist entries. 88 Show period values for both compared hist entries.
89 89
90-F::
91--formula::
92 Show formula for given computation.
93
90COMPARISON METHODS 94COMPARISON METHODS
91------------------ 95------------------
92delta 96delta
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 2411dd18c556..dd9c064514f2 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -25,6 +25,7 @@ static char diff__default_sort_order[] = "dso,symbol";
25static bool force; 25static bool force;
26static bool show_displacement; 26static bool show_displacement;
27static bool show_period; 27static bool show_period;
28static bool show_formula;
28static bool show_baseline_only; 29static bool show_baseline_only;
29static bool sort_compute; 30static bool sort_compute;
30 31
@@ -190,6 +191,62 @@ s64 perf_diff__compute_wdiff(struct hist_entry *he)
190 return he->diff.wdiff; 191 return he->diff.wdiff;
191} 192}
192 193
194static int formula_delta(struct hist_entry *he, char *buf, size_t size)
195{
196 struct hist_entry *pair = he->pair;
197
198 if (!pair)
199 return -1;
200
201 return scnprintf(buf, size,
202 "(%" PRIu64 " * 100 / %" PRIu64 ") - "
203 "(%" PRIu64 " * 100 / %" PRIu64 ")",
204 he->stat.period, he->hists->stats.total_period,
205 pair->stat.period, pair->hists->stats.total_period);
206}
207
208static int formula_ratio(struct hist_entry *he, char *buf, size_t size)
209{
210 struct hist_entry *pair = he->pair;
211 double new_period = he->stat.period;
212 double old_period = pair ? pair->stat.period : 0;
213
214 if (!pair)
215 return -1;
216
217 return scnprintf(buf, size, "%.0F / %.0F", new_period, old_period);
218}
219
220static int formula_wdiff(struct hist_entry *he, char *buf, size_t size)
221{
222 struct hist_entry *pair = he->pair;
223 u64 new_period = he->stat.period;
224 u64 old_period = pair ? pair->stat.period : 0;
225
226 if (!pair)
227 return -1;
228
229 return scnprintf(buf, size,
230 "(%" PRIu64 " * " "%" PRId64 ") - (%" PRIu64 " * " "%" PRId64 ")",
231 new_period, compute_wdiff_w2, old_period, compute_wdiff_w1);
232}
233
234int perf_diff__formula(char *buf, size_t size, struct hist_entry *he)
235{
236 switch (compute) {
237 case COMPUTE_DELTA:
238 return formula_delta(he, buf, size);
239 case COMPUTE_RATIO:
240 return formula_ratio(he, buf, size);
241 case COMPUTE_WEIGHTED_DIFF:
242 return formula_wdiff(he, buf, size);
243 default:
244 BUG_ON(1);
245 }
246
247 return -1;
248}
249
193static int hists__add_entry(struct hists *self, 250static int hists__add_entry(struct hists *self,
194 struct addr_location *al, u64 period) 251 struct addr_location *al, u64 period)
195{ 252{
@@ -543,6 +600,8 @@ static const struct option options[] = {
543 setup_compute), 600 setup_compute),
544 OPT_BOOLEAN('p', "period", &show_period, 601 OPT_BOOLEAN('p', "period", &show_period,
545 "Show period values."), 602 "Show period values."),
603 OPT_BOOLEAN('F', "formula", &show_formula,
604 "Show formula."),
546 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, 605 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
547 "dump raw trace in ASCII"), 606 "dump raw trace in ASCII"),
548 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"), 607 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
@@ -571,7 +630,10 @@ static void ui_init(void)
571 /* No overhead column. */ 630 /* No overhead column. */
572 perf_hpp__column_enable(PERF_HPP__OVERHEAD, false); 631 perf_hpp__column_enable(PERF_HPP__OVERHEAD, false);
573 632
574 /* Display baseline/delta/ratio/displacement/periods columns. */ 633 /*
634 * Display baseline/delta/ratio/displacement/
635 * formula/periods columns.
636 */
575 perf_hpp__column_enable(PERF_HPP__BASELINE, true); 637 perf_hpp__column_enable(PERF_HPP__BASELINE, true);
576 638
577 switch (compute) { 639 switch (compute) {
@@ -591,6 +653,9 @@ static void ui_init(void)
591 if (show_displacement) 653 if (show_displacement)
592 perf_hpp__column_enable(PERF_HPP__DISPL, true); 654 perf_hpp__column_enable(PERF_HPP__DISPL, true);
593 655
656 if (show_formula)
657 perf_hpp__column_enable(PERF_HPP__FORMULA, true);
658
594 if (show_period) { 659 if (show_period) {
595 perf_hpp__column_enable(PERF_HPP__PERIOD, true); 660 perf_hpp__column_enable(PERF_HPP__PERIOD, true);
596 perf_hpp__column_enable(PERF_HPP__PERIOD_BASELINE, true); 661 perf_hpp__column_enable(PERF_HPP__PERIOD_BASELINE, true);
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 2fadaff6312f..305eb79f4af4 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -359,6 +359,27 @@ static int hpp__entry_displ(struct perf_hpp *hpp,
359 return scnprintf(hpp->buf, hpp->size, fmt, buf); 359 return scnprintf(hpp->buf, hpp->size, fmt, buf);
360} 360}
361 361
362static int hpp__header_formula(struct perf_hpp *hpp)
363{
364 const char *fmt = symbol_conf.field_sep ? "%s" : "%70s";
365
366 return scnprintf(hpp->buf, hpp->size, fmt, "Formula");
367}
368
369static int hpp__width_formula(struct perf_hpp *hpp __maybe_unused)
370{
371 return 70;
372}
373
374static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he)
375{
376 const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s";
377 char buf[96] = " ";
378
379 perf_diff__formula(buf, sizeof(buf), he);
380 return scnprintf(hpp->buf, hpp->size, fmt, buf);
381}
382
362#define HPP__COLOR_PRINT_FNS(_name) \ 383#define HPP__COLOR_PRINT_FNS(_name) \
363 .header = hpp__header_ ## _name, \ 384 .header = hpp__header_ ## _name, \
364 .width = hpp__width_ ## _name, \ 385 .width = hpp__width_ ## _name, \
@@ -383,7 +404,8 @@ struct perf_hpp_fmt perf_hpp__format[] = {
383 { .cond = false, HPP__PRINT_FNS(delta) }, 404 { .cond = false, HPP__PRINT_FNS(delta) },
384 { .cond = false, HPP__PRINT_FNS(ratio) }, 405 { .cond = false, HPP__PRINT_FNS(ratio) },
385 { .cond = false, HPP__PRINT_FNS(wdiff) }, 406 { .cond = false, HPP__PRINT_FNS(wdiff) },
386 { .cond = false, HPP__PRINT_FNS(displ) } 407 { .cond = false, HPP__PRINT_FNS(displ) },
408 { .cond = false, HPP__PRINT_FNS(formula) }
387}; 409};
388 410
389#undef HPP__COLOR_PRINT_FNS 411#undef HPP__COLOR_PRINT_FNS
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index fbd4e32d0743..f0ee204f99bb 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -342,7 +342,7 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
342 const char *sep = symbol_conf.field_sep; 342 const char *sep = symbol_conf.field_sep;
343 const char *col_width = symbol_conf.col_width_list_str; 343 const char *col_width = symbol_conf.col_width_list_str;
344 int idx, nr_rows = 0; 344 int idx, nr_rows = 0;
345 char bf[64]; 345 char bf[96];
346 struct perf_hpp dummy_hpp = { 346 struct perf_hpp dummy_hpp = {
347 .buf = bf, 347 .buf = bf,
348 .size = sizeof(bf), 348 .size = sizeof(bf),
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 5604791e5ede..c751624d4153 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -145,6 +145,7 @@ enum {
145 PERF_HPP__RATIO, 145 PERF_HPP__RATIO,
146 PERF_HPP__WEIGHTED_DIFF, 146 PERF_HPP__WEIGHTED_DIFF,
147 PERF_HPP__DISPL, 147 PERF_HPP__DISPL,
148 PERF_HPP__FORMULA,
148 149
149 PERF_HPP__MAX_INDEX 150 PERF_HPP__MAX_INDEX
150}; 151};
@@ -210,4 +211,5 @@ unsigned int hists__sort_list_width(struct hists *self);
210double perf_diff__compute_delta(struct hist_entry *he); 211double perf_diff__compute_delta(struct hist_entry *he);
211double perf_diff__compute_ratio(struct hist_entry *he); 212double perf_diff__compute_ratio(struct hist_entry *he);
212s64 perf_diff__compute_wdiff(struct hist_entry *he); 213s64 perf_diff__compute_wdiff(struct hist_entry *he);
214int perf_diff__formula(char *buf, size_t size, struct hist_entry *he);
213#endif /* __PERF_HIST_H */ 215#endif /* __PERF_HIST_H */