aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/map.c')
-rw-r--r--tools/perf/util/map.c182
1 files changed, 2 insertions, 180 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 6109fa4d14cd..0328d45c4f2a 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -10,6 +10,7 @@
10#include "thread.h" 10#include "thread.h"
11#include "strlist.h" 11#include "strlist.h"
12#include "vdso.h" 12#include "vdso.h"
13#include "build-id.h"
13 14
14const char *map_type__name[MAP__NR_TYPES] = { 15const char *map_type__name[MAP__NR_TYPES] = {
15 [MAP__FUNCTION] = "Functions", 16 [MAP__FUNCTION] = "Functions",
@@ -23,7 +24,7 @@ static inline int is_anon_memory(const char *filename)
23 24
24static inline int is_no_dso_memory(const char *filename) 25static inline int is_no_dso_memory(const char *filename)
25{ 26{
26 return !strcmp(filename, "[stack]") || 27 return !strncmp(filename, "[stack", 6) ||
27 !strcmp(filename, "[heap]"); 28 !strcmp(filename, "[heap]");
28} 29}
29 30
@@ -589,182 +590,3 @@ struct map *maps__find(struct rb_root *maps, u64 ip)
589 590
590 return NULL; 591 return NULL;
591} 592}
592
593int machine__init(struct machine *self, const char *root_dir, pid_t pid)
594{
595 map_groups__init(&self->kmaps);
596 RB_CLEAR_NODE(&self->rb_node);
597 INIT_LIST_HEAD(&self->user_dsos);
598 INIT_LIST_HEAD(&self->kernel_dsos);
599
600 self->threads = RB_ROOT;
601 INIT_LIST_HEAD(&self->dead_threads);
602 self->last_match = NULL;
603
604 self->kmaps.machine = self;
605 self->pid = pid;
606 self->root_dir = strdup(root_dir);
607 if (self->root_dir == NULL)
608 return -ENOMEM;
609
610 if (pid != HOST_KERNEL_ID) {
611 struct thread *thread = machine__findnew_thread(self, pid);
612 char comm[64];
613
614 if (thread == NULL)
615 return -ENOMEM;
616
617 snprintf(comm, sizeof(comm), "[guest/%d]", pid);
618 thread__set_comm(thread, comm);
619 }
620
621 return 0;
622}
623
624static void dsos__delete(struct list_head *self)
625{
626 struct dso *pos, *n;
627
628 list_for_each_entry_safe(pos, n, self, node) {
629 list_del(&pos->node);
630 dso__delete(pos);
631 }
632}
633
634void machine__exit(struct machine *self)
635{
636 map_groups__exit(&self->kmaps);
637 dsos__delete(&self->user_dsos);
638 dsos__delete(&self->kernel_dsos);
639 free(self->root_dir);
640 self->root_dir = NULL;
641}
642
643void machine__delete(struct machine *self)
644{
645 machine__exit(self);
646 free(self);
647}
648
649struct machine *machines__add(struct rb_root *self, pid_t pid,
650 const char *root_dir)
651{
652 struct rb_node **p = &self->rb_node;
653 struct rb_node *parent = NULL;
654 struct machine *pos, *machine = malloc(sizeof(*machine));
655
656 if (!machine)
657 return NULL;
658
659 if (machine__init(machine, root_dir, pid) != 0) {
660 free(machine);
661 return NULL;
662 }
663
664 while (*p != NULL) {
665 parent = *p;
666 pos = rb_entry(parent, struct machine, rb_node);
667 if (pid < pos->pid)
668 p = &(*p)->rb_left;
669 else
670 p = &(*p)->rb_right;
671 }
672
673 rb_link_node(&machine->rb_node, parent, p);
674 rb_insert_color(&machine->rb_node, self);
675
676 return machine;
677}
678
679struct machine *machines__find(struct rb_root *self, pid_t pid)
680{
681 struct rb_node **p = &self->rb_node;
682 struct rb_node *parent = NULL;
683 struct machine *machine;
684 struct machine *default_machine = NULL;
685
686 while (*p != NULL) {
687 parent = *p;
688 machine = rb_entry(parent, struct machine, rb_node);
689 if (pid < machine->pid)
690 p = &(*p)->rb_left;
691 else if (pid > machine->pid)
692 p = &(*p)->rb_right;
693 else
694 return machine;
695 if (!machine->pid)
696 default_machine = machine;
697 }
698
699 return default_machine;
700}
701
702struct machine *machines__findnew(struct rb_root *self, pid_t pid)
703{
704 char path[PATH_MAX];
705 const char *root_dir = "";
706 struct machine *machine = machines__find(self, pid);
707
708 if (machine && (machine->pid == pid))
709 goto out;
710
711 if ((pid != HOST_KERNEL_ID) &&
712 (pid != DEFAULT_GUEST_KERNEL_ID) &&
713 (symbol_conf.guestmount)) {
714 sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
715 if (access(path, R_OK)) {
716 static struct strlist *seen;
717
718 if (!seen)
719 seen = strlist__new(true, NULL);
720
721 if (!strlist__has_entry(seen, path)) {
722 pr_err("Can't access file %s\n", path);
723 strlist__add(seen, path);
724 }
725 machine = NULL;
726 goto out;
727 }
728 root_dir = path;
729 }
730
731 machine = machines__add(self, pid, root_dir);
732
733out:
734 return machine;
735}
736
737void machines__process(struct rb_root *self, machine__process_t process, void *data)
738{
739 struct rb_node *nd;
740
741 for (nd = rb_first(self); nd; nd = rb_next(nd)) {
742 struct machine *pos = rb_entry(nd, struct machine, rb_node);
743 process(pos, data);
744 }
745}
746
747char *machine__mmap_name(struct machine *self, char *bf, size_t size)
748{
749 if (machine__is_host(self))
750 snprintf(bf, size, "[%s]", "kernel.kallsyms");
751 else if (machine__is_default_guest(self))
752 snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
753 else
754 snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms", self->pid);
755
756 return bf;
757}
758
759void machines__set_id_hdr_size(struct rb_root *machines, u16 id_hdr_size)
760{
761 struct rb_node *node;
762 struct machine *machine;
763
764 for (node = rb_first(machines); node; node = rb_next(node)) {
765 machine = rb_entry(node, struct machine, rb_node);
766 machine->id_hdr_size = id_hdr_size;
767 }
768
769 return;
770}