Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf inject: Keep a copy of kcore_dir

If the input perf.data has a kcore_dir, copy it into the output, since
at least the kallsyms in the kcore_dir will be useful to the output.

Example:

Before:

$ ls -lR perf.data-from-desktop
perf.data-from-desktop:
total 916
-rw------- 1 user user 931756 May 19 09:55 data
drwx------ 2 user user 4096 May 19 09:55 kcore_dir

perf.data-from-desktop/kcore_dir:
total 42952
-r-------- 1 user user 7582467 May 19 09:55 kallsyms
-r-------- 1 user user 36388864 May 19 09:55 kcore
-r-------- 1 user user 4828 May 19 09:55 modules

$ perf inject -i perf.data-from-desktop -o injected-perf.data

$ ls -lR injected-perf.data
-rw------- 1 user user 931320 May 20 15:08 injected-perf.data

After:

$ perf inject -i perf.data-from-desktop -o injected-perf.data

$ ls -lR injected-perf.data
injected-perf.data:
total 916
-rw------- 1 user user 931320 May 20 15:21 data
drwx------ 2 user user 4096 May 20 15:21 kcore_dir

injected-perf.data/kcore_dir:
total 42952
-r-------- 1 user user 7582467 May 20 15:21 kallsyms
-r-------- 1 user user 36388864 May 20 15:21 kcore
-r-------- 1 user user 4828 May 20 15:21 modules

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20220520132404.25853-6-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
d8fc0855 a4455e00

+30 -3
+30 -3
tools/perf/builtin-inject.c
··· 50 50 bool in_place_update; 51 51 bool in_place_update_dry_run; 52 52 bool is_pipe; 53 + bool copy_kcore_dir; 53 54 const char *input_name; 54 55 struct perf_data output; 55 56 u64 bytes_written; ··· 881 880 return 1; /* Feature section copied */ 882 881 } 883 882 883 + static int copy_kcore_dir(struct perf_inject *inject) 884 + { 885 + char *cmd; 886 + int ret; 887 + 888 + ret = asprintf(&cmd, "cp -r -n %s/kcore_dir* %s >/dev/null 2>&1", 889 + inject->input_name, inject->output.path); 890 + if (ret < 0) 891 + return ret; 892 + pr_debug("%s\n", cmd); 893 + return system(cmd); 894 + } 895 + 884 896 static int output_fd(struct perf_inject *inject) 885 897 { 886 898 return inject->in_place_update ? -1 : perf_data__fd(&inject->output); ··· 1009 995 session->header.data_offset = output_data_offset; 1010 996 session->header.data_size = inject->bytes_written; 1011 997 perf_session__inject_header(session, session->evlist, fd, &inj_fc.fc); 998 + 999 + if (inject->copy_kcore_dir) { 1000 + ret = copy_kcore_dir(inject); 1001 + if (ret) 1002 + return ret; 1003 + } 1012 1004 } 1013 1005 1014 1006 return ret; ··· 1151 1131 } 1152 1132 if (!inject.in_place_update_dry_run) 1153 1133 data.in_place_update = true; 1154 - } else if (perf_data__open(&inject.output)) { 1155 - perror("failed to create output file"); 1156 - return -1; 1134 + } else { 1135 + if (strcmp(inject.output.path, "-") && !inject.strip && 1136 + has_kcore_dir(inject.input_name)) { 1137 + inject.output.is_dir = true; 1138 + inject.copy_kcore_dir = true; 1139 + } 1140 + if (perf_data__open(&inject.output)) { 1141 + perror("failed to create output file"); 1142 + return -1; 1143 + } 1157 1144 } 1158 1145 1159 1146 data.path = inject.input_name;