aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/header.c7
-rw-r--r--tools/perf/util/session.c64
-rw-r--r--tools/perf/util/session.h3
-rw-r--r--tools/perf/util/symbol.c13
-rw-r--r--tools/perf/util/symbol.h2
5 files changed, 55 insertions, 34 deletions
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index ed3efd728b41..d5facd5ab1f7 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -205,8 +205,11 @@ static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd)
205 dsos__for_each_with_build_id(pos, head) { 205 dsos__for_each_with_build_id(pos, head) {
206 int err; 206 int err;
207 struct build_id_event b; 207 struct build_id_event b;
208 size_t len = pos->long_name_len + 1; 208 size_t len;
209 209
210 if (!pos->hit)
211 continue;
212 len = pos->long_name_len + 1;
210 len = ALIGN(len, NAME_ALIGN); 213 len = ALIGN(len, NAME_ALIGN);
211 memset(&b, 0, sizeof(b)); 214 memset(&b, 0, sizeof(b));
212 memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id)); 215 memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
@@ -371,7 +374,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
371 u64 sec_start; 374 u64 sec_start;
372 int idx = 0, err; 375 int idx = 0, err;
373 376
374 if (dsos__read_build_ids()) 377 if (dsos__read_build_ids(true))
375 perf_header__set_feat(self, HEADER_BUILD_ID); 378 perf_header__set_feat(self, HEADER_BUILD_ID);
376 379
377 nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS); 380 nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index aa8a03120bbd..74cbc64a3a3c 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -385,8 +385,9 @@ static struct thread *perf_session__register_idle_thread(struct perf_session *se
385 return thread; 385 return thread;
386} 386}
387 387
388int perf_session__process_events(struct perf_session *self, 388int __perf_session__process_events(struct perf_session *self,
389 struct perf_event_ops *ops) 389 u64 data_offset, u64 data_size,
390 u64 file_size, struct perf_event_ops *ops)
390{ 391{
391 int err, mmap_prot, mmap_flags; 392 int err, mmap_prot, mmap_flags;
392 u64 head, shift; 393 u64 head, shift;
@@ -396,32 +397,11 @@ int perf_session__process_events(struct perf_session *self,
396 uint32_t size; 397 uint32_t size;
397 char *buf; 398 char *buf;
398 399
399 if (perf_session__register_idle_thread(self) == NULL)
400 return -ENOMEM;
401
402 perf_event_ops__fill_defaults(ops); 400 perf_event_ops__fill_defaults(ops);
403 401
404 page_size = sysconf(_SC_PAGESIZE); 402 page_size = sysconf(_SC_PAGESIZE);
405 403
406 head = self->header.data_offset; 404 head = data_offset;
407
408 if (!symbol_conf.full_paths) {
409 char bf[PATH_MAX];
410
411 if (getcwd(bf, sizeof(bf)) == NULL) {
412 err = -errno;
413out_getcwd_err:
414 pr_err("failed to get the current directory\n");
415 goto out_err;
416 }
417 self->cwd = strdup(bf);
418 if (self->cwd == NULL) {
419 err = -ENOMEM;
420 goto out_getcwd_err;
421 }
422 self->cwdlen = strlen(self->cwd);
423 }
424
425 shift = page_size * (head / page_size); 405 shift = page_size * (head / page_size);
426 offset += shift; 406 offset += shift;
427 head -= shift; 407 head -= shift;
@@ -486,10 +466,10 @@ more:
486 466
487 head += size; 467 head += size;
488 468
489 if (offset + head >= self->header.data_offset + self->header.data_size) 469 if (offset + head >= data_offset + data_size)
490 goto done; 470 goto done;
491 471
492 if (offset + head < self->size) 472 if (offset + head < file_size)
493 goto more; 473 goto more;
494done: 474done:
495 err = 0; 475 err = 0;
@@ -497,6 +477,38 @@ out_err:
497 return err; 477 return err;
498} 478}
499 479
480int perf_session__process_events(struct perf_session *self,
481 struct perf_event_ops *ops)
482{
483 int err;
484
485 if (perf_session__register_idle_thread(self) == NULL)
486 return -ENOMEM;
487
488 if (!symbol_conf.full_paths) {
489 char bf[PATH_MAX];
490
491 if (getcwd(bf, sizeof(bf)) == NULL) {
492 err = -errno;
493out_getcwd_err:
494 pr_err("failed to get the current directory\n");
495 goto out_err;
496 }
497 self->cwd = strdup(bf);
498 if (self->cwd == NULL) {
499 err = -ENOMEM;
500 goto out_getcwd_err;
501 }
502 self->cwdlen = strlen(self->cwd);
503 }
504
505 err = __perf_session__process_events(self, self->header.data_offset,
506 self->header.data_size,
507 self->size, ops);
508out_err:
509 return err;
510}
511
500bool perf_session__has_traces(struct perf_session *self, const char *msg) 512bool perf_session__has_traces(struct perf_session *self, const char *msg)
501{ 513{
502 if (!(self->sample_type & PERF_SAMPLE_RAW)) { 514 if (!(self->sample_type & PERF_SAMPLE_RAW)) {
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 752d75aebade..31950fcd8a4d 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -50,6 +50,9 @@ void perf_session__delete(struct perf_session *self);
50 50
51void perf_event_header__bswap(struct perf_event_header *self); 51void perf_event_header__bswap(struct perf_event_header *self);
52 52
53int __perf_session__process_events(struct perf_session *self,
54 u64 data_offset, u64 data_size, u64 size,
55 struct perf_event_ops *ops);
53int perf_session__process_events(struct perf_session *self, 56int perf_session__process_events(struct perf_session *self,
54 struct perf_event_ops *event_ops); 57 struct perf_event_ops *event_ops);
55 58
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index e752837363ee..bfb055459670 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1076,25 +1076,28 @@ static bool dso__build_id_equal(const struct dso *self, u8 *build_id)
1076 return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0; 1076 return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0;
1077} 1077}
1078 1078
1079static bool __dsos__read_build_ids(struct list_head *head) 1079static bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
1080{ 1080{
1081 bool have_build_id = false; 1081 bool have_build_id = false;
1082 struct dso *pos; 1082 struct dso *pos;
1083 1083
1084 list_for_each_entry(pos, head, node) 1084 list_for_each_entry(pos, head, node) {
1085 if (with_hits && !pos->hit)
1086 continue;
1085 if (filename__read_build_id(pos->long_name, pos->build_id, 1087 if (filename__read_build_id(pos->long_name, pos->build_id,
1086 sizeof(pos->build_id)) > 0) { 1088 sizeof(pos->build_id)) > 0) {
1087 have_build_id = true; 1089 have_build_id = true;
1088 pos->has_build_id = true; 1090 pos->has_build_id = true;
1089 } 1091 }
1092 }
1090 1093
1091 return have_build_id; 1094 return have_build_id;
1092} 1095}
1093 1096
1094bool dsos__read_build_ids(void) 1097bool dsos__read_build_ids(bool with_hits)
1095{ 1098{
1096 bool kbuildids = __dsos__read_build_ids(&dsos__kernel), 1099 bool kbuildids = __dsos__read_build_ids(&dsos__kernel, with_hits),
1097 ubuildids = __dsos__read_build_ids(&dsos__user); 1100 ubuildids = __dsos__read_build_ids(&dsos__user, with_hits);
1098 return kbuildids || ubuildids; 1101 return kbuildids || ubuildids;
1099} 1102}
1100 1103
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index e90568a9e467..1b4192ee5300 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -157,7 +157,7 @@ struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
157 157
158int filename__read_build_id(const char *filename, void *bf, size_t size); 158int filename__read_build_id(const char *filename, void *bf, size_t size);
159int sysfs__read_build_id(const char *filename, void *bf, size_t size); 159int sysfs__read_build_id(const char *filename, void *bf, size_t size);
160bool dsos__read_build_ids(void); 160bool dsos__read_build_ids(bool with_hits);
161int build_id__sprintf(const u8 *self, int len, char *bf); 161int build_id__sprintf(const u8 *self, int len, char *bf);
162int kallsyms__parse(const char *filename, void *arg, 162int kallsyms__parse(const char *filename, void *arg,
163 int (*process_symbol)(void *arg, const char *name, 163 int (*process_symbol)(void *arg, const char *name,