Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 1 | #include <sys/types.h> |
| 2 | #include <unistd.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 5 | #include <linux/list.h> |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 6 | |
| 7 | #include "util.h" |
| 8 | #include "header.h" |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 9 | #include "../perf.h" |
| 10 | #include "trace-event.h" |
Arnaldo Carvalho de Melo | 301a0b0 | 2009-12-13 19:50:25 -0200 | [diff] [blame] | 11 | #include "session.h" |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 12 | #include "symbol.h" |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 13 | #include "debug.h" |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 14 | |
| 15 | /* |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 16 | * Create new perf.data header attribute: |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 17 | */ |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 18 | struct perf_header_attr *perf_header_attr__new(struct perf_event_attr *attr) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 19 | { |
| 20 | struct perf_header_attr *self = malloc(sizeof(*self)); |
| 21 | |
Arnaldo Carvalho de Melo | dc79c0f | 2009-11-16 19:30:26 -0200 | [diff] [blame] | 22 | if (self != NULL) { |
| 23 | self->attr = *attr; |
| 24 | self->ids = 0; |
| 25 | self->size = 1; |
| 26 | self->id = malloc(sizeof(u64)); |
| 27 | if (self->id == NULL) { |
| 28 | free(self); |
| 29 | self = NULL; |
| 30 | } |
| 31 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 32 | |
| 33 | return self; |
| 34 | } |
| 35 | |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 36 | void perf_header_attr__delete(struct perf_header_attr *self) |
| 37 | { |
| 38 | free(self->id); |
| 39 | free(self); |
| 40 | } |
| 41 | |
Arnaldo Carvalho de Melo | 5875412 | 2009-11-17 01:18:10 -0200 | [diff] [blame] | 42 | int perf_header_attr__add_id(struct perf_header_attr *self, u64 id) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 43 | { |
| 44 | int pos = self->ids; |
| 45 | |
| 46 | self->ids++; |
| 47 | if (self->ids > self->size) { |
Arnaldo Carvalho de Melo | 5875412 | 2009-11-17 01:18:10 -0200 | [diff] [blame] | 48 | int nsize = self->size * 2; |
| 49 | u64 *nid = realloc(self->id, nsize * sizeof(u64)); |
| 50 | |
| 51 | if (nid == NULL) |
| 52 | return -1; |
| 53 | |
| 54 | self->size = nsize; |
| 55 | self->id = nid; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 56 | } |
| 57 | self->id[pos] = id; |
Arnaldo Carvalho de Melo | 5875412 | 2009-11-17 01:18:10 -0200 | [diff] [blame] | 58 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 61 | int perf_header__init(struct perf_header *self) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 62 | { |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 63 | self->size = 1; |
| 64 | self->attr = malloc(sizeof(void *)); |
| 65 | return self->attr == NULL ? -ENOMEM : 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 68 | void perf_header__exit(struct perf_header *self) |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 69 | { |
| 70 | int i; |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 71 | for (i = 0; i < self->attrs; ++i) |
Arnaldo Carvalho de Melo | 94c744b | 2009-12-11 21:24:02 -0200 | [diff] [blame] | 72 | perf_header_attr__delete(self->attr[i]); |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 73 | free(self->attr); |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 74 | } |
| 75 | |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 76 | int perf_header__add_attr(struct perf_header *self, |
| 77 | struct perf_header_attr *attr) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 78 | { |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 79 | if (self->frozen) |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 80 | return -1; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 81 | |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 82 | if (self->attrs == self->size) { |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 83 | int nsize = self->size * 2; |
| 84 | struct perf_header_attr **nattr; |
| 85 | |
| 86 | nattr = realloc(self->attr, nsize * sizeof(void *)); |
| 87 | if (nattr == NULL) |
| 88 | return -1; |
| 89 | |
| 90 | self->size = nsize; |
| 91 | self->attr = nattr; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 92 | } |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 93 | |
| 94 | self->attr[self->attrs++] = attr; |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 95 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 98 | #define MAX_EVENT_NAME 64 |
| 99 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 100 | struct perf_trace_event_type { |
| 101 | u64 event_id; |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 102 | char name[MAX_EVENT_NAME]; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static int event_count; |
| 106 | static struct perf_trace_event_type *events; |
| 107 | |
| 108 | void perf_header__push_event(u64 id, const char *name) |
| 109 | { |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 110 | if (strlen(name) > MAX_EVENT_NAME) |
Arnaldo Carvalho de Melo | 6beba7a | 2009-10-21 17:34:06 -0200 | [diff] [blame] | 111 | pr_warning("Event %s will be truncated\n", name); |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 112 | |
| 113 | if (!events) { |
| 114 | events = malloc(sizeof(struct perf_trace_event_type)); |
| 115 | if (!events) |
| 116 | die("nomem"); |
| 117 | } else { |
| 118 | events = realloc(events, (event_count + 1) * sizeof(struct perf_trace_event_type)); |
| 119 | if (!events) |
| 120 | die("nomem"); |
| 121 | } |
| 122 | memset(&events[event_count], 0, sizeof(struct perf_trace_event_type)); |
| 123 | events[event_count].event_id = id; |
Arjan van de Ven | ec60a3f | 2009-09-19 13:36:30 +0200 | [diff] [blame] | 124 | strncpy(events[event_count].name, name, MAX_EVENT_NAME - 1); |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 125 | event_count++; |
| 126 | } |
| 127 | |
| 128 | char *perf_header__find_event(u64 id) |
| 129 | { |
| 130 | int i; |
| 131 | for (i = 0 ; i < event_count; i++) { |
| 132 | if (events[i].event_id == id) |
| 133 | return events[i].name; |
| 134 | } |
| 135 | return NULL; |
| 136 | } |
| 137 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 138 | static const char *__perf_magic = "PERFFILE"; |
| 139 | |
| 140 | #define PERF_MAGIC (*(u64 *)__perf_magic) |
| 141 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 142 | struct perf_file_attr { |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 143 | struct perf_event_attr attr; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 144 | struct perf_file_section ids; |
| 145 | }; |
| 146 | |
Arnaldo Carvalho de Melo | 8d06367 | 2009-11-04 18:50:43 -0200 | [diff] [blame] | 147 | void perf_header__set_feat(struct perf_header *self, int feat) |
| 148 | { |
| 149 | set_bit(feat, self->adds_features); |
| 150 | } |
| 151 | |
| 152 | bool perf_header__has_feat(const struct perf_header *self, int feat) |
| 153 | { |
| 154 | return test_bit(feat, self->adds_features); |
| 155 | } |
| 156 | |
Arnaldo Carvalho de Melo | 3726cc7 | 2009-11-17 01:18:12 -0200 | [diff] [blame] | 157 | static int do_write(int fd, const void *buf, size_t size) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 158 | { |
| 159 | while (size) { |
| 160 | int ret = write(fd, buf, size); |
| 161 | |
| 162 | if (ret < 0) |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 163 | return -errno; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 164 | |
| 165 | size -= ret; |
| 166 | buf += ret; |
| 167 | } |
Arnaldo Carvalho de Melo | 3726cc7 | 2009-11-17 01:18:12 -0200 | [diff] [blame] | 168 | |
| 169 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 172 | #define dsos__for_each_with_build_id(pos, head) \ |
| 173 | list_for_each_entry(pos, head, node) \ |
| 174 | if (!pos->has_build_id) \ |
| 175 | continue; \ |
| 176 | else |
| 177 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 178 | static int __dsos__write_buildid_table(struct list_head *head, int fd) |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 179 | { |
OGAWA Hirofumi | 7691b1e | 2009-12-06 20:10:49 +0900 | [diff] [blame] | 180 | #define NAME_ALIGN 64 |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 181 | struct dso *pos; |
OGAWA Hirofumi | 7691b1e | 2009-12-06 20:10:49 +0900 | [diff] [blame] | 182 | static const char zero_buf[NAME_ALIGN]; |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 183 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 184 | dsos__for_each_with_build_id(pos, head) { |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 185 | int err; |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 186 | struct build_id_event b; |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 187 | size_t len = pos->long_name_len + 1; |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 188 | |
OGAWA Hirofumi | 7691b1e | 2009-12-06 20:10:49 +0900 | [diff] [blame] | 189 | len = ALIGN(len, NAME_ALIGN); |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 190 | memset(&b, 0, sizeof(b)); |
| 191 | memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); |
| 192 | b.header.size = sizeof(b) + len; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 193 | err = do_write(fd, &b, sizeof(b)); |
| 194 | if (err < 0) |
| 195 | return err; |
OGAWA Hirofumi | 7691b1e | 2009-12-06 20:10:49 +0900 | [diff] [blame] | 196 | err = do_write(fd, pos->long_name, pos->long_name_len + 1); |
| 197 | if (err < 0) |
| 198 | return err; |
Xiao Guangrong | d9541ed | 2009-12-07 12:07:15 +0800 | [diff] [blame] | 199 | err = do_write(fd, zero_buf, len - pos->long_name_len - 1); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 200 | if (err < 0) |
| 201 | return err; |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 202 | } |
Arnaldo Carvalho de Melo | 3726cc7 | 2009-11-17 01:18:12 -0200 | [diff] [blame] | 203 | |
| 204 | return 0; |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 205 | } |
| 206 | |
Arnaldo Carvalho de Melo | b0da954 | 2009-11-27 16:29:14 -0200 | [diff] [blame] | 207 | static int dsos__write_buildid_table(int fd) |
| 208 | { |
| 209 | int err = __dsos__write_buildid_table(&dsos__kernel, fd); |
| 210 | if (err == 0) |
| 211 | err = __dsos__write_buildid_table(&dsos__user, fd); |
| 212 | return err; |
| 213 | } |
| 214 | |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 215 | static int dso__cache_build_id(struct dso *self, const char *debugdir) |
| 216 | { |
| 217 | const size_t size = PATH_MAX; |
| 218 | char *filename = malloc(size), |
| 219 | *linkname = malloc(size), *targetname, *sbuild_id; |
| 220 | int len, err = -1; |
| 221 | |
| 222 | if (filename == NULL || linkname == NULL) |
| 223 | goto out_free; |
| 224 | |
| 225 | len = snprintf(filename, size, "%s%s", debugdir, self->long_name); |
| 226 | if (mkdir_p(filename, 0755)) |
| 227 | goto out_free; |
| 228 | |
| 229 | len += snprintf(filename + len, sizeof(filename) - len, "/"); |
| 230 | sbuild_id = filename + len; |
| 231 | build_id__sprintf(self->build_id, sizeof(self->build_id), sbuild_id); |
| 232 | |
| 233 | if (access(filename, F_OK) && link(self->long_name, filename) && |
| 234 | copyfile(self->long_name, filename)) |
| 235 | goto out_free; |
| 236 | |
| 237 | len = snprintf(linkname, size, "%s/.build-id/%.2s", |
| 238 | debugdir, sbuild_id); |
| 239 | |
| 240 | if (access(linkname, X_OK) && mkdir_p(linkname, 0755)) |
| 241 | goto out_free; |
| 242 | |
| 243 | snprintf(linkname + len, size - len, "/%s", sbuild_id + 2); |
| 244 | targetname = filename + strlen(debugdir) - 5; |
| 245 | memcpy(targetname, "../..", 5); |
| 246 | |
| 247 | if (symlink(targetname, linkname) == 0) |
| 248 | err = 0; |
| 249 | out_free: |
| 250 | free(filename); |
| 251 | free(linkname); |
| 252 | return err; |
| 253 | } |
| 254 | |
| 255 | static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir) |
| 256 | { |
| 257 | struct dso *pos; |
| 258 | int err = 0; |
| 259 | |
| 260 | dsos__for_each_with_build_id(pos, head) |
| 261 | if (dso__cache_build_id(pos, debugdir)) |
| 262 | err = -1; |
| 263 | |
| 264 | return err; |
| 265 | } |
| 266 | |
| 267 | static int dsos__cache_build_ids(void) |
| 268 | { |
| 269 | int err_kernel, err_user; |
| 270 | char debugdir[PATH_MAX]; |
| 271 | |
| 272 | snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"), |
| 273 | DEBUG_CACHE_DIR); |
| 274 | |
| 275 | if (mkdir(debugdir, 0755) != 0 && errno != EEXIST) |
| 276 | return -1; |
| 277 | |
| 278 | err_kernel = __dsos__cache_build_ids(&dsos__kernel, debugdir); |
| 279 | err_user = __dsos__cache_build_ids(&dsos__user, debugdir); |
| 280 | return err_kernel || err_user ? -1 : 0; |
| 281 | } |
| 282 | |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 283 | static int perf_header__adds_write(struct perf_header *self, int fd) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 284 | { |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 285 | int nr_sections; |
| 286 | struct perf_file_section *feat_sec; |
| 287 | int sec_size; |
| 288 | u64 sec_start; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 289 | int idx = 0, err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 290 | |
Arnaldo Carvalho de Melo | e30a3d1 | 2009-11-18 20:20:51 -0200 | [diff] [blame] | 291 | if (dsos__read_build_ids()) |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 292 | perf_header__set_feat(self, HEADER_BUILD_ID); |
| 293 | |
| 294 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); |
| 295 | if (!nr_sections) |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 296 | return 0; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 297 | |
| 298 | feat_sec = calloc(sizeof(*feat_sec), nr_sections); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 299 | if (feat_sec == NULL) |
| 300 | return -ENOMEM; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 301 | |
| 302 | sec_size = sizeof(*feat_sec) * nr_sections; |
| 303 | |
| 304 | sec_start = self->data_offset + self->data_size; |
| 305 | lseek(fd, sec_start + sec_size, SEEK_SET); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 306 | |
Frederic Weisbecker | 3e13ab2 | 2009-11-11 04:51:06 +0100 | [diff] [blame] | 307 | if (perf_header__has_feat(self, HEADER_TRACE_INFO)) { |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 308 | struct perf_file_section *trace_sec; |
| 309 | |
| 310 | trace_sec = &feat_sec[idx++]; |
| 311 | |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 312 | /* Write trace info */ |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 313 | trace_sec->offset = lseek(fd, 0, SEEK_CUR); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 314 | read_tracing_data(fd, attrs, nr_counters); |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 315 | trace_sec->size = lseek(fd, 0, SEEK_CUR) - trace_sec->offset; |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 316 | } |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 317 | |
Frederic Weisbecker | 57f395a | 2009-11-11 04:51:04 +0100 | [diff] [blame] | 318 | |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 319 | if (perf_header__has_feat(self, HEADER_BUILD_ID)) { |
| 320 | struct perf_file_section *buildid_sec; |
| 321 | |
| 322 | buildid_sec = &feat_sec[idx++]; |
| 323 | |
| 324 | /* Write build-ids */ |
| 325 | buildid_sec->offset = lseek(fd, 0, SEEK_CUR); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 326 | err = dsos__write_buildid_table(fd); |
| 327 | if (err < 0) { |
| 328 | pr_debug("failed to write buildid table\n"); |
| 329 | goto out_free; |
| 330 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 331 | buildid_sec->size = lseek(fd, 0, SEEK_CUR) - buildid_sec->offset; |
Arnaldo Carvalho de Melo | 4cf4013 | 2009-12-27 21:37:06 -0200 | [diff] [blame] | 332 | dsos__cache_build_ids(); |
Frederic Weisbecker | 8671dab | 2009-11-11 04:51:03 +0100 | [diff] [blame] | 333 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 334 | |
| 335 | lseek(fd, sec_start, SEEK_SET); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 336 | err = do_write(fd, feat_sec, sec_size); |
| 337 | if (err < 0) |
| 338 | pr_debug("failed to write feature section\n"); |
| 339 | out_free: |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 340 | free(feat_sec); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 341 | return err; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 342 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 343 | |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 344 | int perf_header__write(struct perf_header *self, int fd, bool at_exit) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 345 | { |
| 346 | struct perf_file_header f_header; |
| 347 | struct perf_file_attr f_attr; |
| 348 | struct perf_header_attr *attr; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 349 | int i, err; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 350 | |
| 351 | lseek(fd, sizeof(f_header), SEEK_SET); |
| 352 | |
| 353 | |
| 354 | for (i = 0; i < self->attrs; i++) { |
| 355 | attr = self->attr[i]; |
| 356 | |
| 357 | attr->id_offset = lseek(fd, 0, SEEK_CUR); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 358 | err = do_write(fd, attr->id, attr->ids * sizeof(u64)); |
| 359 | if (err < 0) { |
| 360 | pr_debug("failed to write perf header\n"); |
| 361 | return err; |
| 362 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
| 366 | self->attr_offset = lseek(fd, 0, SEEK_CUR); |
| 367 | |
| 368 | for (i = 0; i < self->attrs; i++) { |
| 369 | attr = self->attr[i]; |
| 370 | |
| 371 | f_attr = (struct perf_file_attr){ |
| 372 | .attr = attr->attr, |
| 373 | .ids = { |
| 374 | .offset = attr->id_offset, |
| 375 | .size = attr->ids * sizeof(u64), |
| 376 | } |
| 377 | }; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 378 | err = do_write(fd, &f_attr, sizeof(f_attr)); |
| 379 | if (err < 0) { |
| 380 | pr_debug("failed to write perf header attribute\n"); |
| 381 | return err; |
| 382 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 383 | } |
| 384 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 385 | self->event_offset = lseek(fd, 0, SEEK_CUR); |
| 386 | self->event_size = event_count * sizeof(struct perf_trace_event_type); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 387 | if (events) { |
| 388 | err = do_write(fd, events, self->event_size); |
| 389 | if (err < 0) { |
| 390 | pr_debug("failed to write perf header events\n"); |
| 391 | return err; |
| 392 | } |
| 393 | } |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 394 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 395 | self->data_offset = lseek(fd, 0, SEEK_CUR); |
| 396 | |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 397 | if (at_exit) { |
| 398 | err = perf_header__adds_write(self, fd); |
| 399 | if (err < 0) |
| 400 | return err; |
| 401 | } |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 402 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 403 | f_header = (struct perf_file_header){ |
| 404 | .magic = PERF_MAGIC, |
| 405 | .size = sizeof(f_header), |
| 406 | .attr_size = sizeof(f_attr), |
| 407 | .attrs = { |
| 408 | .offset = self->attr_offset, |
| 409 | .size = self->attrs * sizeof(f_attr), |
| 410 | }, |
| 411 | .data = { |
| 412 | .offset = self->data_offset, |
| 413 | .size = self->data_size, |
| 414 | }, |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 415 | .event_types = { |
| 416 | .offset = self->event_offset, |
| 417 | .size = self->event_size, |
| 418 | }, |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 419 | }; |
| 420 | |
Frederic Weisbecker | db9f11e | 2009-10-17 17:57:18 +0200 | [diff] [blame] | 421 | memcpy(&f_header.adds_features, &self->adds_features, sizeof(self->adds_features)); |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 422 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 423 | lseek(fd, 0, SEEK_SET); |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 424 | err = do_write(fd, &f_header, sizeof(f_header)); |
| 425 | if (err < 0) { |
| 426 | pr_debug("failed to write perf header\n"); |
| 427 | return err; |
| 428 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 429 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); |
| 430 | |
| 431 | self->frozen = 1; |
Arnaldo Carvalho de Melo | d5eed90 | 2009-11-19 14:55:56 -0200 | [diff] [blame] | 432 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 435 | static int do_read(int fd, void *buf, size_t size) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 436 | { |
| 437 | while (size) { |
| 438 | int ret = read(fd, buf, size); |
| 439 | |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 440 | if (ret <= 0) |
| 441 | return -1; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 442 | |
| 443 | size -= ret; |
| 444 | buf += ret; |
| 445 | } |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 446 | |
| 447 | return 0; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 448 | } |
| 449 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 450 | int perf_header__process_sections(struct perf_header *self, int fd, |
| 451 | int (*process)(struct perf_file_section *self, |
| 452 | int feat, int fd)) |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 453 | { |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 454 | struct perf_file_section *feat_sec; |
| 455 | int nr_sections; |
| 456 | int sec_size; |
| 457 | int idx = 0; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 458 | int err = -1, feat = 1; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 459 | |
| 460 | nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); |
| 461 | if (!nr_sections) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 462 | return 0; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 463 | |
| 464 | feat_sec = calloc(sizeof(*feat_sec), nr_sections); |
| 465 | if (!feat_sec) |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 466 | return -1; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 467 | |
| 468 | sec_size = sizeof(*feat_sec) * nr_sections; |
| 469 | |
| 470 | lseek(fd, self->data_offset + self->data_size, SEEK_SET); |
| 471 | |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 472 | if (do_read(fd, feat_sec, sec_size)) |
| 473 | goto out_free; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 474 | |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 475 | err = 0; |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 476 | while (idx < nr_sections && feat < HEADER_LAST_FEATURE) { |
| 477 | if (perf_header__has_feat(self, feat)) { |
| 478 | struct perf_file_section *sec = &feat_sec[idx++]; |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 479 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 480 | err = process(sec, feat, fd); |
| 481 | if (err < 0) |
| 482 | break; |
| 483 | } |
| 484 | ++feat; |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 485 | } |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 486 | out_free: |
Frederic Weisbecker | 9e827dd | 2009-11-11 04:51:07 +0100 | [diff] [blame] | 487 | free(feat_sec); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 488 | return err; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 489 | } |
Frederic Weisbecker | 2ba0825 | 2009-10-17 17:12:34 +0200 | [diff] [blame] | 490 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 491 | int perf_file_header__read(struct perf_file_header *self, |
| 492 | struct perf_header *ph, int fd) |
| 493 | { |
| 494 | lseek(fd, 0, SEEK_SET); |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 495 | |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 496 | if (do_read(fd, self, sizeof(*self)) || |
| 497 | self->magic != PERF_MAGIC || |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 498 | self->attr_size != sizeof(struct perf_file_attr)) |
| 499 | return -1; |
| 500 | |
| 501 | if (self->size != sizeof(*self)) { |
| 502 | /* Support the previous format */ |
| 503 | if (self->size == offsetof(typeof(*self), adds_features)) |
| 504 | bitmap_zero(self->adds_features, HEADER_FEAT_BITS); |
| 505 | else |
| 506 | return -1; |
| 507 | } |
| 508 | |
| 509 | memcpy(&ph->adds_features, &self->adds_features, |
| 510 | sizeof(self->adds_features)); |
| 511 | |
| 512 | ph->event_offset = self->event_types.offset; |
| 513 | ph->event_size = self->event_types.size; |
| 514 | ph->data_offset = self->data.offset; |
| 515 | ph->data_size = self->data.size; |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | static int perf_file_section__process(struct perf_file_section *self, |
| 520 | int feat, int fd) |
| 521 | { |
| 522 | if (lseek(fd, self->offset, SEEK_SET) < 0) { |
| 523 | pr_debug("Failed to lseek to %Ld offset for feature %d, " |
| 524 | "continuing...\n", self->offset, feat); |
| 525 | return 0; |
| 526 | } |
| 527 | |
| 528 | switch (feat) { |
| 529 | case HEADER_TRACE_INFO: |
| 530 | trace_report(fd); |
| 531 | break; |
| 532 | |
| 533 | case HEADER_BUILD_ID: |
| 534 | if (perf_header__read_build_ids(fd, self->offset, self->size)) |
| 535 | pr_debug("Failed to read buildids, continuing...\n"); |
| 536 | break; |
| 537 | default: |
| 538 | pr_debug("unknown feature %d, continuing...\n", feat); |
| 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 544 | int perf_header__read(struct perf_header *self, int fd) |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 545 | { |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 546 | struct perf_file_header f_header; |
| 547 | struct perf_file_attr f_attr; |
| 548 | u64 f_id; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 549 | int nr_attrs, nr_ids, i, j; |
| 550 | |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 551 | if (perf_file_header__read(&f_header, self, fd) < 0) { |
| 552 | pr_debug("incompatible file format\n"); |
| 553 | return -EINVAL; |
| 554 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 555 | |
| 556 | nr_attrs = f_header.attrs.size / sizeof(f_attr); |
| 557 | lseek(fd, f_header.attrs.offset, SEEK_SET); |
| 558 | |
| 559 | for (i = 0; i < nr_attrs; i++) { |
| 560 | struct perf_header_attr *attr; |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 561 | off_t tmp; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 562 | |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 563 | if (do_read(fd, &f_attr, sizeof(f_attr))) |
| 564 | goto out_errno; |
Peter Zijlstra | 1c222bc | 2009-08-06 20:57:41 +0200 | [diff] [blame] | 565 | tmp = lseek(fd, 0, SEEK_CUR); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 566 | |
| 567 | attr = perf_header_attr__new(&f_attr.attr); |
Arnaldo Carvalho de Melo | dc79c0f | 2009-11-16 19:30:26 -0200 | [diff] [blame] | 568 | if (attr == NULL) |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 569 | return -ENOMEM; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 570 | |
| 571 | nr_ids = f_attr.ids.size / sizeof(u64); |
| 572 | lseek(fd, f_attr.ids.offset, SEEK_SET); |
| 573 | |
| 574 | for (j = 0; j < nr_ids; j++) { |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 575 | if (do_read(fd, &f_id, sizeof(f_id))) |
| 576 | goto out_errno; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 577 | |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 578 | if (perf_header_attr__add_id(attr, f_id) < 0) { |
| 579 | perf_header_attr__delete(attr); |
| 580 | return -ENOMEM; |
| 581 | } |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 582 | } |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 583 | if (perf_header__add_attr(self, attr) < 0) { |
| 584 | perf_header_attr__delete(attr); |
| 585 | return -ENOMEM; |
| 586 | } |
Arnaldo Carvalho de Melo | 11deb1f | 2009-11-17 01:18:09 -0200 | [diff] [blame] | 587 | |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 588 | lseek(fd, tmp, SEEK_SET); |
| 589 | } |
| 590 | |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 591 | if (f_header.event_types.size) { |
| 592 | lseek(fd, f_header.event_types.offset, SEEK_SET); |
| 593 | events = malloc(f_header.event_types.size); |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 594 | if (events == NULL) |
| 595 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 596 | if (do_read(fd, events, f_header.event_types.size)) |
| 597 | goto out_errno; |
Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 598 | event_count = f_header.event_types.size / sizeof(struct perf_trace_event_type); |
| 599 | } |
Frederic Weisbecker | 03456a1 | 2009-10-06 23:36:47 +0200 | [diff] [blame] | 600 | |
Arnaldo Carvalho de Melo | 37562ea | 2009-11-16 16:32:43 -0200 | [diff] [blame] | 601 | perf_header__process_sections(self, fd, perf_file_section__process); |
Frederic Weisbecker | 4778d2e | 2009-11-11 04:51:05 +0100 | [diff] [blame] | 602 | |
Ingo Molnar | 2e01d17 | 2009-09-03 16:21:11 +0200 | [diff] [blame] | 603 | lseek(fd, self->data_offset, SEEK_SET); |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 604 | |
| 605 | self->frozen = 1; |
Arnaldo Carvalho de Melo | 4dc0a04 | 2009-11-19 14:55:55 -0200 | [diff] [blame] | 606 | return 0; |
Arnaldo Carvalho de Melo | 769885f | 2009-12-28 22:48:32 -0200 | [diff] [blame^] | 607 | out_errno: |
| 608 | return -errno; |
Peter Zijlstra | 7c6a1c6 | 2009-06-25 17:05:54 +0200 | [diff] [blame] | 609 | } |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 610 | |
| 611 | u64 perf_header__sample_type(struct perf_header *header) |
| 612 | { |
| 613 | u64 type = 0; |
| 614 | int i; |
| 615 | |
| 616 | for (i = 0; i < header->attrs; i++) { |
| 617 | struct perf_header_attr *attr = header->attr[i]; |
| 618 | |
| 619 | if (!type) |
| 620 | type = attr->attr.sample_type; |
| 621 | else if (type != attr->attr.sample_type) |
| 622 | die("non matching sample_type"); |
| 623 | } |
| 624 | |
| 625 | return type; |
| 626 | } |
| 627 | |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 628 | struct perf_event_attr * |
Frederic Weisbecker | 0d3a5c8 | 2009-08-16 20:56:37 +0200 | [diff] [blame] | 629 | perf_header__find_attr(u64 id, struct perf_header *header) |
| 630 | { |
| 631 | int i; |
| 632 | |
| 633 | for (i = 0; i < header->attrs; i++) { |
| 634 | struct perf_header_attr *attr = header->attr[i]; |
| 635 | int j; |
| 636 | |
| 637 | for (j = 0; j < attr->ids; j++) { |
| 638 | if (attr->id[j] == id) |
| 639 | return &attr->attr; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | return NULL; |
| 644 | } |