perf tools: Add support for PERF_RECORD_ITRACE_START
authorAdrian Hunter <adrian.hunter@intel.com>
Thu, 30 Apr 2015 14:37:30 +0000 (17:37 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 5 May 2015 21:12:58 +0000 (18:12 -0300)
Add support for the PERF_RECORD_ITRACE_START event type.  This event can
be used to determine the pid and tid that are running when Instruction
Tracing starts.  Generally that information would come from a
sched_switch event but, at the start, no sched_switch events may yet
have been recorded.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1430404667-10593-8-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-inject.c
tools/perf/util/event.c
tools/perf/util/event.h
tools/perf/util/machine.c
tools/perf/util/machine.h
tools/perf/util/session.c
tools/perf/util/tool.h

index 3e8f730c7dee4060de09751b56f9a7d1a36126df..d6a47e854b2bd6643882d0089287a016d3af32c8 100644 (file)
@@ -559,6 +559,7 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
                        .exit           = perf_event__repipe,
                        .lost           = perf_event__repipe,
                        .aux            = perf_event__repipe,
+                       .itrace_start   = perf_event__repipe,
                        .read           = perf_event__repipe_sample,
                        .throttle       = perf_event__repipe,
                        .unthrottle     = perf_event__repipe,
index 724ffde8e7d7ba44c5b1e180aa85546a0a5bd61f..db526091f58099d54a2181175f147339ccfbe83f 100644 (file)
@@ -24,6 +24,7 @@ static const char *perf_event__names[] = {
        [PERF_RECORD_READ]                      = "READ",
        [PERF_RECORD_SAMPLE]                    = "SAMPLE",
        [PERF_RECORD_AUX]                       = "AUX",
+       [PERF_RECORD_ITRACE_START]              = "ITRACE_START",
        [PERF_RECORD_HEADER_ATTR]               = "ATTR",
        [PERF_RECORD_HEADER_EVENT_TYPE]         = "EVENT_TYPE",
        [PERF_RECORD_HEADER_TRACING_DATA]       = "TRACING_DATA",
@@ -704,6 +705,14 @@ int perf_event__process_aux(struct perf_tool *tool __maybe_unused,
        return machine__process_aux_event(machine, event);
 }
 
+int perf_event__process_itrace_start(struct perf_tool *tool __maybe_unused,
+                                    union perf_event *event,
+                                    struct perf_sample *sample __maybe_unused,
+                                    struct machine *machine)
+{
+       return machine__process_itrace_start_event(machine, event);
+}
+
 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp)
 {
        return fprintf(fp, " %d/%d: [%#" PRIx64 "(%#" PRIx64 ") @ %#" PRIx64 "]: %c %s\n",
@@ -776,6 +785,12 @@ size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp)
                       event->aux.flags & PERF_AUX_FLAG_OVERWRITE ? "O" : "");
 }
 
