Commit 896cbb56bfee6ad99e0ee1b8209dc678f1a49f5a
Committed by
Arnaldo Carvalho de Melo
1 parent
35feee19f9
Exists in
master
and in
16 other branches
perf trace: Use new machine method to loop over threads
Use the new machine method that loops over threads to dump summary data. Signed-off-by: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung.kim@lge.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1380395584-9025-3-git-send-email-dsahern@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Showing 1 changed file with 48 additions and 28 deletions Side-by-side Diff
tools/perf/builtin-trace.c
... | ... | @@ -1751,37 +1751,57 @@ |
1751 | 1751 | return printed; |
1752 | 1752 | } |
1753 | 1753 | |
1754 | -static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) | |
1754 | +/* struct used to pass data to per-thread function */ | |
1755 | +struct summary_data { | |
1756 | + FILE *fp; | |
1757 | + struct trace *trace; | |
1758 | + size_t printed; | |
1759 | +}; | |
1760 | + | |
1761 | +static int trace__fprintf_one_thread(struct thread *thread, void *priv) | |
1755 | 1762 | { |
1756 | - size_t printed = trace__fprintf_threads_header(fp); | |
1757 | - struct rb_node *nd; | |
1763 | + struct summary_data *data = priv; | |
1764 | + FILE *fp = data->fp; | |
1765 | + size_t printed = data->printed; | |
1766 | + struct trace *trace = data->trace; | |
1767 | + struct thread_trace *ttrace = thread->priv; | |
1768 | + const char *color; | |
1769 | + double ratio; | |
1758 | 1770 | |
1759 | - for (nd = rb_first(&trace->host->threads); nd; nd = rb_next(nd)) { | |
1760 | - struct thread *thread = rb_entry(nd, struct thread, rb_node); | |
1761 | - struct thread_trace *ttrace = thread->priv; | |
1762 | - const char *color; | |
1763 | - double ratio; | |
1771 | + if (ttrace == NULL) | |
1772 | + return 0; | |
1764 | 1773 | |
1765 | - if (ttrace == NULL) | |
1766 | - continue; | |
1774 | + ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; | |
1767 | 1775 | |
1768 | - ratio = (double)ttrace->nr_events / trace->nr_events * 100.0; | |
1776 | + color = PERF_COLOR_NORMAL; | |
1777 | + if (ratio > 50.0) | |
1778 | + color = PERF_COLOR_RED; | |
1779 | + else if (ratio > 25.0) | |
1780 | + color = PERF_COLOR_GREEN; | |
1781 | + else if (ratio > 5.0) | |
1782 | + color = PERF_COLOR_YELLOW; | |
1769 | 1783 | |
1770 | - color = PERF_COLOR_NORMAL; | |
1771 | - if (ratio > 50.0) | |
1772 | - color = PERF_COLOR_RED; | |
1773 | - else if (ratio > 25.0) | |
1774 | - color = PERF_COLOR_GREEN; | |
1775 | - else if (ratio > 5.0) | |
1776 | - color = PERF_COLOR_YELLOW; | |
1784 | + printed += color_fprintf(fp, color, "%20s", thread->comm); | |
1785 | + printed += fprintf(fp, " - %-5d :%11lu [", thread->tid, ttrace->nr_events); | |
1786 | + printed += color_fprintf(fp, color, "%5.1f%%", ratio); | |
1787 | + printed += fprintf(fp, " ] %10.3f ms\n", ttrace->runtime_ms); | |
1777 | 1788 | |
1778 | - printed += color_fprintf(fp, color, "%20s", thread->comm); | |
1779 | - printed += fprintf(fp, " - %-5d :%11lu [", thread->tid, ttrace->nr_events); | |
1780 | - printed += color_fprintf(fp, color, "%5.1f%%", ratio); | |
1781 | - printed += fprintf(fp, " ] %10.3f ms\n", ttrace->runtime_ms); | |
1782 | - } | |
1789 | + data->printed += printed; | |
1783 | 1790 | |
1784 | - return printed; | |
1791 | + return 0; | |
1792 | +} | |
1793 | + | |
1794 | +static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) | |
1795 | +{ | |
1796 | + struct summary_data data = { | |
1797 | + .fp = fp, | |
1798 | + .trace = trace | |
1799 | + }; | |
1800 | + data.printed = trace__fprintf_threads_header(fp); | |
1801 | + | |
1802 | + machine__for_each_thread(trace->host, trace__fprintf_one_thread, &data); | |
1803 | + | |
1804 | + return data.printed; | |
1785 | 1805 | } |
1786 | 1806 | |
1787 | 1807 | static int trace__set_duration(const struct option *opt, const char *str, |