perf evlist: Factor out a function to propagate maps for a single evsel
[firefly-linux-kernel-4.4.55.git] / tools / perf / util / machine.c
index 7ff682770fdb16e71b368af16efad0edd9443d87..6309f7ceb08f14cfbf0ce0b3cd23d82d4603a60e 100644 (file)
@@ -250,7 +250,7 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)
                        static struct strlist *seen;
 
                        if (!seen)
-                               seen = strlist__new(true, NULL);
+                               seen = strlist__new(NULL, NULL);
 
                        if (!strlist__has_entry(seen, path)) {
                                pr_err("Can't access file %s\n", path);
@@ -550,6 +550,14 @@ int machine__process_itrace_start_event(struct machine *machine __maybe_unused,
        return 0;
 }
 
+int machine__process_switch_event(struct machine *machine __maybe_unused,
+                                 union perf_event *event)
+{
+       if (dump_trace)
+               perf_event__fprintf_switch(event, stdout);
+       return 0;
+}
+
 struct map *machine__findnew_module_map(struct machine *machine, u64 start,
                                        const char *filename)
 {
@@ -1387,6 +1395,24 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event
                                                        event->fork.ptid);
        int err = 0;
 
+       if (dump_trace)
+               perf_event__fprintf_task(event, stdout);
+
+       /*
+        * There may be an existing thread that is not actually the parent,
+        * either because we are processing events out of order, or because the
+        * (fork) event that would have removed the thread was lost. Assume the
+        * latter case and continue on as best we can.
+        */
+       if (parent->pid_ != (pid_t)event->fork.ppid) {
+               dump_printf("removing erroneous parent thread %d/%d\n",
+                           parent->pid_, parent->tid);
+               machine__remove_thread(machine, parent);
+               thread__put(parent);
+               parent = machine__findnew_thread(machine, event->fork.ppid,
+                                                event->fork.ptid);
+       }
+
        /* if a thread currently exists for the thread id remove it */
        if (thread != NULL) {
                machine__remove_thread(machine, thread);
@@ -1395,8 +1421,6 @@ int machine__process_fork_event(struct machine *machine, union perf_event *event
 
        thread = machine__findnew_thread(machine, event->fork.pid,
                                         event->fork.tid);
-       if (dump_trace)
-               perf_event__fprintf_task(event, stdout);
 
        if (thread == NULL || parent == NULL ||
            thread__fork(thread, parent, sample->time) < 0) {
@@ -1451,6 +1475,9 @@ int machine__process_event(struct machine *machine, union perf_event *event,
                ret = machine__process_itrace_start_event(machine, event); break;
        case PERF_RECORD_LOST_SAMPLES:
                ret = machine__process_lost_samples_event(machine, event, sample); break;
+       case PERF_RECORD_SWITCH:
+       case PERF_RECORD_SWITCH_CPU_WIDE:
+               ret = machine__process_switch_event(machine, event); break;
        default:
                ret = -1;
                break;
@@ -1993,3 +2020,17 @@ struct dso *machine__findnew_dso(struct machine *machine, const char *filename)
 {
        return dsos__findnew(&machine->dsos, filename);
 }
+
+char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp)
+{
+       struct machine *machine = vmachine;
+       struct map *map;
+       struct symbol *sym = map_groups__find_symbol(&machine->kmaps, MAP__FUNCTION, *addrp, &map,  NULL);
+
+       if (sym == NULL)
+               return NULL;
+
+       *modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL;
+       *addrp = map->unmap_ip(map, sym->start);
+       return sym->name;
+}