return err;
 }
 
+static int trace__fprintf_callchain(struct trace *trace, struct perf_evsel *evsel,
+                                   struct perf_sample *sample)
+{
+       struct addr_location al;
+       /* TODO: user-configurable print_opts */
+       const unsigned int print_opts = PRINT_IP_OPT_SYM |
+                                       PRINT_IP_OPT_DSO |
+                                       PRINT_IP_OPT_UNKNOWN_AS_ADDR;
+
+       if (sample->callchain == NULL)
+               return 0;
+
+       if (machine__resolve(trace->host, &al, sample) < 0) {
+               pr_err("Problem processing %s callchain, skipping...\n",
+                       perf_evsel__name(evsel));
+               return 0;
+       }
+
+       return perf_evsel__fprintf_callchain(evsel, sample, &al, 38, print_opts,
+                                            scripting_max_stack, trace->output);
+}
+
 static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
                           union perf_event *event __maybe_unused,
                           struct perf_sample *sample)
 
        fputc('\n', trace->output);
 
-       if (sample->callchain) {
-               struct addr_location al;
-               /* TODO: user-configurable print_opts */
-               const unsigned int print_opts = PRINT_IP_OPT_SYM |
-                                               PRINT_IP_OPT_DSO |
-                                               PRINT_IP_OPT_UNKNOWN_AS_ADDR;
-
-               if (machine__resolve(trace->host, &al, sample) < 0) {
-                       pr_err("problem processing %d event, skipping it.\n",
-                              event->header.type);
-                       goto out_put;
-               }
-               perf_evsel__fprintf_callchain(evsel, sample, &al, 38, print_opts,
-                                             scripting_max_stack, trace->output);
-       }
+       trace__fprintf_callchain(trace, evsel, sample);
 out:
        ttrace->entry_pending = false;
        err = 0;
        }
 
        fprintf(trace->output, ")\n");
+
+       trace__fprintf_callchain(trace, evsel, sample);
+
        return 0;
 }