perf evlist: Rename for_each() macros to for_each_entry()
[deliverable/linux.git] / tools / perf / builtin-script.c
index 52826696c8528d6f17773b9d4359ea7053cc7e0e..0e18e06e7fd58098eba6caa84f8d80aaa9d72cb6 100644 (file)
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/stat.h"
 #include <linux/bitmap.h>
+#include <linux/stringify.h>
 #include "asm/bug.h"
 #include "util/mem-events.h"
 
@@ -317,19 +318,19 @@ static void set_print_ip_opts(struct perf_event_attr *attr)
 
        output[type].print_ip_opts = 0;
        if (PRINT_FIELD(IP))
-               output[type].print_ip_opts |= PRINT_IP_OPT_IP;
+               output[type].print_ip_opts |= EVSEL__PRINT_IP;
 
        if (PRINT_FIELD(SYM))
-               output[type].print_ip_opts |= PRINT_IP_OPT_SYM;
+               output[type].print_ip_opts |= EVSEL__PRINT_SYM;
 
        if (PRINT_FIELD(DSO))
-               output[type].print_ip_opts |= PRINT_IP_OPT_DSO;
+               output[type].print_ip_opts |= EVSEL__PRINT_DSO;
 
        if (PRINT_FIELD(SYMOFFSET))
-               output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
+               output[type].print_ip_opts |= EVSEL__PRINT_SYMOFFSET;
 
        if (PRINT_FIELD(SRCLINE))
