aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/session.c
diff options
context:
space:
mode:
authorZhang, Yanmin <yanmin_zhang@linux.intel.com>2010-04-19 01:32:50 -0400
committerAvi Kivity <avi@redhat.com>2010-04-19 05:37:24 -0400
commita1645ce12adb6c9cc9e19d7695466204e3f017fe (patch)
tree5d31aaaf534997e6e9cebc07f38eca35f76986cf /tools/perf/util/session.c
parentff9d07a0e7ce756a183e7c2e483aec452ee6b574 (diff)
perf: 'perf kvm' tool for monitoring guest performance from host
Here is the patch of userspace perf tool. Signed-off-by: Zhang Yanmin <yanmin_zhang@linux.intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'tools/perf/util/session.c')
-rw-r--r--tools/perf/util/session.c77
1 files changed, 28 insertions, 49 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 0fdf3ebef1e9..7d88ae5c270f 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -67,6 +67,17 @@ void perf_session__update_sample_type(struct perf_session *self)
67 self->sample_type = perf_header__sample_type(&self->header); 67 self->sample_type = perf_header__sample_type(&self->header);
68} 68}
69 69
70int perf_session__create_kernel_maps(struct perf_session *self)
71{
72 int ret;
73 struct rb_root *root = &self->kerninfo_root;
74
75 ret = map_groups__create_kernel_maps(root, HOST_KERNEL_ID);
76 if (ret >= 0)
77 ret = map_groups__create_guest_kernel_maps(root);
78 return ret;
79}
80
70struct perf_session *perf_session__new(const char *filename, int mode, bool force) 81struct perf_session *perf_session__new(const char *filename, int mode, bool force)
71{ 82{
72 size_t len = filename ? strlen(filename) + 1 : 0; 83 size_t len = filename ? strlen(filename) + 1 : 0;
@@ -86,7 +97,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
86 self->cwd = NULL; 97 self->cwd = NULL;
87 self->cwdlen = 0; 98 self->cwdlen = 0;
88 self->unknown_events = 0; 99 self->unknown_events = 0;
89 map_groups__init(&self->kmaps); 100 self->kerninfo_root = RB_ROOT;
90 101
91 if (mode == O_RDONLY) { 102 if (mode == O_RDONLY) {
92 if (perf_session__open(self, force) < 0) 103 if (perf_session__open(self, force) < 0)
@@ -157,8 +168,9 @@ struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
157 continue; 168 continue;
158 } 169 }
159 170
171 al.filtered = false;
160 thread__find_addr_location(thread, self, cpumode, 172 thread__find_addr_location(thread, self, cpumode,
161 MAP__FUNCTION, ip, &al, NULL); 173 MAP__FUNCTION, thread->pid, ip, &al, NULL);
162 if (al.sym != NULL) { 174 if (al.sym != NULL) {
163 if (sort__has_parent && !*parent && 175 if (sort__has_parent && !*parent &&
164 symbol__match_parent_regex(al.sym)) 176 symbol__match_parent_regex(al.sym))
@@ -399,46 +411,6 @@ void perf_event_header__bswap(struct perf_event_header *self)
399 self->size = bswap_16(self->size); 411 self->size = bswap_16(self->size);
400} 412}
401 413
402int perf_header__read_build_ids(struct perf_header *self,
403 int input, u64 offset, u64 size)
404{
405 struct build_id_event bev;
406 char filename[PATH_MAX];
407 u64 limit = offset + size;
408 int err = -1;
409
410 while (offset < limit) {
411 struct dso *dso;
412 ssize_t len;
413 struct list_head *head = &dsos__user;
414
415 if (read(input, &bev, sizeof(bev)) != sizeof(bev))
416 goto out;
417
418 if (self->needs_swap)
419 perf_event_header__bswap(&bev.header);
420
421 len = bev.header.size - sizeof(bev);
422 if (read(input, filename, len) != len)
423 goto out;
424
425 if (bev.header.misc & PERF_RECORD_MISC_KERNEL)
426 head = &dsos__kernel;
427
428 dso = __dsos__findnew(head, filename);
429 if (dso != NULL) {
430 dso__set_build_id(dso, &bev.build_id);
431 if (head == &dsos__kernel && filename[0] == '[')
432 dso->kernel = 1;
433 }
434
435 offset += bev.header.size;
436 }
437 err = 0;
438out:
439 return err;
440}
441
442static struct thread *perf_session__register_idle_thread(struct perf_session *self) 414static struct thread *perf_session__register_idle_thread(struct perf_session *self)
443{ 415{
444 struct thread *thread = perf_session__findnew(self, 0); 416 struct thread *thread = perf_session__findnew(self, 0);
@@ -690,26 +662,33 @@ bool perf_session__has_traces(struct perf_session *self, const char *msg)
690 return true; 662 return true;
691} 663}
692 664
693int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self, 665int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
694 const char *symbol_name, 666 const char *symbol_name,
695 u64 addr) 667 u64 addr)
696{ 668{
697 char *bracket; 669 char *bracket;
698 enum map_type i; 670 enum map_type i;
671 struct ref_reloc_sym *ref;
672
673 ref = zalloc(sizeof(struct ref_reloc_sym));
674 if (ref == NULL)
675 return -ENOMEM;
699 676
700 self->ref_reloc_sym.name = strdup(symbol_name); 677 ref->name = strdup(symbol_name);
701 if (self->ref_reloc_sym.name == NULL) 678 if (ref->name == NULL) {
679 free(ref);
702 return -ENOMEM; 680 return -ENOMEM;
681 }
703 682
704 bracket = strchr(self->ref_reloc_sym.name, ']'); 683 bracket = strchr(ref->name, ']');
705 if (bracket) 684 if (bracket)
706 *bracket = '\0'; 685 *bracket = '\0';
707 686
708 self->ref_reloc_sym.addr = addr; 687 ref->addr = addr;
709 688
710 for (i = 0; i < MAP__NR_TYPES; ++i) { 689 for (i = 0; i < MAP__NR_TYPES; ++i) {
711 struct kmap *kmap = map__kmap(self->vmlinux_maps[i]); 690 struct kmap *kmap = map__kmap(maps[i]);
712 kmap->ref_reloc_sym = &self->ref_reloc_sym; 691 kmap->ref_reloc_sym = ref;
713 } 692 }
714 693
715 return 0; 694 return 0;