perf: Convert perf header build_ids into build_id events
authorTom Zanussi <tzanussi@gmail.com>
Fri, 2 Apr 2010 04:59:22 +0000 (23:59 -0500)
committerIngo Molnar <mingo@elte.hu>
Wed, 14 Apr 2010 09:56:08 +0000 (11:56 +0200)
Bypasses the build_id perf header code and replaces it with a
synthesized event and processing function that accomplishes the
same thing, used when reading/writing perf data to/from a pipe.

Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: fweisbec@gmail.com
Cc: rostedt@goodmis.org
Cc: k-keiichi@bx.jp.nec.com
Cc: acme@ghostprotocols.net
LKML-Reference: <1270184365-8281-9-git-send-email-tzanussi@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-record.c
tools/perf/builtin-report.c
tools/perf/builtin-trace.c
tools/perf/util/event.h
tools/perf/util/header.c
tools/perf/util/header.h
tools/perf/util/session.c
tools/perf/util/session.h

index 3775abe2af78621e2356f97b7719eff45c703438..0bde31bc8e2e63f1ddcd41103b16d19ce194afcd 100644 (file)
@@ -426,10 +426,19 @@ static int process_buildids(void)
 
 static void atexit_header(void)
 {
-       session->header.data_size += bytes_written;
+       if (!pipe_output) {
+               session->header.data_size += bytes_written;
 
-       process_buildids();
-       perf_header__write(&session->header, output, true);
+               process_buildids();
+               perf_header__write(&session->header, output, true);
+       } else {
+               int err;
+
+               err = event__synthesize_build_ids(process_synthesized_event,
+                                                 session);
+               if (err < 0)
+                       pr_err("Couldn't synthesize build ids.\n");
+       }
 }
 
 static int __cmd_record(int argc, const char **argv)
index 76f03a70aaca7ea37401bd87697ee2366aee0434..7da5fb3652641726b8c1b921293f51610135e303 100644 (file)
@@ -270,6 +270,7 @@ static struct perf_event_ops event_ops = {
        .attr   = event__process_attr,
        .event_type = event__process_event_type,
        .tracing_data = event__process_tracing_data,
+       .build_id = event__process_build_id,
 };
 
 extern volatile int session_done;
index 1509744429c8df1cacc3a9c55749ee8b8a4abc68..1ee1e3006649d7d8eaa97e6e17661f80e30c4efe 100644 (file)
@@ -107,6 +107,7 @@ static struct perf_event_ops event_ops = {
        .attr   = event__process_attr,
        .event_type = event__process_event_type,
        .tracing_data = event__process_tracing_data,
+       .build_id = event__process_build_id,
 };
 
 extern volatile int session_done;
index b896a177ea41ae97463e6d025eb833d8e2a2f6cb..e5740ea140abfc319326f454ae814bf0dab5c45c 100644 (file)
@@ -87,6 +87,7 @@ enum perf_header_event_type { /* above any possible kernel type */
        PERF_RECORD_HEADER_ATTR                 = 64,
        PERF_RECORD_HEADER_EVENT_TYPE           = 65,
        PERF_RECORD_HEADER_TRACING_DATA         = 66,
+       PERF_RECORD_HEADER_BUILD_ID             = 67,
        PERF_RECORD_HEADER_MAX
 };
 
