perf tools: Move the build-id storage operations to headers
authorFrederic Weisbecker <fweisbec@gmail.com>
Wed, 11 Nov 2009 03:51:03 +0000 (04:51 +0100)
committerIngo Molnar <mingo@elte.hu>
Wed, 11 Nov 2009 06:30:17 +0000 (07:30 +0100)
So that it makes easier to control it. Especially because we
plan to give it a feature section.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
LKML-Reference: <1257911467-28276-2-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-record.c
tools/perf/util/header.c
tools/perf/util/header.h

index 9f98b86e747c67142875bc7c6901ed35ac34f495..c35e61b309886218527e4b1c09dab12dd9bb1704 100644 (file)
@@ -378,39 +378,11 @@ static void open_counters(int cpu, pid_t pid)
        nr_cpu++;
 }
 
-static bool write_buildid_table(void)
-{
-       struct dso *pos;
-       bool have_buildid = false;
-
-       list_for_each_entry(pos, &dsos, node) {
-               struct build_id_event b;
-               size_t len;
-
-               if (filename__read_build_id(pos->long_name,
-                                           &b.build_id,
-                                           sizeof(b.build_id)) < 0)
-                       continue;
-               have_buildid = true;
-               memset(&b.header, 0, sizeof(b.header));
-               len = strlen(pos->long_name) + 1;
-               len = ALIGN(len, 64);
-               b.header.size = sizeof(b) + len;
-               write_output(&b, sizeof(b));
-               write_output(pos->long_name, len);
-       }
-
-       return have_buildid;
-}
-
 static void atexit_header(void)
 {
        header->data_size += bytes_written;
 
-       if (write_buildid_table())
-               perf_header__set_feat(header, HEADER_BUILD_ID);
-
-       perf_header__write(header, output);
+       perf_header__write(header, output, true);
 }
 
 static int __cmd_record(int argc, const char **argv)
@@ -487,7 +459,7 @@ static int __cmd_record(int argc, const char **argv)
        }
 
        if (file_new)
-               perf_header__write(header, output);
+               perf_header__write(header, output, false);
 
        if (!system_wide)
                event__synthesize_thread(pid, process_synthesized_event);
index 050f543fd9653181f1cc8f824934521402ebc11a..a4d0bbef9a4394d62497ccf29dc36e8b7e6bacef 100644 (file)
@@ -2,11 +2,13 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <linux/list.h>
 
 #include "util.h"
 #include "header.h"
 #include "../perf.h"
 #include "trace-event.h"
+#include "symbol.h"
 
 /*
  * Create new perf.data header attribute:
@@ -172,7 +174,33 @@ static void do_write(int fd, void *buf, size_t size)
        }
 }
 
-static void perf_header__adds_write(struct perf_header *self, int fd)
+static bool write_buildid_table(int fd)
+{
+       struct dso *pos;
+       bool have_buildid = false;
+
+       list_for_each_entry(pos, &dsos, node) {
+               struct build_id_event b;
+               size_t len;
+
+               if (filename__read_build_id(pos->long_name,
+                                           &b.build_id,
+                                           sizeof(b.build_id)) < 0)
+                       continue;
+               have_buildid = true;
+               memset(&b.header, 0, sizeof(b.header));
+               len = strlen(pos->long_name) + 1;
+               len = ALIGN(len, 64);
+               b.header.size = sizeof(b) + len;
+               do_write(fd, &b, sizeof(b));
+               do_write(fd, pos->long_name, len);
+       }
+
+       return have_buildid;
+}
+
+static void
+perf_header__adds_write(struct perf_header *self, int fd, bool at_exit)
 {
        struct perf_file_section trace_sec;
        u64 cur_offset = lseek(fd, 0, SEEK_CUR);
@@ -196,9 +224,16 @@ static void perf_header__adds_write(struct perf_header *self, int fd)
                 */
                cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET);
        }
+
+       if (at_exit) {
+               lseek(fd, self->data_offset + self->data_size, SEEK_SET);
+               if (write_buildid_table(fd))
+                       perf_header__set_feat(self, HEADER_BUILD_ID);
+               lseek(fd, cur_offset, SEEK_SET);
+       }
 };
 
-void perf_header__write(struct perf_header *self, int fd)
+void perf_header__write(struct perf_header *self, int fd, bool at_exit)
 {
        struct perf_file_header f_header;
        struct perf_file_attr   f_attr;
@@ -236,7 +271,7 @@ void perf_header__write(struct perf_header *self, int fd)
        if (events)
                do_write(fd, events, self->event_size);
 
-       perf_header__adds_write(self, fd);
+       perf_header__adds_write(self, fd, at_exit);
 
        self->data_offset = lseek(fd, 0, SEEK_CUR);
 
index 2f233c5db7e9f6749751c94b604a547605b4318f..77186c9e605b96e85334372075a6fb4e596f2947 100644 (file)
@@ -33,7 +33,7 @@ struct perf_header {
 };
 
 struct perf_header *perf_header__read(int fd);
-void perf_header__write(struct perf_header *self, int fd);
+void perf_header__write(struct perf_header *self, int fd, bool at_exit);
 
 void perf_header__add_attr(struct perf_header *self,
                           struct perf_header_attr *attr);