aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c67
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
23static char const *script_name; 27static char const *script_name;
24static char const *generate_script_lang; 28static 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
611static void process_event(struct perf_script *script __maybe_unused, union perf_event *event, 618static 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
1692static 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
1711static
1712int 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
1730static
1731int 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
1685int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) 1749int 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
2065out_delete: 2131out_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)