]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/perf/builtin-script.c
perf script: Add --insn-trace for instruction decoding
[linux.git] / tools / perf / builtin-script.c
index 7732346bd9dd45a1281188e00394fa55564649b2..411ea175bcaf0c4e002224f75145284fc4eab1c1 100644 (file)
@@ -44,6 +44,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <subcmd/pager.h>
 
 #include "sane_ctype.h"
 
@@ -1262,6 +1263,18 @@ static struct {
        {0, NULL}
 };
 
+static const char *sample_flags_to_name(u32 flags)
+{
+       int i;
+
+       for (i = 0; sample_flags[i].name ; i++) {
+               if (sample_flags[i].flags == flags)
+                       return sample_flags[i].name;
+       }
+
+       return NULL;
+}
+
 static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
 {
        const char *chars = PERF_IP_FLAG_CHARS;
@@ -1271,11 +1284,20 @@ static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
        char str[33];
        int i, pos = 0;
 
-       for (i = 0; sample_flags[i].name ; i++) {
-               if (sample_flags[i].flags == (flags & ~PERF_IP_FLAG_IN_TX)) {
-                       name = sample_flags[i].name;
-                       break;
-               }
+       name = sample_flags_to_name(flags & ~PERF_IP_FLAG_IN_TX);
+       if (name)
+               return fprintf(fp, "  %-15s%4s ", name, in_tx ? "(x)" : "");
+
+       if (flags & PERF_IP_FLAG_TRACE_BEGIN) {
+               name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_BEGIN));
+               if (name)
+                       return fprintf(fp, "  tr strt %-7s%4s ", name, in_tx ? "(x)" : "");
+       }
+
+       if (flags & PERF_IP_FLAG_TRACE_END) {
+               name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_END));
+               if (name)
+                       return fprintf(fp, "  tr end  %-7s%4s ", name, in_tx ? "(x)" : "");
        }
 
        for (i = 0; i < n; i++, flags >>= 1) {
@@ -1288,10 +1310,7 @@ static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
        }
        str[pos] = 0;
 
-       if (name)
-               return fprintf(fp, "  %-7s%4s ", name, in_tx ? "(x)" : "");
-
-       return fprintf(fp, "  %-11s ", str);
+       return fprintf(fp, "  %-19s ", str);
 }
 
 struct printer_data {
@@ -1719,6 +1738,9 @@ static void process_event(struct perf_script *script,
 
        if (PRINT_FIELD(METRIC))
                perf_sample__fprint_metric(script, thread, evsel, sample, fp);
+
+       if (verbose)
+               fflush(fp);
 }
 
 static struct scripting_ops    *scripting_ops;
@@ -3082,6 +3104,24 @@ static int perf_script__process_auxtrace_info(struct perf_session *session,
 #define perf_script__process_auxtrace_info 0
 #endif
 
+static int parse_insn_trace(const struct option *opt __maybe_unused,
+                           const char *str __maybe_unused,
+                           int unset __maybe_unused)
+{
+       parse_output_fields(NULL, "+insn,-event,-period", 0);
+       itrace_parse_synth_opts(opt, "i0ns", 0);
+       nanosecs = true;
+       return 0;
+}
+
+static int parse_xed(const struct option *opt __maybe_unused,
+                    const char *str __maybe_unused,
+                    int unset __maybe_unused)
+{
+       force_pager("xed -F insn: -A -64 | less");
+       return 0;
+}
+
 int cmd_script(int argc, const char **argv)
 {
        bool show_full_info = false;
@@ -3166,6 +3206,10 @@ int cmd_script(int argc, const char **argv)
                    "system-wide collection from all CPUs"),
        OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
                   "only consider these symbols"),
+       OPT_CALLBACK_OPTARG(0, "insn-trace", &itrace_synth_opts, NULL, NULL,
+                       "Decode instructions from itrace", parse_insn_trace),
+       OPT_CALLBACK_OPTARG(0, "xed", NULL, NULL, NULL,
+                       "Run xed disassembler on output", parse_xed),
        OPT_STRING(0, "stop-bt", &symbol_conf.bt_stop_list_str, "symbol[,symbol...]",
                   "Stop display of callgraph at these symbols"),
        OPT_STRING('C', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
@@ -3399,8 +3443,10 @@ int cmd_script(int argc, const char **argv)
                exit(-1);
        }
 
-       if (!script_name)
+       if (!script_name) {
                setup_pager();
+               use_browser = 0;
+       }
 
        session = perf_session__new(&data, false, &script.tool);
        if (session == NULL)