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