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.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b27f21638207..fb5e49b3bc44 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1392,6 +1392,7 @@ struct perf_script {
1392 bool show_switch_events; 1392 bool show_switch_events;
1393 bool show_namespace_events; 1393 bool show_namespace_events;
1394 bool allocated; 1394 bool allocated;
1395 bool per_event_dump;
1395 struct cpu_map *cpus; 1396 struct cpu_map *cpus;
1396 struct thread_map *threads; 1397 struct thread_map *threads;
1397 int name_width; 1398 int name_width;
@@ -1438,7 +1439,7 @@ static void process_event(struct perf_script *script,
1438 struct thread *thread = al->thread; 1439 struct thread *thread = al->thread;
1439 struct perf_event_attr *attr = &evsel->attr; 1440 struct perf_event_attr *attr = &evsel->attr;
1440 unsigned int type = output_type(attr->type); 1441 unsigned int type = output_type(attr->type);
1441 FILE *fp = stdout; 1442 FILE *fp = evsel->priv;
1442 1443
1443 if (output[type].fields == 0) 1444 if (output[type].fields == 0)
1444 return; 1445 return;
@@ -1887,6 +1888,52 @@ static void sig_handler(int sig __maybe_unused)
1887 session_done = 1; 1888 session_done = 1;
1888} 1889}
1889 1890
1891static void perf_script__fclose_per_event_dump(struct perf_script *script)
1892{
1893 struct perf_evlist *evlist = script->session->evlist;
1894 struct perf_evsel *evsel;
1895
1896 evlist__for_each_entry(evlist, evsel) {
1897 if (!evsel->priv)
1898 break;
1899 fclose(evsel->priv);
1900 evsel->priv = NULL;
1901 }
1902}
1903
1904static int perf_script__fopen_per_event_dump(struct perf_script *script)
1905{
1906 struct perf_evsel *evsel;
1907
1908 evlist__for_each_entry(script->session->evlist, evsel) {
1909 char filename[PATH_MAX];
1910 snprintf(filename, sizeof(filename), "%s.%s.dump",
1911 script->session->file->path, perf_evsel__name(evsel));
1912 evsel->priv = fopen(filename, "w");
1913 if (evsel->priv == NULL)
1914 goto out_err_fclose;
1915 }
1916
1917 return 0;
1918
1919out_err_fclose:
1920 perf_script__fclose_per_event_dump(script);
1921 return -1;
1922}
1923
1924static int perf_script__setup_per_event_dump(struct perf_script *script)
1925{
1926 struct perf_evsel *evsel;
1927
1928 if (script->per_event_dump)
1929 return perf_script__fopen_per_event_dump(script);
1930
1931 evlist__for_each_entry(script->session->evlist, evsel)
1932 evsel->priv = stdout;
1933
1934 return 0;
1935}
1936
1890static int __cmd_script(struct perf_script *script) 1937static int __cmd_script(struct perf_script *script)
1891{ 1938{
1892 int ret; 1939 int ret;
@@ -1908,8 +1955,16 @@ static int __cmd_script(struct perf_script *script)
1908 if (script->show_namespace_events) 1955 if (script->show_namespace_events)
1909 script->tool.namespaces = process_namespaces_event; 1956 script->tool.namespaces = process_namespaces_event;
1910 1957
1958 if (perf_script__setup_per_event_dump(script)) {
1959 pr_err("Couldn't create the per event dump files\n");
1960 return -1;
1961 }
1962
1911 ret = perf_session__process_events(script->session); 1963 ret = perf_session__process_events(script->session);
1912 1964
1965 if (script->per_event_dump)
1966 perf_script__fclose_per_event_dump(script);
1967
1913 if (debug_mode) 1968 if (debug_mode)
1914 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered); 1969 pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
1915 1970
@@ -2827,6 +2882,8 @@ int cmd_script(int argc, const char **argv)
2827 "Show context switch events (if recorded)"), 2882 "Show context switch events (if recorded)"),
2828 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events, 2883 OPT_BOOLEAN('\0', "show-namespace-events", &script.show_namespace_events,
2829 "Show namespace events (if recorded)"), 2884 "Show namespace events (if recorded)"),
2885 OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
2886 "Dump trace output to files named by the monitored events"),
2830 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), 2887 OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
2831 OPT_INTEGER(0, "max-blocks", &max_blocks, 2888 OPT_INTEGER(0, "max-blocks", &max_blocks,
2832 "Maximum number of code blocks to dump with brstackinsn"), 2889 "Maximum number of code blocks to dump with brstackinsn"),