mm/migrate: correct failure handling if !hugepage_migration_support()
[firefly-linux-kernel-4.4.55.git] / tools / perf / builtin-script.c
index 4484886dcf0866a5fb26488de6c3d14bd0a08040..9e9c91f5b7fae97de166583b46bd801fc4ccc2f1 100644 (file)
@@ -43,6 +43,7 @@ enum perf_output_field {
        PERF_OUTPUT_DSO             = 1U << 9,
        PERF_OUTPUT_ADDR            = 1U << 10,
        PERF_OUTPUT_SYMOFFSET       = 1U << 11,
+       PERF_OUTPUT_SRCLINE         = 1U << 12,
 };
 
 struct output_option {
@@ -61,6 +62,7 @@ struct output_option {
        {.str = "dso",   .field = PERF_OUTPUT_DSO},
        {.str = "addr",  .field = PERF_OUTPUT_ADDR},
        {.str = "symoff", .field = PERF_OUTPUT_SYMOFFSET},
+       {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
 };
 
 /* default set to maintain compatibility with current format */
@@ -210,6 +212,11 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
                       "to DSO.\n");
                return -EINVAL;
        }
+       if (PRINT_FIELD(SRCLINE) && !PRINT_FIELD(IP)) {
+               pr_err("Display of source line number requested but sample IP is not\n"
+                      "selected. Hence, no address to lookup the source line number.\n");
+               return -EINVAL;
+       }
 
        if ((PRINT_FIELD(PID) || PRINT_FIELD(TID)) &&
                perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID",
@@ -245,6 +252,9 @@ static void set_print_ip_opts(struct perf_event_attr *attr)
 
        if (PRINT_FIELD(SYMOFFSET))
                output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
+
+       if (PRINT_FIELD(SRCLINE))
+               output[type].print_ip_opts |= PRINT_IP_OPT_SRCLINE;
 }
 
 /*
@@ -413,7 +423,6 @@ static void print_sample_addr(union perf_event *event,
 static void print_sample_bts(union perf_event *event,
                             struct perf_sample *sample,
                             struct perf_evsel *evsel,
-                            struct machine *machine,
                             struct thread *thread,
                             struct addr_location *al)
 {
@@ -425,7 +434,7 @@ static void print_sample_bts(union perf_event *event,
                        printf(" ");
                else
                        printf("\n");
-               perf_evsel__print_ip(evsel, sample, machine, al,
+               perf_evsel__print_ip(evsel, sample, al,
                                     output[attr->type].print_ip_opts,
                                     PERF_MAX_STACK_DEPTH);
        }
@@ -436,14 +445,13 @@ static void print_sample_bts(union perf_event *event,
        if (PRINT_FIELD(ADDR) ||
            ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
             !output[attr->type].user_set))
-               print_sample_addr(event, sample, machine, thread, attr);
+               print_sample_addr(event, sample, al->machine, thread, attr);
 
        printf("\n");
 }
 
 static void process_event(union perf_event *event, struct perf_sample *sample,
-                         struct perf_evsel *evsel, struct machine *machine,
-                         struct thread *thread,
+                         struct perf_evsel *evsel, struct thread *thread,
                          struct addr_location *al)
 {
        struct perf_event_attr *attr = &evsel->attr;
@@ -459,7 +467,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
        }
 
        if (is_bts_event(attr)) {
-               print_sample_bts(event, sample, evsel, machine, thread, al);
+               print_sample_bts(event, sample, evsel, thread, al);
                return;
        }
 
@@ -467,7 +475,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
                event_format__print(evsel->tp_format, sample->cpu,
                                    sample->raw_data, sample->raw_size);
        if (PRINT_FIELD(ADDR))
-               print_sample_addr(event, sample, machine, thread, attr);
+               print_sample_addr(event, sample, al->machine, thread, attr);
 
        if (PRINT_FIELD(IP)) {
                if (!symbol_conf.use_callchain)
@@ -475,7 +483,7 @@ static void process_event(union perf_event *event, struct perf_sample *sample,
                else
                        printf("\n");
 
-               perf_evsel__print_ip(evsel, sample, machine, al,
+               perf_evsel__print_ip(evsel, sample, al,
                                     output[attr->type].print_ip_opts,
                                     PERF_MAX_STACK_DEPTH);
        }
@@ -564,7 +572,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
        if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
                return 0;
 
-       scripting_ops->process_event(event, sample, evsel, machine, thread, &al);
+       scripting_ops->process_event(event, sample, evsel, thread, &al);
 
        evsel->hists.stats.total_period += sample->period;
        return 0;
@@ -595,7 +603,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
        if (evsel->attr.type >= PERF_TYPE_MAX)
                return 0;
 
-       list_for_each_entry(pos, &evlist->entries, node) {
+       evlist__for_each(evlist, pos) {
                if (pos->attr.type == evsel->attr.type && pos != evsel)
                        return 0;
        }
@@ -1094,9 +1102,9 @@ static struct script_desc *script_desc__new(const char *name)
 
 static void script_desc__delete(struct script_desc *s)
 {
-       free(s->name);
-       free(s->half_liner);
-       free(s->args);
+       zfree(&s->name);
+       zfree(&s->half_liner);
+       zfree(&s->args);
        free(s);
 }
 
@@ -1301,8 +1309,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
                        snprintf(evname, len + 1, "%s", p);
 
                        match = 0;
-                       list_for_each_entry(pos,
-                                       &session->evlist->entries, node) {
+                       evlist__for_each(session->evlist, pos) {
                                if (!strcmp(perf_evsel__name(pos), evname)) {
                                        match = 1;
                                        break;
@@ -1484,6 +1491,8 @@ static int have_cmd(int argc, const char **argv)
 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;
        char *rec_script_path = NULL;
        char *rep_script_path = NULL;
        struct perf_session *session;
@@ -1522,6 +1531,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
        OPT_STRING('i', "input", &input_name, "file", "input file name"),
        OPT_BOOLEAN('d', "debug-mode", &debug_mode,
                   "do various checks like samples ordering and lost events"),
+       OPT_BOOLEAN(0, "header", &header, "Show data header."),
+       OPT_BOOLEAN(0, "header-only", &header_only, "Show only data header."),
        OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
                   "file", "vmlinux pathname"),
        OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
@@ -1738,6 +1749,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
        if (session == NULL)
                return -ENOMEM;
 
+       if (header || header_only) {
+               perf_session__fprintf_info(session, stdout, show_full_info);
+               if (header_only)
+                       return 0;
+       }
+
        script.session = session;
 
        if (cpu_list) {
@@ -1745,9 +1762,6 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                        return -1;
        }
 
-       if (!script_name && !generate_script_lang)
-               perf_session__fprintf_info(session, stdout, show_full_info);
-
        if (!no_callchain)
                symbol_conf.use_callchain = true;
        else