+size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp)
+{
+       return fprintf(fp, " pid: %u tid: %u\n",
+                      event->itrace_start.pid, event->itrace_start.tid);
+}
+
 size_t perf_event__fprintf(union perf_event *event, FILE *fp)
 {
        size_t ret = fprintf(fp, "PERF_RECORD_%s",
@@ -798,6 +813,9 @@ size_t perf_event__fprintf(union perf_event *event, FILE *fp)
        case PERF_RECORD_AUX:
                ret += perf_event__fprintf_aux(event, fp);
                break;
+       case PERF_RECORD_ITRACE_START:
+               ret += perf_event__fprintf_itrace_start(event, fp);
+               break;
        default:
                ret += fprintf(fp, "\n");
        }
index b3c350ed4768e295bb19b9f199fba446c8570398..7eecd5e23d7752ea29f0bac749ba3af53f2423cc 100644 (file)
@@ -330,6 +330,11 @@ struct aux_event {
        u64     flags;
 };
 
+struct itrace_start_event {
+       struct perf_event_header header;
+       u32 pid, tid;
+};
+
 union perf_event {
        struct perf_event_header        header;
        struct mmap_event               mmap;
@@ -349,6 +354,7 @@ union perf_event {
        struct auxtrace_event           auxtrace;
        struct auxtrace_error_event     auxtrace_error;
        struct aux_event                aux;
+       struct itrace_start_event       itrace_start;
 };
 
 void perf_event__print_totals(void);
@@ -388,6 +394,10 @@ int perf_event__process_aux(struct perf_tool *tool,
                            union perf_event *event,
                            struct perf_sample *sample,
                            struct machine *machine);
+int perf_event__process_itrace_start(struct perf_tool *tool,
+                                    union perf_event *event,
+                                    struct perf_sample *sample,
+                                    struct machine *machine);
 int perf_event__process_mmap(struct perf_tool *tool,
                             union perf_event *event,
                             struct perf_sample *sample,
@@ -446,6 +456,7 @@ size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
+size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
 size_t perf_event__fprintf(union perf_event *event, FILE *fp);
 
 u64 kallsyms__get_function_start(const char *kallsyms_filename,
index a7ad51100b557cab2bf4310e40782c1eb67044ba..2f471105efb1f98e5fe855f976220e832feb466d 100644 (file)
@@ -494,6 +494,14 @@ int machine__process_aux_event(struct machine *machine __maybe_unused,
        return 0;
 }
 
+int machine__process_itrace_start_event(struct machine *machine __maybe_unused,
+                                       union perf_event *event)
+{
+       if (dump_trace)
+               perf_event__fprintf_itrace_start(event, stdout);
+       return 0;
+}
+
 struct map *machine__new_module(struct machine *machine, u64 start,
                                const char *filename)
 {
@@ -1341,6 +1349,9 @@ int machine__process_event(struct machine *machine, union perf_event *event,
                ret = machine__process_lost_event(machine, event, sample); break;
        case PERF_RECORD_AUX:
                ret = machine__process_aux_event(machine, event); break;
+       case PERF_RECORD_ITRACE_START:
+               ret = machine__process_itrace_start_event(machine, event);
+               break;
        default:
                ret = -1;
                break;
index fc5432aa66b51e5ee65cb04b0eb45e6755c200a7..1d992961d5d1195797cbfc022bcea800736146dc 100644 (file)
@@ -83,6 +83,8 @@ int machine__process_lost_event(struct machine *machine, union perf_event *event
                                struct perf_sample *sample);
 int machine__process_aux_event(struct machine *machine,
                               union perf_event *event);
+int machine__process_itrace_start_event(struct machine *machine,
+                                       union perf_event *event);
 int machine__process_mmap_event(struct machine *machine, union perf_event *event,
                                struct perf_sample *sample);
 int machine__process_mmap2_event(struct machine *machine, union perf_event *event,
index 0b4646cd5245790135a3c07ec2fc02dcad4f1505..e722107f932ac8383e570c83bd94ee4a014ff398 100644 (file)
@@ -327,6 +327,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
                tool->lost = perf_event__process_lost;
        if (tool->aux == NULL)
                tool->aux = perf_event__process_aux;
+       if (tool->itrace_start == NULL)
+               tool->itrace_start = perf_event__process_itrace_start;
        if (tool->read == NULL)
                tool->read = process_event_sample_stub;
        if (tool->throttle == NULL)
@@ -455,6 +457,16 @@ static void perf_event__aux_swap(union perf_event *event, bool sample_id_all)
                swap_sample_id_all(event, &event->aux + 1);
 }
 
+static void perf_event__itrace_start_swap(union perf_event *event,
+                                         bool sample_id_all)
+{
+       event->itrace_start.pid  = bswap_32(event->itrace_start.pid);
+       event->itrace_start.tid  = bswap_32(event->itrace_start.tid);
+
+       if (sample_id_all)
+               swap_sample_id_all(event, &event->itrace_start + 1);
+}
+
 static void perf_event__throttle_swap(union perf_event *event,
                                      bool sample_id_all)
 {
@@ -593,6 +605,7 @@ static perf_event__swap_op perf_event__swap_ops[] = {
        [PERF_RECORD_UNTHROTTLE]          = perf_event__throttle_swap,
        [PERF_RECORD_SAMPLE]              = perf_event__all64_swap,
        [PERF_RECORD_AUX]                 = perf_event__aux_swap,
+       [PERF_RECORD_ITRACE_START]        = perf_event__itrace_start_swap,
        [PERF_RECORD_HEADER_ATTR]         = perf_event__hdr_attr_swap,
        [PERF_RECORD_HEADER_EVENT_TYPE]   = perf_event__event_type_swap,
        [PERF_RECORD_HEADER_TRACING_DATA] = perf_event__tracing_data_swap,
@@ -1044,6 +1057,8 @@ static int machines__deliver_event(struct machines *machines,
                return tool->unthrottle(tool, event, sample, machine);
        case PERF_RECORD_AUX:
                return tool->aux(tool, event, sample, machine);
+       case PERF_RECORD_ITRACE_START:
+               return tool->itrace_start(tool, event, sample, machine);
        default:
                ++evlist->stats.nr_unknown_events;
                return -1;
index 8288caf0836e0b78d9c9a8bb794221bf7fbd2c25..7f282ad1d2bd44b768a98992a75f8c71199ce1a7 100644 (file)
@@ -44,6 +44,7 @@ struct perf_tool {
                        exit,
                        lost,
                        aux,
+                       itrace_start,
                        throttle,
                        unthrottle;
        event_attr_op   attr;