-               output[type].print_ip_opts |= PRINT_IP_OPT_SRCLINE;
+               output[type].print_ip_opts |= EVSEL__PRINT_SRCLINE;
 }
 
 /*
@@ -338,7 +339,7 @@ static void set_print_ip_opts(struct perf_event_attr *attr)
  */
 static int perf_session__check_output_opt(struct perf_session *session)
 {
-       int j;
+       unsigned int j;
        struct perf_evsel *evsel;
 
        for (j = 0; j < PERF_TYPE_MAX; ++j) {
@@ -368,7 +369,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
        if (!no_callchain) {
                bool use_callchain = false;
 
-               evlist__for_each(session->evlist, evsel) {
+               evlist__for_each_entry(session->evlist, evsel) {
                        if (evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN) {
                                use_callchain = true;
                                break;
@@ -387,17 +388,20 @@ static int perf_session__check_output_opt(struct perf_session *session)
                struct perf_event_attr *attr;
 
                j = PERF_TYPE_TRACEPOINT;
-               evsel = perf_session__find_first_evtype(session, j);
-               if (evsel == NULL)
-                       goto out;
 
-               attr = &evsel->attr;
+               evlist__for_each_entry(session->evlist, evsel) {
+                       if (evsel->attr.type != j)
+                               continue;
+
+                       attr = &evsel->attr;
 
-               if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) {
-                       output[j].fields |= PERF_OUTPUT_IP;
-                       output[j].fields |= PERF_OUTPUT_SYM;
-                       output[j].fields |= PERF_OUTPUT_DSO;
-                       set_print_ip_opts(attr);
+                       if (attr->sample_type & PERF_SAMPLE_CALLCHAIN) {
+                               output[j].fields |= PERF_OUTPUT_IP;
+                               output[j].fields |= PERF_OUTPUT_SYM;
+                               output[j].fields |= PERF_OUTPUT_DSO;
+                               set_print_ip_opts(attr);
+                               goto out;
+                       }
                }
        }
 
@@ -569,18 +573,23 @@ static void print_sample_bts(struct perf_sample *sample,
        /* print branch_from information */
        if (PRINT_FIELD(IP)) {
                unsigned int print_opts = output[attr->type].print_ip_opts;
+               struct callchain_cursor *cursor = NULL;
 
-               if (symbol_conf.use_callchain && sample->callchain) {
-                       printf("\n");
-               } else {
-                       printf(" ");
-                       if (print_opts & PRINT_IP_OPT_SRCLINE) {
+               if (symbol_conf.use_callchain && sample->callchain &&
+                   thread__resolve_callchain(al->thread, &callchain_cursor, evsel,
+                                             sample, NULL, NULL, scripting_max_stack) == 0)
+                       cursor = &callchain_cursor;
+
+               if (cursor == NULL) {
+                       putchar(' ');
+                       if (print_opts & EVSEL__PRINT_SRCLINE) {
                                print_srcline_last = true;
-                               print_opts &= ~PRINT_IP_OPT_SRCLINE;
+                               print_opts &= ~EVSEL__PRINT_SRCLINE;
                        }
-               }
-               perf_evsel__print_ip(evsel, sample, al, print_opts,
-                                    scripting_max_stack);
+               } else
+                       putchar('\n');
+
+               sample__fprintf_sym(sample, al, 0, print_opts, cursor, stdout);
        }
 
        /* print branch_to information */
@@ -711,7 +720,7 @@ static int perf_evlist__max_name_len(struct perf_evlist *evlist)
        struct perf_evsel *evsel;
        int max = 0;
 
-       evlist__for_each(evlist, evsel) {
+       evlist__for_each_entry(evlist, evsel) {
                int len = strlen(perf_evsel__name(evsel));
 
                max = MAX(len, max);
@@ -783,14 +792,15 @@ static void process_event(struct perf_script *script,
                printf("%16" PRIu64, sample->weight);
 
        if (PRINT_FIELD(IP)) {
-               if (!symbol_conf.use_callchain)
-                       printf(" ");
-               else
-                       printf("\n");
+               struct callchain_cursor *cursor = NULL;
+
+               if (symbol_conf.use_callchain && sample->callchain &&
+                   thread__resolve_callchain(al->thread, &callchain_cursor, evsel,
+                                             sample, NULL, NULL, scripting_max_stack) == 0)
+                       cursor = &callchain_cursor;
 
-               perf_evsel__print_ip(evsel, sample, al,
-                                    output[attr->type].print_ip_opts,
-                                    scripting_max_stack);
+               putchar(cursor ? '\n' : ' ');
+               sample__fprintf_sym(sample, al, 0, output[attr->type].print_ip_opts, cursor, stdout);
        }
 
        if (PRINT_FIELD(IREGS))
@@ -935,7 +945,7 @@ static int process_attr(struct perf_tool *tool, union perf_event *event,
        if (evsel->attr.type >= PERF_TYPE_MAX)
                return 0;
 
-       evlist__for_each(evlist, pos) {
+       evlist__for_each_entry(evlist, pos) {
                if (pos->attr.type == evsel->attr.type && pos != evsel)
                        return 0;
        }
@@ -1661,7 +1671,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
                        snprintf(evname, len + 1, "%s", p);
 
                        match = 0;
-                       evlist__for_each(session->evlist, pos) {
+                       evlist__for_each_entry(session->evlist, pos) {
                                if (!strcmp(perf_evsel__name(pos), evname)) {
                                        match = 1;
                                        break;
@@ -1863,7 +1873,7 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
        struct stat_round_event *round = &event->stat_round;
        struct perf_evsel *counter;
 
-       evlist__for_each(session->evlist, counter) {
+       evlist__for_each_entry(session->evlist, counter) {
                perf_stat_process_counter(&stat_config, counter);
                process_stat(counter, round->time);
        }
@@ -1959,6 +1969,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                        .exit            = perf_event__process_exit,
                        .fork            = perf_event__process_fork,
                        .attr            = process_attr,
+                       .event_update   = perf_event__process_event_update,
                        .tracing_data    = perf_event__process_tracing_data,
                        .build_id        = perf_event__process_build_id,
                        .id_index        = perf_event__process_id_index,
@@ -2002,8 +2013,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                   "file", "kallsyms pathname"),
        OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
                    "When printing symbols do not display call chain"),
-       OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
-                   "Look for files with symbols relative to this directory"),
+       OPT_CALLBACK(0, "symfs", NULL, "directory",
+                    "Look for files with symbols relative to this directory",
+                    symbol__config_symfs),
        OPT_CALLBACK('F', "fields", NULL, "str",
                     "comma separated output fields prepend with 'type:'. "
                     "Valid types: hw,sw,trace,raw. "
@@ -2020,6 +2032,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
                   "only consider symbols in these pids"),
        OPT_STRING(0, "tid", &symbol_conf.tid_list_str, "tid[,tid...]",
                   "only consider symbols in these tids"),
+       OPT_UINTEGER(0, "max-stack", &scripting_max_stack,
+                    "Set the maximum stack depth when parsing the callchain, "
+                    "anything beyond the specified depth will be ignored. "
+                    "Default: kernel.perf_event_max_stack or " __stringify(PERF_MAX_STACK_DEPTH)),
        OPT_BOOLEAN('I', "show-info", &show_full_info,
                    "display extended information from perf.data file"),
        OPT_BOOLEAN('\0', "show-kernel-path", &symbol_conf.show_kernel_path,
This page took 0.026536 seconds and 5 git commands to generate.