perf tools: Check recorded kernel version when finding vmlinux
[deliverable/linux.git] / tools / perf / builtin-script.c
index 9e9c91f5b7fae97de166583b46bd801fc4ccc2f1..37d2b608d3887e292bff19b91b7ea840dd4133c8 100644 (file)
@@ -358,27 +358,6 @@ static void print_sample_start(struct perf_sample *sample,
        }
 }
 
-static bool is_bts_event(struct perf_event_attr *attr)
-{
-       return ((attr->type == PERF_TYPE_HARDWARE) &&
-               (attr->config & PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
-               (attr->sample_period == 1));
-}
-
-static bool sample_addr_correlates_sym(struct perf_event_attr *attr)
-{
-       if ((attr->type == PERF_TYPE_SOFTWARE) &&
-           ((attr->config == PERF_COUNT_SW_PAGE_FAULTS) ||
-            (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MIN) ||
-            (attr->config == PERF_COUNT_SW_PAGE_FAULTS_MAJ)))
-               return true;
-
-       if (is_bts_event(attr))
-               return true;
-
-       return false;
-}
-
 static void print_sample_addr(union perf_event *event,
                          struct perf_sample *sample,
                          struct machine *machine,
@@ -386,24 +365,13 @@ static void print_sample_addr(union perf_event *event,
                          struct perf_event_attr *attr)
 {
        struct addr_location al;
-       u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
        printf("%16" PRIx64, sample->addr);
 
        if (!sample_addr_correlates_sym(attr))
                return;
 
-       thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
-                             sample->addr, &al);
-       if (!al.map)
-               thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
-                                     sample->addr, &al);
-
-       al.cpu = sample->cpu;
-       al.sym = NULL;
-
-       if (al.map)
-               al.sym = map__find_symbol(al.map, al.addr, NULL);
+       perf_event__preprocess_sample_addr(event, sample, machine, thread, &al);
 
        if (PRINT_FIELD(SYM)) {
                printf(" ");
@@ -427,25 +395,35 @@ static void print_sample_bts(union perf_event *event,
                             struct addr_location *al)
 {
        struct perf_event_attr *attr = &evsel->attr;
+       bool print_srcline_last = false;
 
        /* print branch_from information */
        if (PRINT_FIELD(IP)) {
-               if (!symbol_conf.use_callchain)
-                       printf(" ");
-               else
+               unsigned int print_opts = output[attr->type].print_ip_opts;
+
+               if (symbol_conf.use_callchain && sample->callchain) {
                        printf("\n");
-               perf_evsel__print_ip(evsel, sample, al,
-                                    output[attr->type].print_ip_opts,
+               } else {
+                       printf(" ");
+                       if (print_opts & PRINT_IP_OPT_SRCLINE) {
+                               print_srcline_last = true;
+                               print_opts &= ~PRINT_IP_OPT_SRCLINE;
+                       }
+               }
+               perf_evsel__print_ip(evsel, sample, al, print_opts,
                                     PERF_MAX_STACK_DEPTH);
        }
 
-       printf(" => ");
-
        /* print branch_to information */
        if (PRINT_FIELD(ADDR) ||
            ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
-            !output[attr->type].user_set))
+            !output[attr->type].user_set)) {
+               printf(" => ");
                print_sample_addr(event, sample, al->machine, thread, attr);
+       }
+
+       if (print_srcline_last)
+               map__fprintf_srcline(al->map, al->addr, "\n  ", stdout);
 
        printf("\n");
 }
@@ -1493,12 +1471,13 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
        bool show_full_info = false;
        bool header = false;
        bool header_only = false;
+       bool script_started = false;
        char *rec_script_path = NULL;
        char *rep_script_path = NULL;
        struct perf_session *session;
        char *script_path = NULL;
        const char **__argv;
-       int i, j, err;
+       int i, j, err = 0;
        struct perf_script script = {
                .tool = {
                        .sample          = process_sample_event,
@@ -1510,7 +1489,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                        .attr            = process_attr,
                        .tracing_data    = perf_event__process_tracing_data,
                        .build_id        = perf_event__process_build_id,
-                       .ordered_samples = true,
+                       .ordered_events  = true,
                        .ordering_requires_timestamps = true,
                },
        };
@@ -1740,8 +1719,6 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                exit(-1);
        }
 
-       if (symbol__init() < 0)
-               return -1;
        if (!script_name)
                setup_pager();
 
@@ -1752,14 +1729,18 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
        if (header || header_only) {
                perf_session__fprintf_info(session, stdout, show_full_info);
                if (header_only)
-                       return 0;
+                       goto out_delete;
        }
 
+       if (symbol__init(&session->header.env) < 0)
+               goto out_delete;
+
        script.session = session;
 
        if (cpu_list) {
-               if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
-                       return -1;
+               err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
+               if (err < 0)
+                       goto out_delete;
        }
 
        if (!no_callchain)
@@ -1774,53 +1755,60 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                if (output_set_by_user()) {
                        fprintf(stderr,
                                "custom fields not supported for generated scripts");
-                       return -1;
+                       err = -EINVAL;
+                       goto out_delete;
                }
 
                input = open(file.path, O_RDONLY);      /* input_name */
                if (input < 0) {
+                       err = -errno;
                        perror("failed to open file");
-                       return -1;
+                       goto out_delete;
                }
 
                err = fstat(input, &perf_stat);
                if (err < 0) {
                        perror("failed to stat file");
-                       return -1;
+                       goto out_delete;
                }
 
                if (!perf_stat.st_size) {
                        fprintf(stderr, "zero-sized file, nothing to do!\n");
-                       return 0;
+                       goto out_delete;
                }
 
                scripting_ops = script_spec__lookup(generate_script_lang);
                if (!scripting_ops) {
                        fprintf(stderr, "invalid language specifier");
-                       return -1;
+                       err = -ENOENT;
+                       goto out_delete;
                }
 
                err = scripting_ops->generate_script(session->tevent.pevent,
                                                     "perf-script");
-               goto out;
+               goto out_delete;
        }
 
        if (script_name) {
                err = scripting_ops->start_script(script_name, argc, argv);
                if (err)
-                       goto out;
+                       goto out_delete;
                pr_debug("perf script started with script %s\n\n", script_name);
+               script_started = true;
        }
 
 
        err = perf_session__check_output_opt(session);
        if (err < 0)
-               goto out;
+               goto out_delete;
 
        err = __cmd_script(&script);
 
+out_delete:
        perf_session__delete(session);
-       cleanup_scripting();
+
+       if (script_started)
+               cleanup_scripting();
 out:
        return err;
 }
This page took 0.034334 seconds and 5 git commands to generate.