perf report: Fix -T/--threads option to work again
[firefly-linux-kernel-4.4.55.git] / tools / perf / builtin-trace.c
index 211614fba2178e7866c136f9e5a55ab44af5e27b..e122970361f21af6d07c321480aefa2cb90bf31d 100644 (file)
@@ -1135,6 +1135,8 @@ static struct syscall_fmt *syscall_fmt__find(const char *name)
 
 struct syscall {
        struct event_format *tp_format;
+       int                 nr_args;
+       struct format_field *args;
        const char          *name;
        bool                filtered;
        bool                is_exit;
@@ -1252,6 +1254,7 @@ struct trace {
        bool                    show_comm;
        bool                    show_tool_stats;
        bool                    trace_syscalls;
+       bool                    force;
        int                     trace_pgfaults;
 };
 
@@ -1442,14 +1445,14 @@ static int syscall__set_arg_fmts(struct syscall *sc)
        struct format_field *field;
        int idx = 0;
 
-       sc->arg_scnprintf = calloc(sc->tp_format->format.nr_fields - 1, sizeof(void *));
+       sc->arg_scnprintf = calloc(sc->nr_args, sizeof(void *));
        if (sc->arg_scnprintf == NULL)
                return -1;
 
        if (sc->fmt)
                sc->arg_parm = sc->fmt->arg_parm;
 
-       for (field = sc->tp_format->format.fields->next; field; field = field->next) {
+       for (field = sc->args; field; field = field->next) {
                if (sc->fmt && sc->fmt->arg_scnprintf[idx])
                        sc->arg_scnprintf[idx] = sc->fmt->arg_scnprintf[idx];
                else if (field->flags & FIELD_IS_POINTER)
@@ -1515,6 +1518,14 @@ static int trace__read_syscall_info(struct trace *trace, int id)
        if (sc->tp_format == NULL)
                return -1;
 
+       sc->args = sc->tp_format->format.fields;
+       sc->nr_args = sc->tp_format->format.nr_fields;
+       /* drop nr field - not relevant here; does not exist on older kernels */
+       if (sc->args && strcmp(sc->args->name, "nr") == 0) {
+               sc->args = sc->args->next;
+               --sc->nr_args;
+       }
+
        sc->is_exit = !strcmp(name, "exit_group") || !strcmp(name, "exit");
 
        return syscall__set_arg_fmts(sc);
@@ -1537,7 +1548,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
        unsigned char *p;
        unsigned long val;
 
-       if (sc->tp_format != NULL) {
+       if (sc->args != NULL) {
                struct format_field *field;
                u8 bit = 1;
                struct syscall_arg arg = {
@@ -1547,7 +1558,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
                        .thread = thread,
                };
 
-               for (field = sc->tp_format->format.fields->next; field;
+               for (field = sc->args; field;
                     field = field->next, ++arg.idx, bit <<= 1) {
                        if (arg.mask & bit)
                                continue;
@@ -1724,7 +1735,8 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
                        return -1;
        }
 
-       printed += trace__printf_interrupted_entry(trace, sample);
+       if (!trace->summary_only)
+               trace__printf_interrupted_entry(trace, sample);
 
        ttrace->entry_time = sample->time;
        msg = ttrace->entry_str;
@@ -2229,10 +2241,11 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
        if (err < 0)
                goto out_error_mmap;
 
+       if (!target__none(&trace->opts.target))
+               perf_evlist__enable(evlist);
+
        if (forks)
                perf_evlist__start_workload(evlist);
-       else
-               perf_evlist__enable(evlist);
 
        trace->multiple_threads = evlist->threads->map[0] == -1 ||
                                  evlist->threads->nr > 1 ||
@@ -2260,6 +2273,11 @@ next_event:
 
                        if (interrupted)
                                goto out_disable;
+
+                       if (done && !draining) {
+                               perf_evlist__disable(evlist);
+                               draining = true;
+                       }
                }
        }
 
@@ -2334,6 +2352,7 @@ static int trace__replay(struct trace *trace)
        struct perf_data_file file = {
                .path  = input_name,
                .mode  = PERF_DATA_MODE_READ,
+               .force = trace->force,
        };
        struct perf_session *session;
        struct perf_evsel *evsel;
@@ -2408,7 +2427,7 @@ static int trace__replay(struct trace *trace)
 
        setup_pager();
 
-       err = perf_session__process_events(session, &trace->tool);
+       err = perf_session__process_events(session);
        if (err)
                pr_err("Failed to process events, error %d", err);
 
@@ -2609,7 +2628,7 @@ static void evlist__set_evsel_handler(struct perf_evlist *evlist, void *handler)
 
 int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-       const char * const trace_usage[] = {
+       const char *trace_usage[] = {
                "perf trace [<options>] [<command>]",
                "perf trace [<options>] -- <command> [<options>]",
                "perf trace record [<options>] [<command>]",
@@ -2682,8 +2701,10 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
        OPT_CALLBACK_DEFAULT('F', "pf", &trace.trace_pgfaults, "all|maj|min",
                     "Trace pagefaults", parse_pagefaults, "maj"),
        OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
+       OPT_BOOLEAN('f', "force", &trace.force, "don't complain, do it"),
        OPT_END()
        };
+       const char * const trace_subcommands[] = { "record", NULL };
        int err;
        char bf[BUFSIZ];
 
@@ -2699,8 +2720,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
                goto out;
        }
 
-       argc = parse_options(argc, argv, trace_options, trace_usage,
-                            PARSE_OPT_STOP_AT_NON_OPTION);
+       argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands,
+                                trace_usage, PARSE_OPT_STOP_AT_NON_OPTION);
 
        if (trace.trace_pgfaults) {
                trace.opts.sample_address = true;