diff options
Diffstat (limited to 'tools/perf/util/map.c')
-rw-r--r-- | tools/perf/util/map.c | 105 |
1 files changed, 51 insertions, 54 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 7facd016ec97..da3d4e826231 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -245,7 +245,7 @@ void map_groups__init(struct map_groups *self) | |||
245 | self->maps[i] = RB_ROOT; | 245 | self->maps[i] = RB_ROOT; |
246 | INIT_LIST_HEAD(&self->removed_maps[i]); | 246 | INIT_LIST_HEAD(&self->removed_maps[i]); |
247 | } | 247 | } |
248 | self->this_kerninfo = NULL; | 248 | self->machine = NULL; |
249 | } | 249 | } |
250 | 250 | ||
251 | void map_groups__flush(struct map_groups *self) | 251 | void map_groups__flush(struct map_groups *self) |
@@ -513,133 +513,130 @@ struct map *maps__find(struct rb_root *maps, u64 ip) | |||
513 | return NULL; | 513 | return NULL; |
514 | } | 514 | } |
515 | 515 | ||
516 | struct kernel_info *add_new_kernel_info(struct rb_root *kerninfo_root, | 516 | struct machine *machines__add(struct rb_root *self, pid_t pid, |
517 | pid_t pid, const char *root_dir) | 517 | const char *root_dir) |
518 | { | 518 | { |
519 | struct rb_node **p = &kerninfo_root->rb_node; | 519 | struct rb_node **p = &self->rb_node; |
520 | struct rb_node *parent = NULL; | 520 | struct rb_node *parent = NULL; |
521 | struct kernel_info *kerninfo, *pos; | 521 | struct machine *pos, *machine = malloc(sizeof(*machine)); |
522 | 522 | ||
523 | kerninfo = malloc(sizeof(struct kernel_info)); | 523 | if (!machine) |
524 | if (!kerninfo) | ||
525 | return NULL; | 524 | return NULL; |
526 | 525 | ||
527 | kerninfo->pid = pid; | 526 | machine->pid = pid; |
528 | map_groups__init(&kerninfo->kmaps); | 527 | map_groups__init(&machine->kmaps); |
529 | kerninfo->root_dir = strdup(root_dir); | 528 | machine->root_dir = strdup(root_dir); |
530 | RB_CLEAR_NODE(&kerninfo->rb_node); | 529 | RB_CLEAR_NODE(&machine->rb_node); |
531 | INIT_LIST_HEAD(&kerninfo->dsos__user); | 530 | INIT_LIST_HEAD(&machine->user_dsos); |
532 | INIT_LIST_HEAD(&kerninfo->dsos__kernel); | 531 | INIT_LIST_HEAD(&machine->kernel_dsos); |
533 | kerninfo->kmaps.this_kerninfo = kerninfo; | 532 | machine->kmaps.machine = machine; |
534 | 533 | ||
535 | while (*p != NULL) { | 534 | while (*p != NULL) { |
536 | parent = *p; | 535 | parent = *p; |
537 | pos = rb_entry(parent, struct kernel_info, rb_node); | 536 | pos = rb_entry(parent, struct machine, rb_node); |
538 | if (pid < pos->pid) | 537 | if (pid < pos->pid) |
539 | p = &(*p)->rb_left; | 538 | p = &(*p)->rb_left; |
540 | else | 539 | else |
541 | p = &(*p)->rb_right; | 540 | p = &(*p)->rb_right; |
542 | } | 541 | } |
543 | 542 | ||
544 | rb_link_node(&kerninfo->rb_node, parent, p); | 543 | rb_link_node(&machine->rb_node, parent, p); |
545 | rb_insert_color(&kerninfo->rb_node, kerninfo_root); | 544 | rb_insert_color(&machine->rb_node, self); |
546 | 545 | ||
547 | return kerninfo; | 546 | return machine; |
548 | } | 547 | } |
549 | 548 | ||
550 | struct kernel_info *kerninfo__find(struct rb_root *kerninfo_root, pid_t pid) | 549 | struct machine *machines__find(struct rb_root *self, pid_t pid) |
551 | { | 550 | { |
552 | struct rb_node **p = &kerninfo_root->rb_node; | 551 | struct rb_node **p = &self->rb_node; |
553 | struct rb_node *parent = NULL; | 552 | struct rb_node *parent = NULL; |
554 | struct kernel_info *kerninfo; | 553 | struct machine *machine; |
555 | struct kernel_info *default_kerninfo = NULL; | 554 | struct machine *default_machine = NULL; |
556 | 555 | ||
557 | while (*p != NULL) { | 556 | while (*p != NULL) { |
558 | parent = *p; | 557 | parent = *p; |
559 | kerninfo = rb_entry(parent, struct kernel_info, rb_node); | 558 | machine = rb_entry(parent, struct machine, rb_node); |
560 | if (pid < kerninfo->pid) | 559 | if (pid < machine->pid) |
561 | p = &(*p)->rb_left; | 560 | p = &(*p)->rb_left; |
562 | else if (pid > kerninfo->pid) | 561 | else if (pid > machine->pid) |
563 | p = &(*p)->rb_right; | 562 | p = &(*p)->rb_right; |
564 | else | 563 | else |
565 | return kerninfo; | 564 | return machine; |
566 | if (!kerninfo->pid) | 565 | if (!machine->pid) |
567 | default_kerninfo = kerninfo; | 566 | default_machine = machine; |
568 | } | 567 | } |
569 | 568 | ||
570 | return default_kerninfo; | 569 | return default_machine; |
571 | } | 570 | } |
572 | 571 | ||
573 | struct kernel_info *kerninfo__findhost(struct rb_root *kerninfo_root) | 572 | /* |
573 | * FIXME: Why repeatedly search for this? | ||
574 | */ | ||
575 | struct machine *machines__find_host(struct rb_root *self) | ||
574 | { | 576 | { |
575 | struct rb_node **p = &kerninfo_root->rb_node; | 577 | struct rb_node **p = &self->rb_node; |
576 | struct rb_node *parent = NULL; | 578 | struct rb_node *parent = NULL; |
577 | struct kernel_info *kerninfo; | 579 | struct machine *machine; |
578 | pid_t pid = HOST_KERNEL_ID; | 580 | pid_t pid = HOST_KERNEL_ID; |
579 | 581 | ||
580 | while (*p != NULL) { | 582 | while (*p != NULL) { |
581 | parent = *p; | 583 | parent = *p; |
582 | kerninfo = rb_entry(parent, struct kernel_info, rb_node); | 584 | machine = rb_entry(parent, struct machine, rb_node); |
583 | if (pid < kerninfo->pid) | 585 | if (pid < machine->pid) |
584 | p = &(*p)->rb_left; | 586 | p = &(*p)->rb_left; |
585 | else if (pid > kerninfo->pid) | 587 | else if (pid > machine->pid) |
586 | p = &(*p)->rb_right; | 588 | p = &(*p)->rb_right; |
587 | else | 589 | else |
588 | return kerninfo; | 590 | return machine; |
589 | } | 591 | } |
590 | 592 | ||
591 | return NULL; | 593 | return NULL; |
592 | } | 594 | } |
593 | 595 | ||
594 | struct kernel_info *kerninfo__findnew(struct rb_root *kerninfo_root, pid_t pid) | 596 | struct machine *machines__findnew(struct rb_root *self, pid_t pid) |
595 | { | 597 | { |
596 | char path[PATH_MAX]; | 598 | char path[PATH_MAX]; |
597 | const char *root_dir; | 599 | const char *root_dir; |
598 | int ret; | 600 | struct machine *machine = machines__find(self, pid); |
599 | struct kernel_info *kerninfo = kerninfo__find(kerninfo_root, pid); | ||
600 | 601 | ||
601 | if (!kerninfo || kerninfo->pid != pid) { | 602 | if (!machine || machine->pid != pid) { |
602 | if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID) | 603 | if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID) |
603 | root_dir = ""; | 604 | root_dir = ""; |
604 | else { | 605 | else { |
605 | if (!symbol_conf.guestmount) | 606 | if (!symbol_conf.guestmount) |
606 | goto out; | 607 | goto out; |
607 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); | 608 | sprintf(path, "%s/%d", symbol_conf.guestmount, pid); |
608 | ret = access(path, R_OK); | 609 | if (access(path, R_OK)) { |
609 | if (ret) { | ||
610 | pr_err("Can't access file %s\n", path); | 610 | pr_err("Can't access file %s\n", path); |
611 | goto out; | 611 | goto out; |
612 | } | 612 | } |
613 | root_dir = path; | 613 | root_dir = path; |
614 | } | 614 | } |
615 | kerninfo = add_new_kernel_info(kerninfo_root, pid, root_dir); | 615 | machine = machines__add(self, pid, root_dir); |
616 | } | 616 | } |
617 | 617 | ||
618 | out: | 618 | out: |
619 | return kerninfo; | 619 | return machine; |
620 | } | 620 | } |
621 | 621 | ||
622 | void kerninfo__process_allkernels(struct rb_root *kerninfo_root, | 622 | void machines__process(struct rb_root *self, machine__process_t process, void *data) |
623 | process_kernel_info process, | ||
624 | void *data) | ||
625 | { | 623 | { |
626 | struct rb_node *nd; | 624 | struct rb_node *nd; |
627 | 625 | ||
628 | for (nd = rb_first(kerninfo_root); nd; nd = rb_next(nd)) { | 626 | for (nd = rb_first(self); nd; nd = rb_next(nd)) { |
629 | struct kernel_info *pos = rb_entry(nd, struct kernel_info, | 627 | struct machine *pos = rb_entry(nd, struct machine, rb_node); |
630 | rb_node); | ||
631 | process(pos, data); | 628 | process(pos, data); |
632 | } | 629 | } |
633 | } | 630 | } |
634 | 631 | ||
635 | char *kern_mmap_name(struct kernel_info *kerninfo, char *buff) | 632 | char *machine__mmap_name(struct machine *self, char *buff) |
636 | { | 633 | { |
637 | if (is_host_kernel(kerninfo)) | 634 | if (machine__is_host(self)) |
638 | sprintf(buff, "[%s]", "kernel.kallsyms"); | 635 | sprintf(buff, "[%s]", "kernel.kallsyms"); |
639 | else if (is_default_guest(kerninfo)) | 636 | else if (machine__is_default_guest(self)) |
640 | sprintf(buff, "[%s]", "guest.kernel.kallsyms"); | 637 | sprintf(buff, "[%s]", "guest.kernel.kallsyms"); |
641 | else | 638 | else |
642 | sprintf(buff, "[%s.%d]", "guest.kernel.kallsyms", kerninfo->pid); | 639 | sprintf(buff, "[%s.%d]", "guest.kernel.kallsyms", self->pid); |
643 | 640 | ||
644 | return buff; | 641 | return buff; |
645 | } | 642 | } |