diff options
author | Jiri Olsa <jolsa@kernel.org> | 2016-01-05 16:09:06 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-01-06 18:11:15 -0500 |
commit | cfc8874a485992491b865dde64965bb7c18c26b5 (patch) | |
tree | d3f5490b7d0b2b96da90af8f3d4c3a3bd386e299 /tools/perf/builtin-script.c | |
parent | 6db1a5c190d6abe416ea36aa28a6c53e0b3bbd5e (diff) |
perf script: Process cpu/threads maps
Adding processing of cpu/threads maps. Configuring session's evlist with
these maps.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Kan Liang <kan.liang@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1452028152-26762-3-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r-- | tools/perf/builtin-script.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index bcc3542d9df5..aa6d7cf87dab 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -18,7 +18,11 @@ | |||
18 | #include "util/sort.h" | 18 | #include "util/sort.h" |
19 | #include "util/data.h" | 19 | #include "util/data.h" |
20 | #include "util/auxtrace.h" | 20 | #include "util/auxtrace.h" |
21 | #include "util/cpumap.h" | ||
22 | #include "util/thread_map.h" | ||
23 | #include "util/stat.h" | ||
21 | #include <linux/bitmap.h> | 24 | #include <linux/bitmap.h> |
25 | #include "asm/bug.h" | ||
22 | 26 | ||
23 | static char const *script_name; | 27 | static char const *script_name; |
24 | static char const *generate_script_lang; | 28 | static char const *generate_script_lang; |
@@ -606,6 +610,9 @@ struct perf_script { | |||
606 | bool show_task_events; | 610 | bool show_task_events; |
607 | bool show_mmap_events; | 611 | bool show_mmap_events; |
608 | bool show_switch_events; | 612 | bool show_switch_events; |
613 | bool allocated; | ||
614 | struct cpu_map *cpus; | ||
615 | struct thread_map *threads; | ||
609 | }; | 616 | }; |
610 | 617 | ||
611 | static void process_event(struct perf_script *script __maybe_unused, union perf_event *event, | 618 | static void process_event(struct perf_script *script __maybe_unused, union perf_event *event, |
@@ -1682,6 +1689,63 @@ static void script__setup_sample_type(struct perf_script *script) | |||
1682 | } | 1689 | } |
1683 | } | 1690 | } |
1684 | 1691 | ||
1692 | static int set_maps(struct perf_script *script) | ||
1693 | { | ||
1694 | struct perf_evlist *evlist = script->session->evlist; | ||
1695 | |||
1696 | if (!script->cpus || !script->threads) | ||
1697 | return 0; | ||
1698 | |||
1699 | if (WARN_ONCE(script->allocated, "stats double allocation\n")) | ||
1700 | return -EINVAL; | ||
1701 | |||
1702 | perf_evlist__set_maps(evlist, script->cpus, script->threads); | ||
1703 | |||
1704 | if (perf_evlist__alloc_stats(evlist, true)) | ||
1705 | return -ENOMEM; | ||
1706 | |||
1707 | script->allocated = true; | ||
1708 | return 0; | ||
1709 | } | ||
1710 | |||
1711 | static | ||
1712 | int process_thread_map_event(struct perf_tool *tool, | ||
1713 | union perf_event *event, | ||
1714 | struct perf_session *session __maybe_unused) | ||
1715 | { | ||
1716 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
1717 | |||
1718 | if (script->threads) { | ||
1719 | pr_warning("Extra thread map event, ignoring.\n"); | ||
1720 | return 0; | ||
1721 | } | ||
1722 | |||
1723 | script->threads = thread_map__new_event(&event->thread_map); | ||
1724 | if (!script->threads) | ||
1725 | return -ENOMEM; | ||
1726 | |||
1727 | return set_maps(script); | ||
1728 | } | ||
1729 | |||
1730 | static | ||
1731 | int process_cpu_map_event(struct perf_tool *tool __maybe_unused, | ||
1732 | union perf_event *event, | ||
1733 | struct perf_session *session __maybe_unused) | ||
1734 | { | ||
1735 | struct perf_script *script = container_of(tool, struct perf_script, tool); | ||
1736 | |||
1737 | if (script->cpus) { | ||
1738 | pr_warning("Extra cpu map event, ignoring.\n"); | ||
1739 | return 0; | ||
1740 | } | ||
1741 | |||
1742 | script->cpus = cpu_map__new_data(&event->cpu_map.data); | ||
1743 | if (!script->cpus) | ||
1744 | return -ENOMEM; | ||
1745 | |||
1746 | return set_maps(script); | ||
1747 | } | ||
1748 | |||
1685 | int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | 1749 | int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) |
1686 | { | 1750 | { |
1687 | bool show_full_info = false; | 1751 | bool show_full_info = false; |
@@ -1710,6 +1774,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1710 | .auxtrace_info = perf_event__process_auxtrace_info, | 1774 | .auxtrace_info = perf_event__process_auxtrace_info, |
1711 | .auxtrace = perf_event__process_auxtrace, | 1775 | .auxtrace = perf_event__process_auxtrace, |
1712 | .auxtrace_error = perf_event__process_auxtrace_error, | 1776 | .auxtrace_error = perf_event__process_auxtrace_error, |
1777 | .thread_map = process_thread_map_event, | ||
1778 | .cpu_map = process_cpu_map_event, | ||
1713 | .ordered_events = true, | 1779 | .ordered_events = true, |
1714 | .ordering_requires_timestamps = true, | 1780 | .ordering_requires_timestamps = true, |
1715 | }, | 1781 | }, |
@@ -2063,6 +2129,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) | |||
2063 | flush_scripting(); | 2129 | flush_scripting(); |
2064 | 2130 | ||
2065 | out_delete: | 2131 | out_delete: |
2132 | perf_evlist__free_stats(session->evlist); | ||
2066 | perf_session__delete(session); | 2133 | perf_session__delete(session); |
2067 | 2134 | ||
2068 | if (script_started) | 2135 | if (script_started) |