@@ -125,6 +126,7 @@ typedef union event_union {
        struct attr_event               attr;
        struct event_type_event         event_type;
        struct tracing_data_event       tracing_data;
+       struct build_id_event           build_id;
 } event_t;
 
 struct events_stats {
index c6874ecc90b85761f96f1d28b6505e53aef67a12..628173ba689edf855f2a15c85b547db7e5b8e164 100644 (file)
@@ -986,3 +986,93 @@ int event__process_tracing_data(event_t *self,
 
        return size_read + padding;
 }
+
+int event__synthesize_build_id(struct dso *pos, u16 misc,
+                              event__handler_t process,
+                              struct perf_session *session)
+{
+       event_t ev;
+       size_t len;
+       int err = 0;
+
+       if (!pos->hit)
+               return err;
+
+       memset(&ev, 0, sizeof(ev));
+
+       len = pos->long_name_len + 1;
+       len = ALIGN(len, NAME_ALIGN);
+       memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id));
+       ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
+       ev.build_id.header.misc = misc;
+       ev.build_id.header.size = sizeof(ev.build_id) + len;
+       memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
+
+       err = process(&ev, session);
+
+       return err;
+}
+
+static int __event_synthesize_build_ids(struct list_head *head, u16 misc,
+                                       event__handler_t process,
+                                       struct perf_session *session)
+{
+       struct dso *pos;
+
+       dsos__for_each_with_build_id(pos, head) {
+               int err;
+               if (!pos->hit)
+                       continue;
+
+               err = event__synthesize_build_id(pos, misc, process, session);
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+int event__synthesize_build_ids(event__handler_t process,
+                               struct perf_session *session)
+{
+       int err;
+
+       if (!dsos__read_build_ids(true))
+               return 0;
+
+       err = __event_synthesize_build_ids(&dsos__kernel,
+                                          PERF_RECORD_MISC_KERNEL,
+                                          process, session);
+       if (err == 0)
+               err = __event_synthesize_build_ids(&dsos__user,
+                                                  PERF_RECORD_MISC_USER,
+                                                  process, session);
+
+       if (err < 0) {
+               pr_debug("failed to synthesize build ids\n");
+               return err;
+       }
+
+       dsos__cache_build_ids();
+
+       return 0;
+}
+
+int event__process_build_id(event_t *self,
+                           struct perf_session *session __unused)
+{
+       struct list_head *head = &dsos__user;
+       struct dso *dso;
+
+       if (self->build_id.header.misc & PERF_RECORD_MISC_KERNEL)
+               head = &dsos__kernel;
+
+       dso = __dsos__findnew(head, self->build_id.filename);
+       if (dso != NULL) {
+               dso__set_build_id(dso, &self->build_id.build_id);
+               if (head == &dsos__kernel && self->build_id.filename[0] == '[')
+                       dso->kernel = 1;
+       }
+
+       return 0;
+}
index 3ed3d98c81d41f9f91d6d8280371301718240162..4214e2375650e30ef740b8f38c7f286d29dfc96b 100644 (file)
@@ -118,4 +118,11 @@ int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs,
 int event__process_tracing_data(event_t *self,
                                struct perf_session *session);
 
+int event__synthesize_build_id(struct dso *pos, u16 misc,
+                              event__handler_t process,
+                              struct perf_session *session);
+int event__synthesize_build_ids(event__handler_t process,
+                               struct perf_session *session);
+int event__process_build_id(event_t *self, struct perf_session *session);
+
 #endif /* __PERF_HEADER_H */
index 1516c40d47acf2149f0da74f8cf2167c9c9e6b7c..0fdf3ebef1e9d349a6256c95c2fc70dd8feea2fe 100644 (file)
@@ -206,6 +206,8 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
                handler->event_type = process_event_stub;
        if (handler->tracing_data == NULL)
                handler->tracing_data = process_event_stub;
+       if (handler->build_id == NULL)
+               handler->build_id = process_event_stub;
 }
 
 static const char *event__name[] = {
@@ -222,6 +224,7 @@ static const char *event__name[] = {
        [PERF_RECORD_HEADER_ATTR]        = "ATTR",
        [PERF_RECORD_HEADER_EVENT_TYPE]  = "EVENT_TYPE",
        [PERF_RECORD_HEADER_TRACING_DATA]        = "TRACING_DATA",
+       [PERF_RECORD_HEADER_BUILD_ID]    = "BUILD_ID",
 };
 
 unsigned long event__total[PERF_RECORD_HEADER_MAX];
@@ -332,6 +335,7 @@ static event__swap_op event__swap_ops[] = {
        [PERF_RECORD_HEADER_ATTR]   = event__attr_swap,
        [PERF_RECORD_HEADER_EVENT_TYPE]   = event__event_type_swap,
        [PERF_RECORD_HEADER_TRACING_DATA]   = event__tracing_data_swap,
+       [PERF_RECORD_HEADER_BUILD_ID]   = NULL,
        [PERF_RECORD_HEADER_MAX]    = NULL,
 };
 
@@ -380,6 +384,8 @@ static int perf_session__process_event(struct perf_session *self,
                /* setup for reading amidst mmap */
                lseek(self->fd, offset + head, SEEK_SET);
                return ops->tracing_data(event, self);
+       case PERF_RECORD_HEADER_BUILD_ID:
+               return ops->build_id(event, self);
        default:
                self->unknown_events++;
                return -1;
index 0739ebbbf9fdc1e1aa20af303e01078eedaa2fc9..0ac14d42dc2874d43e894b48fe8b0587247dc72a 100644 (file)
@@ -47,7 +47,8 @@ struct perf_event_ops {
                 unthrottle,
                 attr,
                 event_type,
-                tracing_data;
+                tracing_data,
+                build_id;
 };
 
 struct perf_session *perf_session__new(const char *filename, int mode, bool force);