aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/header.c41
-rw-r--r--tools/perf/util/header.h2
2 files changed, 39 insertions, 4 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 050f543fd965..a4d0bbef9a43 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2,11 +2,13 @@
2#include <unistd.h> 2#include <unistd.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <linux/list.h>
5 6
6#include "util.h" 7#include "util.h"
7#include "header.h" 8#include "header.h"
8#include "../perf.h" 9#include "../perf.h"
9#include "trace-event.h" 10#include "trace-event.h"
11#include "symbol.h"
10 12
11/* 13/*
12 * Create new perf.data header attribute: 14 * Create new perf.data header attribute:
@@ -172,7 +174,33 @@ static void do_write(int fd, void *buf, size_t size)
172 } 174 }
173} 175}
174 176
175static void perf_header__adds_write(struct perf_header *self, int fd) 177static bool write_buildid_table(int fd)
178{
179 struct dso *pos;
180 bool have_buildid = false;
181
182 list_for_each_entry(pos, &dsos, node) {
183 struct build_id_event b;
184 size_t len;
185
186 if (filename__read_build_id(pos->long_name,
187 &b.build_id,
188 sizeof(b.build_id)) < 0)
189 continue;
190 have_buildid = true;
191 memset(&b.header, 0, sizeof(b.header));
192 len = strlen(pos->long_name) + 1;
193 len = ALIGN(len, 64);
194 b.header.size = sizeof(b) + len;
195 do_write(fd, &b, sizeof(b));
196 do_write(fd, pos->long_name, len);
197 }
198
199 return have_buildid;
200}
201
202static void
203perf_header__adds_write(struct perf_header *self, int fd, bool at_exit)
176{ 204{
177 struct perf_file_section trace_sec; 205 struct perf_file_section trace_sec;
178 u64 cur_offset = lseek(fd, 0, SEEK_CUR); 206 u64 cur_offset = lseek(fd, 0, SEEK_CUR);
@@ -196,9 +224,16 @@ static void perf_header__adds_write(struct perf_header *self, int fd)
196 */ 224 */
197 cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET); 225 cur_offset = lseek(fd, trace_sec.offset + trace_sec.size, SEEK_SET);
198 } 226 }
227
228 if (at_exit) {
229 lseek(fd, self->data_offset + self->data_size, SEEK_SET);
230 if (write_buildid_table(fd))
231 perf_header__set_feat(self, HEADER_BUILD_ID);
232 lseek(fd, cur_offset, SEEK_SET);
233 }
199}; 234};
200 235
201void perf_header__write(struct perf_header *self, int fd) 236void perf_header__write(struct perf_header *self, int fd, bool at_exit)
202{ 237{
203 struct perf_file_header f_header; 238 struct perf_file_header f_header;
204 struct perf_file_attr f_attr; 239 struct perf_file_attr f_attr;
@@ -236,7 +271,7 @@ void perf_header__write(struct perf_header *self, int fd)
236 if (events) 271 if (events)
237 do_write(fd, events, self->event_size); 272 do_write(fd, events, self->event_size);
238 273
239 perf_header__adds_write(self, fd); 274 perf_header__adds_write(self, fd, at_exit);
240 275
241 self->data_offset = lseek(fd, 0, SEEK_CUR); 276 self->data_offset = lseek(fd, 0, SEEK_CUR);
242 277
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 2f233c5db7e9..77186c9e605b 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -33,7 +33,7 @@ struct perf_header {
33}; 33};
34 34
35struct perf_header *perf_header__read(int fd); 35struct perf_header *perf_header__read(int fd);
36void perf_header__write(struct perf_header *self, int fd); 36void perf_header__write(struct perf_header *self, int fd, bool at_exit);
37 37
38void perf_header__add_attr(struct perf_header *self, 38void perf_header__add_attr(struct perf_header *self,
39 struct perf_header_attr *attr); 39 struct perf_header_attr *attr);