]> Pileus Git - ~andy/linux/blobdiff - tools/perf/builtin-trace.c
perf trace: Add support for syscalls vs raw_syscalls
[~andy/linux] / tools / perf / builtin-trace.c
index 6b230af940e2ab0c136098ef49b21522b6c165b6..a7aa771a98e625c70258db1c44b5ee911b5aa16d 100644 (file)
@@ -11,6 +11,8 @@
 #include "util/intlist.h"
 #include "util/thread_map.h"
 #include "util/stat.h"
+#include "trace-event.h"
+#include "util/parse-events.h"
 
 #include <libaudit.h>
 #include <stdlib.h>
@@ -172,6 +174,10 @@ static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void
 {
        struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction);
 
+       /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */
+       if (evsel == NULL)
+               evsel = perf_evsel__newtp("syscalls", direction);
+
        if (evsel) {
                if (perf_evsel__init_syscall_tp(evsel, handler))
                        goto out_delete;
@@ -1430,11 +1436,11 @@ static int trace__read_syscall_info(struct trace *trace, int id)
        sc->fmt  = syscall_fmt__find(sc->name);
 
        snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);
-       sc->tp_format = event_format__new("syscalls", tp_name);
+       sc->tp_format = trace_event__tp_format("syscalls", tp_name);
 
        if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) {
                snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias);
-               sc->tp_format = event_format__new("syscalls", tp_name);
+               sc->tp_format = trace_event__tp_format("syscalls", tp_name);
        }
 
        if (sc->tp_format == NULL)
@@ -1800,10 +1806,11 @@ static int trace__record(int argc, const char **argv)
                "-R",
                "-m", "1024",
                "-c", "1",
-               "-e", "raw_syscalls:sys_enter,raw_syscalls:sys_exit",
+               "-e",
        };
 
-       rec_argc = ARRAY_SIZE(record_args) + argc;
+       /* +1 is for the event string below */
+       rec_argc = ARRAY_SIZE(record_args) + 1 + argc;
        rec_argv = calloc(rec_argc + 1, sizeof(char *));
 
        if (rec_argv == NULL)
@@ -1812,6 +1819,17 @@ static int trace__record(int argc, const char **argv)
        for (i = 0; i < ARRAY_SIZE(record_args); i++)
                rec_argv[i] = record_args[i];
 
+       /* event string may be different for older kernels - e.g., RHEL6 */
+       if (is_valid_tracepoint("raw_syscalls:sys_enter"))
+               rec_argv[i] = "raw_syscalls:sys_enter,raw_syscalls:sys_exit";
+       else if (is_valid_tracepoint("syscalls:sys_enter"))
+               rec_argv[i] = "syscalls:sys_enter,syscalls:sys_exit";
+       else {
+               pr_err("Neither raw_syscalls nor syscalls events exist.\n");
+               return -1;
+       }
+       i++;
+
        for (j = 0; j < (unsigned int)argc; j++, i++)
                rec_argv[i] = argv[j];
 
@@ -1890,7 +1908,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
        if (err < 0)
                goto out_error_open;
 
-       err = perf_evlist__mmap(evlist, UINT_MAX, false);
+       err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
        if (err < 0) {
                fprintf(trace->output, "Couldn't mmap the events: %s\n", strerror(errno));
                goto out_close_evlist;
@@ -2047,6 +2065,10 @@ static int trace__replay(struct trace *trace)
 
        evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
                                                     "raw_syscalls:sys_enter");
+       /* older kernels have syscalls tp versus raw_syscalls */
+       if (evsel == NULL)
+               evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
+                                                            "syscalls:sys_enter");
        if (evsel == NULL) {
                pr_err("Data file does not have raw_syscalls:sys_enter event\n");
                goto out;
@@ -2060,6 +2082,9 @@ static int trace__replay(struct trace *trace)
 
        evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
                                                     "raw_syscalls:sys_exit");
+       if (evsel == NULL)
+               evsel = perf_evlist__find_tracepoint_by_name(session->evlist,
+                                                            "syscalls:sys_exit");
        if (evsel == NULL) {
                pr_err("Data file does not have raw_syscalls:sys_exit event\n");
                goto out;
@@ -2112,9 +2137,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 
        printed += fprintf(fp, "\n");
 
-       printed += fprintf(fp, "                                                    msec/call\n");
-       printed += fprintf(fp, "   syscall            calls      min      avg      max stddev\n");
-       printed += fprintf(fp, "   --------------- -------- -------- -------- -------- ------\n");
+       printed += fprintf(fp, "   syscall            calls      min       avg       max      stddev\n");
+       printed += fprintf(fp, "                               (msec)    (msec)    (msec)        (%%)\n");
+       printed += fprintf(fp, "   --------------- -------- --------- --------- ---------     ------\n");
 
        /* each int_node is a syscall */
        while (inode) {
@@ -2131,9 +2156,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 
                        sc = &trace->syscalls.table[inode->i];
                        printed += fprintf(fp, "   %-15s", sc->name);
-                       printed += fprintf(fp, " %8" PRIu64 " %8.3f %8.3f",
+                       printed += fprintf(fp, " %8" PRIu64 " %9.3f %9.3f",
                                           n, min, avg);
-                       printed += fprintf(fp, " %8.3f %6.2f\n", max, pct);
+                       printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct);
                }
 
                inode = intlist__next(inode);
@@ -2158,7 +2183,6 @@ static int trace__fprintf_one_thread(struct thread *thread, void *priv)
        size_t printed = data->printed;
        struct trace *trace = data->trace;
        struct thread_trace *ttrace = thread->priv;
-       const char *color;
        double ratio;
 
        if (ttrace == NULL)
@@ -2166,17 +2190,9 @@ static int trace__fprintf_one_thread(struct thread *thread, void *priv)
 
        ratio = (double)ttrace->nr_events / trace->nr_events * 100.0;
 
-       color = PERF_COLOR_NORMAL;
-       if (ratio > 50.0)
-               color = PERF_COLOR_RED;
-       else if (ratio > 25.0)
-               color = PERF_COLOR_GREEN;
-       else if (ratio > 5.0)
-               color = PERF_COLOR_YELLOW;
-
-       printed += color_fprintf(fp, color, " %s (%d), ", thread__comm_str(thread), thread->tid);
+       printed += fprintf(fp, " %s (%d), ", thread__comm_str(thread), thread->tid);
        printed += fprintf(fp, "%lu events, ", ttrace->nr_events);
-       printed += color_fprintf(fp, color, "%.1f%%", ratio);
+       printed += fprintf(fp, "%.1f%%", ratio);
        printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms);
        printed += thread__dump_stats(ttrace, trace, fp);